Skip to content

[rl] Removed patched qwen3 parallel plan to core torchtitan Qwen3 parallel plan - #3070

Merged
wwwjn merged 9 commits into
mainfrom
rl-parallel-plan
Apr 28, 2026
Merged

wwwjn merged 9 commits into
mainfrom
rl-parallel-plan

Conversation

@wwwjn

@wwwjn wwwjn commented Apr 23, 2026 •

Copy link
Copy Markdown
Contributor

As titled.

We need to skip FSDP because FSDP's forward hooks (unshard/reshard) use in-place operations that conflict with torch.inference_mode(). vLLM runs the model forward under @torch.inference_mode() during KV cache profiling and generation.

Also inference don't need mixed precision (now) because all computation / weights are in bf16

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 23, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will revert changes to this file - Just import order change

Comment thread torchtitan/models/qwen3/parallelize.py Outdated
parallel_dims.get_mesh("cp"),
)

# Skip FSDP, AC, and compile for inference. FSDP is incompatible

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For FSDP, here's why FSDP doesn't work with inference mode:

FSDP's pre_forward hook calls unshard() which uses _unsafe_preserve_version_counter to do in-place modifications on parameter tensors (swapping sharded ↔ unsharded views). torch.inference_mode() disables version counting on tensors entirely, so when FSDP tries to access tensor._version, it raises RuntimeError: Inference tensors do not track version counter.

This happens even at dp_shard=1 because FSDP still registers the hooks — it just doesn't do actual communication. The hook still runs the version counter logic.

cc @weifengpy

@wwwjn
wwwjn marked this pull request as ready for review April 23, 2026 19:38
Comment thread torchtitan/models/qwen3/parallelize.py Resolved
@wwwjn wwwjn changed the title Removed patched qwen3 parallel plan to core torchtitan Qwen3 parallel plan [rl] Removed patched qwen3 parallel plan to core torchtitan Qwen3 parallel plan Apr 23, 2026
@wwwjn
wwwjn force-pushed the rl-parallel-plan branch from 2b34c24 to d271fc0 Compare April 26, 2026 22:26
@wwwjn
wwwjn requested a review from tianyu-l April 27, 2026 16:04
Comment thread torchtitan/models/qwen3/parallelize.py Resolved
@wwwjn
wwwjn force-pushed the rl-parallel-plan branch from 8ae6939 to c818af9 Compare April 27, 2026 20:31

if hasattr(self.config, "update_from_config"):
self.config.update_from_config(
trainer_config=SimpleNamespace(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is idea from @fegin 's PR and discussion here: #2986 (comment)

Comment thread torchtitan/models/qwen3/parallelize.py Resolved
@wwwjn
wwwjn merged commit 61138e0 into main Apr 28, 2026
19 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants