Using FP8 inference in long response vllm rollouts
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!
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.
Another approach is to perform quantization in the sharding manager. But we haven't got a chance to try it
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...
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.
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())
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
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.
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?
Imho, you can potentially do something similar to https://github.com/NVIDIA/NeMo-RL/blob/99ba9a130e72cbf87a3e20acf43bc01a47adc8ee/nemo_rl/models/generation/vllm_backend.py
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 : )
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.
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
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
@vermouth1992 Could you advise if:
- Does/can Verl deallocates vllm's KV-cache memory at the end of rollout stage?
- Does/can Verl deallocates vllm's model weights at the end of rollout stage?
- 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
Also, would model = model_class(vllm_config=vllm_config, prefix=prefix) trigger re-torch.compile/CUDA-graph capture?
@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
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 : )
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?
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.
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 :)