Skip to content

fix: preserve torch_dtype in get_engine_config and add it to CodeFormulaV2#3117

Merged
cau-git merged 2 commits intodocling-project:mainfrom
majiayu000:fix/issue-3026-codeformulav2-torch-dtype
Mar 17, 2026
Merged

fix: preserve torch_dtype in get_engine_config and add it to CodeFormulaV2#3117
cau-git merged 2 commits intodocling-project:mainfrom
majiayu000:fix/issue-3026-codeformulav2-torch-dtype

Conversation

@majiayu000
Copy link
Contributor

Summary

Fixes #3026

The CodeFormulaV2 preset was missing torch_dtype in its TRANSFORMERS engine override, causing the model to load in fp32 which is incompatible with Flash Attention 2 (requires fp16/bf16). Additionally, get_engine_config() was not preserving the torch_dtype field from engine overrides, so even presets that specified it would lose the value.

Changes

  • Added torch_dtype="bfloat16" to CodeFormulaV2 preset's TRANSFORMERS engine override in stage_model_specs.py
  • Updated get_engine_config() to preserve and pass through torch_dtype from engine overrides to EngineModelConfig
  • Added test test_get_engine_config_preserves_torch_dtype to verify torch_dtype propagation

Test plan

  • pre-commit run --all-files passes (Ruff + MyPy)
  • uv run pytest tests/test_vlm_presets_and_runtime_options.py — all 32 tests pass
  • New test verifies torch_dtype is correctly preserved in EngineModelConfig

…ulaV2

get_engine_config() was silently dropping torch_dtype from engine
overrides when constructing EngineModelConfig. This caused
CodeFormulaV2 to load in fp32 while using Flash Attention 2, which
only supports fp16/bf16.

Also adds torch_dtype="bfloat16" to the CodeFormulaV2 preset's
TRANSFORMERS engine override.

Fixes docling-project#3026

Signed-off-by: majiayu000 <1835304752@qq.com>
@github-actions
Copy link
Contributor

github-actions bot commented Mar 13, 2026

DCO Check Passed

Thanks @majiayu000, all your commits are properly signed off. 🎉

@mergify
Copy link

mergify bot commented Mar 13, 2026

Merge Protections

Your pull request matches the following merge protections and will not be merged until they are valid.

🟢 Enforce conventional commit

Wonderful, this rule succeeded.

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Signed-off-by: majiayu000 <1835304752@qq.com>
@majiayu000 majiayu000 marked this pull request as ready for review March 13, 2026 12:10
@majiayu000
Copy link
Contributor Author

Hi @dolfim-ibm, done! I've moved torch_dtype into extra_config in commit a143858. The transformers engine now reads it from extra_config with the priority: options.torch_dtype > extra_config["torch_dtype"] > None. Tests updated accordingly. Could you please re-review when you get a chance?

Copy link
Member

@dolfim-ibm dolfim-ibm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@cau-git cau-git merged commit 53a5f80 into docling-project:main Mar 17, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeFormulaV2 Preset Missing torch_dtype Causes Flash Attention 2 Incompatibility

3 participants