Repository navigation
fix(autograd): register reshape backward exactly once - #6
Merged
Merged
Conversation
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.
Summary
Make
Tensor::reshapethe single owner of reshape's backward registration in the new autograd engine, and add explicit reshape/LoRA and Qwen finite-difference regressions.This is adapted to this repository, not a blind cherry-pick of the MobileRLHF fix. Here,
Tensor::set_grad_fnonly stores a legacy callback: currentops::reshapehas one correct engine edge, while direct memberreshape/viewlacks one. Moving the registration into the member fixes that missing path; removing the wrapper registration prevents the doubled-gradient regression when both paths are active.Thanks to Johnny for identifying the duplicate-registration failure mode in MobileRLHF issue #5 and proposing MobileRLHF PR #4. The related tests are in MobileRLHF PR #6.
Changes
ReshapeBackwardonce inTensor::reshape; preserve the existing legacy callback/non-leaf classification.BUILD_TESTS/USE_NEW_AUTOGRAD_ENGINEin CMake; CSV output stays in each build directory.Validation
Local macOS results on upstream
086b1a027fe708d5eaca89b1ec2bf1a876fb80de:TokenizerHFGoldenreports SKIP without an external fixture; its inclusion in the CTest passing count is not tokenizer alignment evidence. The constructed double-registration control is not the current upstream implementation. No task accuracy/convergence, full-pretrained training, or phone-runtime improvement is claimed.BLAS + warnings-as-errors ON still fails on the existing unused
matmul_fallback_nn/matmul_fallback_nthelpers. Those unrelated kernels are unchanged; the default pure warnings-as-errors CI configuration passes locally.Reproduction:
cmake -S operator -B /tmp/mft-reshape-release -DCMAKE_BUILD_TYPE=Release -DUSE_BLAS=OFF -DOPERATORS_WARNINGS_AS_ERRORS=ON cmake --build /tmp/mft-reshape-release -j4 ctest --test-dir /tmp/mft-reshape-release --output-on-failure cmake -S operator -B /tmp/mft-reshape-blas -DCMAKE_BUILD_TYPE=Release -DUSE_BLAS=ON -DOPERATORS_WARNINGS_AS_ERRORS=OFF -DCMAKE_CXX_FLAGS=-DACCELERATE_NEW_LAPACK '-DCMAKE_CXX_FLAGS_RELEASE=-O3 -UNDEBUG' cmake --build /tmp/mft-reshape-blas -j4 ctest --test-dir /tmp/mft-reshape-blas --output-on-failureOnly five source/build files are changed. No weights, datasets, logs, unrelated energy code, or MobileRLHF submodule changes are included.
GitHub operator-ci completed successfully for head
eaf0cfbfd0dafddb043626a7348070813b7808fd, including C++ tests/install/consumer checks, Android visualizer build, five synthetic entrypoint scripts, and energy scheduler integration. Android build success is not a physical-phone runtime result.