Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add defaults for compute_environmnent #23

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/accelerate/commands/config/config_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def load_config_from_file(config_file):
config_file = config_file if config_file is not None else default_config_file
with open(config_file, "r", encoding="utf-8") as f:
if config_file.endswith(".json"):
if json.load(f)["compute_environment"] == ComputeEnvironment.LOCAL_MACHINE:
if json.load(f).get("compute_environment", ComputeEnvironment.LOCAL_MACHINE):
config_class = ClusterConfig
else:
config_class = SageMakerConfig
return config_class.from_json_file(json_file=config_file)
else:
if yaml.safe_load(f)["compute_environment"] == ComputeEnvironment.LOCAL_MACHINE:
if yaml.safe_load(f).get("compute_environment", ComputeEnvironment.LOCAL_MACHINE):
config_class = ClusterConfig
else:
config_class = SageMakerConfig
Expand All @@ -73,7 +73,10 @@ def to_dict(self):
def from_json_file(cls, json_file=None):
json_file = default_json_config_file if json_file is None else json_file
with open(json_file, "r", encoding="utf-8") as f:
return cls(**json.load(f))
config_dict = json.load(f)
if "compute_environment" not in config_dict:
config_dict["compute_environment"] = ComputeEnvironment.LOCAL_MACHINE
return cls(**config_dict)

def to_json_file(self, json_file):
with open(json_file, "w", encoding="utf-8") as f:
Expand All @@ -84,7 +87,10 @@ def to_json_file(self, json_file):
def from_yaml_file(cls, yaml_file=None):
yaml_file = default_yaml_config_file if yaml_file is None else yaml_file
with open(yaml_file, "r", encoding="utf-8") as f:
return cls(**yaml.safe_load(f))
config_dict = yaml.safe_load(f)
if "compute_environment" not in config_dict:
config_dict["compute_environment"] = ComputeEnvironment.LOCAL_MACHINE
return cls(**config_dict)

def to_yaml_file(self, yaml_file):
with open(yaml_file, "w", encoding="utf-8") as f:
Expand Down