verl icon indicating copy to clipboard operation
verl copied to clipboard

Using FP8 inference in long response vllm rollouts

Open vadimkantorov opened this issue 1 year ago • 27 comments

Hi! In our experience, vllm rollouts use 70% of the grpo iteration time (when performed in bf16)

Has anyone tried using more aggressive precision reduction for rollouts (like using FP8) for gaining speed? I wonder if some okay methods exist for online FP8 usage for gaining speed in this rollout phase

Thanks!

vadimkantorov avatar Jun 02 '25 09:06 vadimkantorov

The real issue was that the current vllm implementation doesn't support loading bf16 weights online and dynamically quantize them to fp8. We need this feature to land in vllm first and we only need to set the precision in vllm engine without modifying any code.

vermouth1992 avatar Jun 02 '25 10:06 vermouth1992

Another approach is to perform quantization in the sharding manager. But we haven't got a chance to try it

vermouth1992 avatar Jun 02 '25 10:06 vermouth1992

Another approach is to perform quantization in the sharding manager.

Does verl do weight consolidation on one rank prior to syncing them to the vllm workers?

Probably an example is needed of scaling out the rollout phase on a separate pool of machines (and thus of efficient weight broadcast/online fp8 quantization)... Does the sharding manager handle the weight consolidation/broadcast on the verl side?

If verl uses sth like https://github.com/vllm-project/vllm/blob/ebb1ec931871ee1baca23673049865856c44ce4e/examples/offline_inference/rlhf_utils.py#L53, could it somehow reuse some fp8 quant util from vllm and construct the fp8 weights prior to calling load_weights? Although it would be more robust if vllm supported this directly...

vadimkantorov avatar Jun 02 '25 12:06 vadimkantorov

Another approach is to perform quantization in the sharding manager.

Does verl do weight consolidation on one rank prior to syncing them to the vllm workers?

Probably an example is needed of scaling out the rollout phase on a separate pool of machines (and thus of efficient weight broadcast/online fp8 quantization)... Does the sharding manager handle the weight consolidation/broadcast on the verl side?

If verl uses sth like https://github.com/vllm-project/vllm/blob/ebb1ec931871ee1baca23673049865856c44ce4e/examples/offline_inference/rlhf_utils.py#L53, could it somehow reuse some fp8 quant util from vllm and construct the fp8 weights prior to calling load_weights? Although it would be more robust if vllm supported this directly...

It's actually here. https://github.com/volcengine/verl/blob/main/verl/workers/sharding_manager/fsdp_vllm.py#L289. verl does weight allgather per tensor to avoid OOM.

vermouth1992 avatar Jun 02 '25 13:06 vermouth1992

You can write a quantization function like

def quantize_to_fp8(name, param):
    return xxx

and modify this line to call the function

quantize_to_fp8(name, param.to(device, non_blocking=True).full_tensor())

vermouth1992 avatar Jun 02 '25 13:06 vermouth1992

I wonder if any vllm built-in quant functions exist for this... And I also wonder if at LLM(..., quantization="fp8") any full-model calibration is performed to tweak the quantized weights to match the full perf (e.g. layerwise) - but of course having a basic (but still working in reasoning generation) method would already have big impact in terms of GRPO workload speeds

vadimkantorov avatar Jun 02 '25 13:06 vadimkantorov

Agreed. The online quantization should be implemented inside the inference engine to support a class of models and keep the API clean in RL framework.

vermouth1992 avatar Jun 02 '25 13:06 vermouth1992

keep the API clean in RL framework.

Then I also wonder: could param allgather be fused with some fp8 quantization (to reduce the allgather param memory/communication overweight)?

It also appears that the code in https://github.com/volcengine/verl/blob/main/verl/workers/sharding_manager/fsdp_vllm.py#L289 is specialized for FSDP1?

vadimkantorov avatar Jun 02 '25 16:06 vadimkantorov

Imho, you can potentially do something similar to https://github.com/NVIDIA/NeMo-RL/blob/99ba9a130e72cbf87a3e20acf43bc01a47adc8ee/nemo_rl/models/generation/vllm_backend.py

engint-cerebras avatar Jun 07 '25 03:06 engint-cerebras

We have an implementation for this and I'm doing some explorations on the impact of using quantization during rollout. Currently it seems the recipe needs to be re-tuned. I will release the toolkit after finish the validation. stay tuned : )

LiyuanLucasLiu avatar Jun 11 '25 17:06 LiyuanLucasLiu

We have an implementation for this and I'm doing some explorations on the impact of using quantization during rollout.

I also wonder if fp8-quantized variant can have sufficient precision for reference model log-prob evaluation? And if also vllm can be used for ref-model inference.

vadimkantorov avatar Jun 16 '25 10:06 vadimkantorov

We have an implementation for this

I wonder if this recently merged vllm PR is helpful for this work on verl side:

  • https://github.com/vllm-project/vllm/pull/18745

vadimkantorov avatar Jun 16 '25 10:06 vadimkantorov

I have hooked vllm _process_weights_after_loading method to test fp8 rollout,https://github.com/volcengine/verl/compare/main...hxdtest:FP8_RL:add_fp8#diff-7f393140ded33f50195f94ff860ef8a6e261846a1b1272a84fcc7a8f1dedbda8

hxdtest avatar Jul 27 '25 06:07 hxdtest

@vermouth1992 Could you advise if:

  1. Does/can Verl deallocates vllm's KV-cache memory at the end of rollout stage?
  2. Does/can Verl deallocates vllm's model weights at the end of rollout stage?
  3. Does/can Verl use FP8 for ref-model? Can Verl use vllm for ref-log-probs computation? Should it be faster than FSDP inference?

These can be important for the co-location setup and having more predictable memory usage

vadimkantorov avatar Jul 27 '25 15:07 vadimkantorov

Also, would model = model_class(vllm_config=vllm_config, prefix=prefix) trigger re-torch.compile/CUDA-graph capture?

vadimkantorov avatar Jul 31 '25 21:07 vadimkantorov

@hxdtest I think it's very important to merge it upstream to Verl. And then maybe even add an option for FP4 quantization.

Then I also wonder if it's possible to run ref-model also in FP8

vadimkantorov avatar Aug 08 '25 20:08 vadimkantorov

we just released FlashRL for conducting quantized rollouts in RL training and identified one key technique, i.e., TIS, for stabilizing training. you can read more at: https://fengyao.notion.site/flash-rl : )

LiyuanLucasLiu avatar Aug 11 '25 23:08 LiyuanLucasLiu

https://github.com/yaof20/Flash-RL seems still private. Please post your changes to vllm :) At least to this issue:

  • https://github.com/vllm-project/vllm/issues/19020

Also curious, have you experimented with running the ref-model in fp8 to get the ref log-probs?

vadimkantorov avatar Aug 11 '25 23:08 vadimkantorov

https://github.com/yaof20/Flash-RL seems still private. Please post your changes to vllm :) At least to this issue:

Also curious, have you experimented with running the ref-model in fp8 to get the ref log-probs?

Please check again, the github should be public now! As to your question, no, we haven't tried that yet.

LiyuanLucasLiu avatar Aug 12 '25 04:08 LiyuanLucasLiu

https://github.com/yaof20/Flash-RL/blob/main/flash_rl/vllm_patch.py has quite a lot of patches - could you please add more comments why every function in vllm_patch.py is needed and more comments what exactly they fix? thank you :)

vadimkantorov avatar Aug 12 '25 08:08 vadimkantorov