Skip to content

Commit

Permalink
fix the is_empty logic
Browse files Browse the repository at this point in the history
Signed-off-by: Yu Chin Fabian Lim <[email protected]>
  • Loading branch information
fabianlim committed Jul 9, 2024
1 parent c859361 commit 3ef14a2
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions tuning/config/acceleration_configs/acceleration_framework_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,6 @@ def from_dataclasses(*dataclasses: Type):
return config

def get_framework(self):
if self.is_empty():
return

if is_fms_accelerate_available():

Expand All @@ -174,17 +172,31 @@ def get_framework(self):
NamedTemporaryFile,
)

with NamedTemporaryFile("w") as f:
self.to_yaml(f.name)
return AccelerationFramework(f.name)
try:
with NamedTemporaryFile("w") as f:
self.to_yaml(f.name)
return AccelerationFramework(f.name)
except ValueError as e:
(msg,) = e.args

# AcceleratorFramework raises ValueError if it
# fails to configure any plugin
if self.is_empty() and msg.startswith("No plugins could be configured"):
# in the case when the error was thrown when
# the acceleration framework config was empty
# then this is expected.
return None

raise e
else:
raise ValueError(
"No acceleration framework package found. To use, first "
"ensure that 'pip install fms-hf-tuning[fms-accel]' is done first to "
"obtain the acceleration framework dependency. Additional "
"acceleration plugins make be required depending on the requsted "
"acceleration. See README.md for instructions."
)
if not self.is_empty():
raise ValueError(
"No acceleration framework package found. To use, first "
"ensure that 'pip install fms-hf-tuning[fms-accel]' is done first to "
"obtain the acceleration framework dependency. Additional "
"acceleration plugins make be required depending on the requsted "
"acceleration. See README.md for instructions."
)

def is_empty(self):
"check if the configuration is empty"
Expand Down

0 comments on commit 3ef14a2

Please sign in to comment.