Repository navigation
Studio: normalize OOXML namespaces without rewriting document text - #18012
Merged
danielhanchen merged 5 commits intoNov 17, 2026
Merged
danielhanchen merged 5 commits into
danielhanchen merged 5 commits into
Conversation
danielhanchen
added a commit
that referenced
this pull request
Nov 16, 2026
…t (fsdp2 red since accelerate 1.16) (#18025) ## Summary `Repo tests (CPU, fsdp2)` fails on main since accelerate 1.16.0 reached PyPI today (seen on #18012 and #18017, both on `20d05c20`): ``` tests/test_fsdp2_wrap_gloo.py::test_activation_checkpointed_blocks_keep_the_last_block_gathered assert r["blocks"] == N_LAYERS E assert 0 == 3 ``` ## Cause With activation checkpointing on, accelerate wraps each decoder block in a `CheckpointWrapper` and then calls `fully_shard`. Up to 1.15 it sharded the block inside the wrapper. 1.16 shards the wrapper instead and skips the block inside ("Shard the wrapper to keep FSDP hooks outside compiled code", `fsdp2_prepare_model`). `after_fsdp2_wrap` finds the blocks with `_decoder_blocks(model)` and keeps the ones that are `FSDPModule`s. On 1.16 the block is no longer one, and the wrapper's class is not a decoder layer class, so it found no blocks. The fused LoRA gate does not depend on that list (it checks that each fused layer's owning unit sits in the layer list, which the wrapper does). What was lost is the per-block tuning: the last block was no longer kept gathered after forward (`set_reshard_after_forward(False)`), so with activation checkpointing every step gathered it again at the start of backward. The test is right. accelerate's change is reasonable, and Unsloth's block lookup assumed the old layout. ## Change - `unsloth/models/fsdp2.py`: new `_block_units`, which returns each decoder block's FSDP unit: the block itself, or the checkpoint wrapper around it when that wrapper is the `FSDPModule` (`_checkpoint_wrapped_module is block`). `after_fsdp2_wrap` uses it for the block list, the block count and the last-block reshard setting. - New `tests/test_fsdp2_block_units.py` (in the `fsdp2` shard): both layouts with stand-in classes, so the 1.16 layout is checked whatever accelerate CI installs, plus a case where neither the block nor the wrapper is sharded. ## Verification - `tests/test_fsdp2_wrap_gloo.py` on accelerate 1.16.0: the checkpointed test fails on main (`0 == 3`) and all 5 pass with this change. On accelerate 1.15.0: 5 passed with this change. - `tests/test_fsdp2_block_units.py`: 3 passed. Without the wrapper lookup, the wrapper case fails. - The whole `fsdp2` shard file set on accelerate 1.16.0: 247 passed, 16 skipped.
Signed-off-by: dimitri <[email protected]>
Signed-off-by: dimitri <[email protected]>
Member
|
@codex review |
1 similar comment
Member
|
@codex review |
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
RAG's XML reader changes document text when it contains a Strict OOXML namespace URL. A cell written with XlsxWriter as
http://purl.oclc.org/ooxml/spreadsheetml/mainis read back ashttp://schemas.openxmlformats.org/spreadsheetml/2006/main. The byte replacement runs on every XML archive part, so it also changes that text in an ODT paragraph.The same normalization misses Strict workbooks and slides whose XML is UTF-16: the ASCII byte pattern is absent, the namespace lookups find nothing, and parsing returns no text. Transitional UTF-16 XML already works.
Normalize parsed element and attribute names using the existing Strict-to-Transitional map. Namespace events identify the actual URI after XML decoding, including character references. Cell text and attribute values stay as stored. Namespace events remain internal to the reader, preserving the existing stream units and element/depth limits.
Validation on macOS, Python 3.12.9:
git diff --checkpass.Parsed-name normalization adds CPU work. A local 25,000-row control adds about 7 ms for Transitional XML and 34 ms for Strict XML while keeping the output identical. No model download or GPU run.
Follow-up: entity guard in UTF-16 parts
The
<!ENTITYrefusal had the same encoding gap as the old namespace rewrite: it searched for ASCII bytes before decoding, so a UTF-16 archive part declaring an entity was parsed and its entity text indexed. The guard now also matches the UTF-16 LE and BE forms, andtest_xml_entities_are_refusedcovers all three encodings (the two UTF-16 cases fail without the change).Validation on the final head: RAG office, parsing, ingestion and retrieval suites 371 passed, 1 skipped; the office formats test file passes on ubuntu-latest, windows-latest and macos-15.