[DO NOT MERGE] add all level buffer support when computing infer_auto_device_map #2663
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.
What does this PR do ?
This PR adds all level support when computing
infer_auto_device_map
. This is especially important for persistant buffer that are in the state_dict. If we don't attribute a device to those buffers, we will get error in transformers when we try to load thestate_dict
. We might hit edge cases with cpu and disk offload.Usually buffers are defined in a
nn.Module
that don't have other children modules. However, in a model such as RecurrentGemmaModel,normalize
buffer is defined at the level of the model. So when we have model = RecurrentGemmaForCausalLM, the persistent buffer is defined there at this locationmodel.model.normalize
butmodel.model
have children modules such aslayers
.cc @ArthurZucker
Another solution would be to just use non persistant buffer all the time for these cases
-> This is the solution that we are going with for now. We can merge this PR if it makes sense later.