Skip to content

fix(qwen3.8): allow sequence-boundary shape specialization - #4028

Merged
hubert-marek merged 1 commit into
mainfrom
fix/qwen38-optional-dynamic-sequences
Oct 21, 2026
Merged

hubert-marek merged 1 commit into
mainfrom
fix/qwen38-optional-dynamic-sequences

Conversation

@hubert-marek

@hubert-marek hubert-marek commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Compiled Qwen 3.8 training fails on a single packed sequence with ConstraintViolationError: the ngram/position-learning path specializes cu_seqlens to length 2, but mark_dynamic forbids that specialization.

Use maybe_mark_dynamic for this dimension so Dynamo can specialize the single-sequence case while attempting dynamic shapes for other packed-sequence counts. Shape guards remain active. This changes only Qwen 3.8; it does not change embedding sharding, model math, or other architectures.

Targets main, which already contains the affected text-model path. Multimodal support in #3916 is independent of this fix.

Validation on an H200 compute allocation with PyTorch 2.13.0+cu130:

  • The unmodified strict annotation reproduces the same ConstraintViolationError in the real ngram module.
  • The optional annotation passes 10 compiled/eager PLE comparisons: one, two, four, one and three packed sequences, both with and without non-reentrant activation checkpointing. Outputs, input/parameter gradients and AdamW parameter updates match within rtol=2e-4, atol=2e-5.
  • Ruff check, formatting check and git diff --check pass.

The isolated probe uses small real PLE/ngram modules, not the full distributed model. These checks do not establish a successful full-model distributed compiled update.


Note

Low Risk
Single-line Dynamo annotation change in one model; validated for numerical parity across packed-sequence shapes without altering training math.

Overview
Fixes compiled Qwen 3.8 training when a batch is a single packed sequence: Torch Dynamo was hitting ConstraintViolationError because the PLE/ngram path specializes cu_seqlens length (e.g. to 2) while mark_dynamic blocked that specialization.

In Qwen3_8FlashNextTextModel.forward, cu_seqlens dim 0 is annotated with torch._dynamo.maybe_mark_dynamic instead of mark_dynamic, so Dynamo can specialize the one-sequence case while still treating other packed-sequence counts as dynamic. Scope is Qwen 3.8 Flash Next only; model math, sharding, and other architectures are unchanged.

Reviewed by Cursor Bugbot for commit afcb32d. Bugbot is set up for automated code reviews on this repo. Configure here.

@hubert-marek
hubert-marek marked this pull request as ready for review October 11, 2026 18:52
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-15T11:12:39.354800Z 13beb48 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@hubert-marek
hubert-marek force-pushed the fix/qwen38-optional-dynamic-sequences branch from afcb32d to 13beb48 Compare October 15, 2026 11:11
@hubert-marek
hubert-marek changed the base branch from qwen-3-8-flash to main October 15, 2026 11:11

@garrett361 garrett361 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@hubert-marek
hubert-marek merged commit 7ac4be4 into main Oct 21, 2026
28 of 38 checks passed
@hubert-marek
hubert-marek deleted the fix/qwen38-optional-dynamic-sequences branch October 21, 2026 14:37
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.

2 participants