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

update config to ignore unset key in defaults #683

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ public DeepspeedContainerBuildConfig(String sessionId, long processorId,
this.workingDir = containerWorkspace.toAbsolutePath();

Map<String, byte[]> updatedFiles = new HashMap<>(files);
updatedFiles.put(scriptPath, runScript);
this.workingDirectoryPreparer = new WorkingDirectoryPreparer();
this.workingDirectoryPreparer.setFiles(updatedFiles);
this.workingDirectoryPreparer.setZippedFiles(zippedFiles);
Expand Down Expand Up @@ -97,5 +96,6 @@ public DeepspeedContainerBuildConfig(String sessionId, long processorId,
"main(\"%s\")\n" +
"\n",this.options.get(Dict.DEEPSPEED_SCRIPT_PATH)).getBytes();
this.scriptPath = "_boost.py";
updatedFiles.put(scriptPath, runScript);
}
}
28 changes: 19 additions & 9 deletions python/eggroll/config/config.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import configparser
import logging
import pprint
import typing

import omegaconf

from eggroll.config.defaults import DefaultConfig

logger = logging.getLogger(__name__)


class Config(object):
"""
Expand All @@ -27,16 +30,16 @@ def load_default(self):
def load_properties(self, config_file):
c = configparser.ConfigParser()
c.read(config_file)
dot_list = [f"{k}={v}" for k, v in c.items("eggroll") if v != ""]
dot_list_config = omegaconf.OmegaConf.from_dotlist(dot_list)
self.config = omegaconf.OmegaConf.merge(self.config, dot_list_config)
for k, v in c.items("eggroll"):
if v == "":
continue
ConfigUtils.maybe_update(self.config, k, v)
self.loaded_history.append(f"load_properties: {config_file}")
return self

def load_options(self, options: dict):
dot_list = [f"{k}={v}" for k, v in options.items()]
dot_list_config = omegaconf.OmegaConf.from_dotlist(dot_list)
self.config = omegaconf.OmegaConf.merge(self.config, dot_list_config)
for k, v in options.items():
ConfigUtils.maybe_update(self.config, k, v)
self.loaded_history.append(f"load_options: {options}")
return self

Expand All @@ -46,10 +49,10 @@ def load_env(self):
accept_envs = []
for k, v in os.environ.items():
if k.lower().startswith("eggroll."):
if v == "":
continue
ConfigUtils.maybe_update(self.config, k.lower(), v.lower())
accept_envs.append(f"{k.lower()}={v.lower()}")

env_config = omegaconf.OmegaConf.from_dotlist(accept_envs)
self.config = omegaconf.OmegaConf.merge(self.config, env_config)
self.loaded_history.append(f"load_env:\n " + "\n ".join(accept_envs))
return self

Expand Down Expand Up @@ -92,6 +95,13 @@ def set(
else:
raise ValueError(f"config type={type(config)} not supported")

@staticmethod
def maybe_update(c: omegaconf.Container, k, v):
try:
omegaconf.OmegaConf.update(c, k, v)
except omegaconf.errors.OmegaConfBaseException as e:
logger.warning(f"update `{k}` to `{v}` failed, skip:\n{e}")

@staticmethod
def get_option(config: Config, option: dict, key: typing.Any):
assert isinstance(key, DotKey)
Expand Down
8 changes: 8 additions & 0 deletions python/eggroll/config/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,13 @@ class LoginConfig:
@dataclass
class ContainerConfig:
@dataclass
class PythonConfig:
@dataclass
class ExecConfig:
path: str = MISSING

exec: ExecConfig = ExecConfig()
@dataclass
class DeepspeedConfig:
@dataclass
class PythonConfig:
Expand All @@ -431,6 +438,7 @@ class ScriptConfig:
script: ScriptConfig = ScriptConfig()

deepspeed: DeepspeedConfig = DeepspeedConfig()
python: PythonConfig = PythonConfig()

@dataclass
class CoreConfig:
Expand Down