Skip to content

Commit f5dbfc3

Browse files
authored
Fix error on import whenever accelerate is absent (#342)
Before, if accelerate is absent, the `check_accelerate` decorator would generate an error at import time whenever `@check_accelerate(fallback="error")` is specified. After it fails only if the particular function is called.
1 parent d330744 commit f5dbfc3

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/compressed_tensors/utils/offload.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ def decorator(func: Callable[[Any], Any]):
8787
if not _has_accelerate:
8888

8989
if fallback == "error":
90-
raise ValueError(
91-
"Please install `accelerate` in order to use this function"
92-
)
93-
94-
@wraps(func)
95-
def fallback_fn(*args, **kwargs):
96-
return fallback
90+
@wraps(func)
91+
def fallback_fn(*args, **kwargs):
92+
raise ValueError(
93+
"Please install `accelerate` in order to use this function"
94+
)
95+
else:
96+
@wraps(func)
97+
def fallback_fn(*args, **kwargs):
98+
return fallback
9799

98100
return fallback_fn
99101

0 commit comments

Comments
 (0)