[cosmos3] Bitwise train/rollout parity: FSDP precision spec + cosmos3_bitwise rollout patch group - #109
Open
zhihengy wants to merge 1 commit into
Open
[cosmos3] Bitwise train/rollout parity: FSDP precision spec + cosmos3_bitwise rollout patch group#109zhihengy wants to merge 1 commit into
zhihengy wants to merge 1 commit into
Conversation
…os3_bitwise patch group Train side: port PrecisionSpec/compile_precision (module-granular FSDP2 gather dtypes) and wire it through apply_fsdp2; keep time_embedder gathered at fp32 (diffusers' _keep_in_fp32_modules contract, silently downgraded by the blanket bf16 gather) with row-dedup so the fp32 MLP matches sgl-d's per-request compute shape; raise diffusers RMSNorm to fp32-through-mul via F.rms_norm. Rollout side (cosmos3_bitwise group): pin TORCH_SDPA, route RMSNorm through F.rms_norm, unfuse MergedColumnParallelLinear per output_sizes (fused column blocks are not bitwise equal to standalone GEMMs; output_partition_sizes collapses to one slice under tp=1 init order — fail loud), eager SiluAndMul, split qk-norm/rope path, sequential batch-1 CFG (cuBLAS is not batch- invariant on cosmos3 shapes). Verified: 103/103 aligned tensor pairs bit-exact across both CFG branches, both towers, first/last denoise steps (embed_tokens -> proj_out). Co-authored-by: Cursor <cursoragent@cursor.com>
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.
Stacked on #25 (
feat/cosmos3).Summary
Makes the Cosmos3 GRPO training forward (miles/diffusers/FSDP2) produce bit-identical tensors to the rollout engine (sglang-d), verified across every aligned module output: 103/103 comparable tensor pairs bit-exact (both CFG branches, UND+GEN towers, first and last denoise steps,
embed_tokensthroughproj_out).Train side
precision.py:PrecisionSpec/compile_precision— module-granular FSDP2 gather-dtype overrides, compiled on clean FQNs (pre-LoRA/pre-FSDP) and lowered into theapply_fsdp2wrap plan.time_embedderfp32 island: diffusers declares_keep_in_fp32_modules = ["time_embedder"]and sglang-d pins it to fp32 at load; the blanket bf16 gather silently downgraded it on the train side. The spec gathers it at fp32, the wrapper runs it with autocast disabled, and identical sinusoid rows are deduplicated before the MLP (cuBLAS fp32 GEMMs are not bitwise M-invariant, measured on the 4096x4096 MLP; sglang-d runs M=1 per request).F.rms_norm: eager diffusers RMSNorm rounds to bf16 before the weight mul (two roundings); sglang-d keeps fp32 through the mul. Upgrade the train side (never downgrade) so both run the identical op.Rollout side (
rollout_patch_group = "cosmos3_bitwise", applied at engine startup)TORCH_SDPAattention backend (matches the train-side SDPA path).F.rms_norm.MergedColumnParallelLinear(to_qkv,gate_up_proj) into per-sliceF.linearGEMMs — fused column blocks are not bitwise equal to the standalone GEMMs diffusers runs. Slices come fromoutput_sizes(with tp=1 init order,output_partition_sizescollapses to one fused slice); the patch fails loud rather than silently falling back fused.SiluAndMuland split (unfused) qk-norm/RoPE path.Validation
pair_metricsshowsmax_abs_diff = 0for all 103 aligned pairs; 3 remaining records are benign scalar-vs-broadcast shape mismatches with byte-identical values.Test plan
Made with Cursor