Fix: Replace nn.Buffer with register_buffer#30
Open
Tar-ive wants to merge 1 commit into
Open
Conversation
autonull
pushed a commit
to deepstupid/hrem
that referenced
this pull request
Aug 25, 2025
This commit refactors, enhances, and robustifies the unified optimization/evaluation/comparison process. It also incorporates a critical bug fix from PR sapientinc#30. - Applied a fix from PR sapientinc#30 to address an `AttributeError` related to `nn.Buffer` by replacing it with `register_buffer`. - Created an `optimization` directory and moved/renamed the relevant scripts. - Created `optimization/utils.py` to deduplicate code. - The hyperparameter search space is now loaded from a YAML file. - Added support for parallel execution of Optuna trials. - Improved the detail and location of the `comparison_report.md`. - Improved the console output. - Added robust error handling to the main scripts. - Updated `README.md` to reflect the changes. The final verification step was blocked by a `ModuleNotFoundError` which can be fixed by adding the project root to the Python path.
|
I've applied it here: deepstupid@45a3b2c |
dribnet
added a commit
to dribnet/TinyRecursiveModels
that referenced
this pull request
Oct 10, 2025
replaced adam-atan2 with adam-atan2-pytorch which works on older and newer versions of CUDA / pytorch sapientinc/HRM#45 Replace nn.Buffer with register_buffer sapientinc/HRM#30
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.
#28
The core issue was a bug in the original HRM source code that made it incompatible with modern versions of PyTorch. The error message AttributeError: module 'torch.nn' has no attribute 'Buffer' told us that the code was trying to use a feature in a way that doesn't exist.
The Cause: Incorrect PyTorch Usage
In PyTorch, a "buffer" is a tensor that is part of a model's state (like weights) but is not a parameter that gets updated during training (e.g., a running mean in a normalization layer).
The original developer wrote code like this:
self.weights = nn.Buffer(...)
This is incorrect. nn.Buffer is not a function you can call directly to create a buffer. This might have worked in a very old, pre-release version of PyTorch, but it is not the correct way to do it.
The Change: Using the Correct Method
The official and correct way to create and register a buffer in a PyTorch model is by using the self.register_buffer() method.
We fixed the code by changing lines like the one above to the following pattern:
By making these changes, we made the code compliant with the modern PyTorch API, which allowed the training to proceed without errors.