Repository navigation
Make the gradient-accumulation rewrite emit group references - #10818
vineethsaivs wants to merge 3 commits into
Conversation
|
Confirmed the replacement in unsloth/models/_utils.py still uses plain backslash-digit strings, so the captured indents come back as control bytes if that pattern ever matches again. Will get this reviewed, and I may take you up on the delete-the-block variant instead. |
Use backreference syntax so the captured indents come back as text rather than control bytes.
55160b9 to
5baa9e5
Compare
|
Thank you for the careful write-up and the test, @vineethsaivs. You are right that the replacement used plain I checked whether that line can ever run. The pattern does not match Since the branch is unreachable on every supported version, the cleaner fix is to remove the dead rewrite rather than repair it, as you suggested in the description. Closing this one in favour of that cleanup. Thanks again for spotting it. |
What breaks
patch_gradient_accumulation_fixrewritestraining_stepsoaccelerator.backwardruns on the divided loss instead of the full one. The regex is raw. The replacement is not:"\1","\2"and"\3"are octal escapes. Python turns them into0x01,0x02and0x03long beforere.subgets a chance to read them as group references, so the three captured indents come back as control characters:The
exec(function, globals())two lines below then raisesSyntaxError: unexpected indentrather than installing the patchedtraining_step.What changed
A raw template with
\g<1>,\g<2>,\g<3>. The rewrite now produces what it was written to produce:How live is it
Not live. The shape this matches is what
training_steplooked like before huggingface/transformers#35808 reordered the two. I checked the whole pinned range inpyproject.toml(transformers>=4.51.3,<=5.5.0):So today the branch is a silent no-op, and this is a landmine rather than a crash anyone is hitting. Deleting the block is a fair call instead and I am happy to send that version if you prefer it. I did not assume it, because the other three replacements in the same function are also inert on these versions and I did not want to decide that for you.
Tests
tests/test_gradient_accumulation_rewrite.pyreads the pattern and the replacement out of_utils.pywithastand runs them against the oldtraining_stepshape, since_utils.pycannot be imported without an accelerator.backwardbelow the divisionbackwardone indent level outside theifThe second fails on main: