fix(doc_vlm): remove ROCm BF16 _keep_in_fp32_modules workaround in PaddleOCR-VL#5077
Open
fchange wants to merge 1 commit intoPaddlePaddle:developfrom
Open
fix(doc_vlm): remove ROCm BF16 _keep_in_fp32_modules workaround in PaddleOCR-VL#5077fchange wants to merge 1 commit intoPaddlePaddle:developfrom
fchange wants to merge 1 commit intoPaddlePaddle:developfrom
Conversation
Remove _keep_in_fp32_modules = ["visual", "mlp_AR"] from PaddleOCRVLForConditionalGeneration. This workaround was added to avoid MIOpen BF16 convolution bugs on ROCm 7.0 by forcing the visual encoder to FP32, which doubled VRAM usage and reduced throughput. The Paddle framework now registers BF16 conv kernels for HIP backend, making this workaround unnecessary. See: PaddlePaddle/Paddle#78587 Signed-off-by: fchange Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
|
Thanks for your contribution! |
austin1997
added a commit
to austin1997/PaddleX
that referenced
this pull request
Apr 18, 2026
The PaddleOCR-VL pipeline previously needed two ROCm-specific escape hatches:
* `_keep_in_fp32_modules = ["visual", "mlp_AR"]` on
PaddleOCRVLForConditionalGeneration kept the SigLIP vision tower and the
multimodal projector in FP32 because BF16 layer_norm and BF16 softmax were
not registered for HIP, so running the vision encoder in BF16 crashed.
* Four `paddle.is_compiled_with_rocm()` blocks in
`paddlex/inference/models/runners/paddle_static/runner.py` (lines 406-408,
462-464, 496-498, 505-507) called
`delete_pass("conv2d_add_act_fuse_pass")` and
`delete_pass("conv2d_add_fuse_pass")` because both PIR passes rewrite
conv2d+add[+act] into the `fused_conv2d_add_act` op, which only has a
cuDNN GPUDNN kernel — kernel dispatch then failed on ROCm.
These are addressed at the framework level by the upstream Paddle BF16 fix
(layer_norm + softmax registration on HIP, plus gating both PIR passes on
PADDLE_WITH_CUDA so they no longer run on HIP builds). With that wheel
installed, both PaddleX workarounds become unnecessary:
* Drop `_keep_in_fp32_modules` so the vision encoder + multimodal projector
run natively in BF16 on ROCm. End-to-end output matches the FP32-fallback
path on PaddleOCR-VL-1.5 (validated on MI300X / gfx942 / ROCm 7.2). This
overlaps with PaddlePaddle#5077; if PaddlePaddle#5077 lands first, the conflict is trivial.
* Drop all four `delete_pass` blocks under `paddle.is_compiled_with_rocm()`.
Once the framework PR lands, the two passes are no longer registered on
HIP wheels, so `delete_pass` becomes a no-op there.
Requires the framework BF16 PR to be merged and released; with older Paddle
wheels the BF16 visual path will still crash on ROCm. CUDA behavior is
unchanged — both passes remain registered under PADDLE_WITH_CUDA, and the
vision encoder simply uses whatever dtype the model is loaded with.
This was referenced Apr 18, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Remove ROCm BF16 _keep_in_fp32_modules workaround in PaddleOCR-VL
Summary
Removes the
_keep_in_fp32_modules = ["visual", "mlp_AR"]workaround fromPaddleOCRVLForConditionalGeneration, enabling BF16 precision inference for the vision encoder on AMD GPUs (ROCm).Related Issue: #5076
Depends on: PaddlePaddle/Paddle#78587
Problem
The
_keep_in_fp32_modulesworkaround forces the SigLIP vision encoder to run in FP32 on ROCm, even when the model is loaded with BF16 dtype. This was necessary because Paddle's HIP backend did not register BF16 convolution kernels.Impact:
Change
class PaddleOCRVLForConditionalGeneration(Ernie4_5PretrainedModel): _tied_weights_keys = ["lm_head.weight"] config_class = PaddleOCRVLConfig _no_split_modules = ["Ernie4_5DecoderLayer", "SiglipEncoderLayer"] - _keep_in_fp32_modules = ["visual", "mlp_AR"] + _keep_in_fp32_modules = None base_model_prefix = ""Dependency
This PR requires the Paddle framework fix to be merged first:
phi::bfloat16to HIP conv kernel registrations (conv2d,conv3d,depthwise_conv2d)Verification
Environment
Test: Native Backend Inference
cd /opt/PaddleX paddlex --pipeline PaddleOCR-VL-native.yaml --input /tmp/test_ocr.pngResult: Successfully processed boarding pass image with correct OCR output:
Test: Vision Encoder BF16 Verification
After this change, the vision encoder runs in BF16 (no longer forced to FP32):
Before vs After
Notes
conv2d_add_act_fuse_pass,conv2d_add_fuse_passinstatic_infer.py) is unchanged — these depend on cuDNN and are correctly disabled on HIP.is_bfloat16_available()function inmisc.pydoes not have a ROCm override in the upstream develop branch, so no changes needed there.