Add missing -> bool return type hints in utils/imports.py - #4123
Open
RudrenduPaul wants to merge 1 commit into
Open
Add missing -> bool return type hints in utils/imports.py#4123RudrenduPaul wants to merge 1 commit into
RudrenduPaul wants to merge 1 commit into
Conversation
Adds -> bool to is_torch_xla_available, is_bf16_available, is_mps_available, is_mlu_available, is_musa_available, is_npu_available, is_sdaa_available, is_hpu_available, and is_xpu_available, matching the existing precedent set by is_torch_distributed_available() -> bool.
This was referenced Jul 18, 2026
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
-> boolreturn type hints to nineis_*_availabledevice/feature-checkhelper functions in
src/accelerate/utils/imports.py, matching the existingprecedent set by
is_torch_distributed_available() -> boolin the same file.This is a self-identified typing-consistency fix (no linked issue) — the file
already establishes the
-> boolconvention for one helper but severalsibling functions with identical return semantics were left unannotated.
Functions updated
is_torch_xla_availableis_bf16_availableis_mps_availableis_mlu_availableis_musa_availableis_npu_availableis_sdaa_availableis_hpu_availableis_xpu_availableEach of these functions returns only
boolvalues on every code path(verified by reading the full function body of each before annotating).
Scope note: torchao_required / deepspeed_required intentionally excluded
Both are decorator factories that take a
funcargument and return awrappercallable (viafunctools.wraps) — they never returnbool.Adding
-> boolto them would be a factually incorrect type hint, so theywere left unannotated in this PR rather than introduce an inaccurate
signature. Happy to follow up with a correct
Callable-based annotationfor those two in a separate PR if maintainers want it.
No behaviour change
Type-hint-only change. No logic was modified.
Testing
ruff check src/accelerate/utils/imports.py— 6 pre-existing findings,none on changed lines, none introduced by this change (verified against
upstream
mainbefore/after).ruff format --check src/accelerate/utils/imports.py— passes, filealready formatted.
python3 -m py_compileon the modified file — passes.