Add missing type hints in utils/memory.py - #4152
Open
RudrenduPaul wants to merge 1 commit into
Open
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.
What this PR does
Adds missing type hints to two functions in
src/accelerate/utils/memory.py:clear_device_cache(garbage_collection: bool = False) -> Nonerelease_memory(*objects) -> listThis follows the same self-identified typing-consistency pattern as my prior
PRs in this repo (#4123, #4124, #4125) — no linked issue, just filling in
type hints that were missing while the rest of the module (and the file's
other two functions,
should_reduce_batch_sizeandfind_executable_batch_size) already had them.Functions updated
clear_device_cache:garbage_collectionis only ever called withboolvalues (
True/False) at every call site in the codebase, and thefunction has no
returnstatement, so-> Noneis accurate.release_memory: builds alistfrom*objects, sets every element toNone, and returns that list — verified by reading the full functionbody, so
-> listis accurate. The variadic*objectsparameter itselfis intentionally left unannotated (it accepts arbitrary object types to
release from memory), consistent with how
*args/**kwargswere leftunannotated in my earlier
hooks.py(Add module: nn.Module type hints to ModelHook lifecycle methods #4124) andlogging.py(Add level and msg type hints to MultiProcessAdapter.log #4125) PRs.Functions intentionally left unchanged
should_reduce_batch_sizeandfind_executable_batch_sizealready havecomplete type hints on every parameter in this file — no changes needed.
No behaviour change
Type-hint-only change. No logic was modified.
Testing
ruff check src/accelerate/utils/memory.py— all checks pass.ruff format --check src/accelerate/utils/memory.py— passes, filealready formatted.
python3 -c "import ast; ast.parse(...)"on the modified file — passes.