.torchxconfig¶
状态:Beta 版
您可以存储项目的调度程序 run cfg (run configs)
将它们存储在文件中。目前,此文件仅被读取
并在从 CLI 运行组件时 honored 执行。.torchxconfig
CLI 使用情况¶
调度器配置
cd
到要放置文件的目录中。 CLI 仅从当前工作目录 (CWD) 中选取文件 因此,请选择您通常运行的目录。通常,此 是项目目录的根目录。.torchxconfig
.torchxconfig
torchx
通过运行
$ torchx configure -s <comma,delimited,scheduler,names> # -- or for all registered schedulers -- $ torchx configure
如果指定了 ,您应该会看到如下所示的文件:
-s local_cwd,kubernetes
.torchxconfig
$ cat .torchxconfig [local_cwd] [kubernetes] queue = #FIXME:(str) Volcano queue to schedule job in
.torchxconfig
in 中,并且节名称映射到调度程序名称。 每个部分都包含调度程序的运行配置成对。 您可能会发现某些调度程序有空部分,这意味着 调度器为其所有运行配置定义了合理的默认值,因此没有运行配置 在运行时是必需的。如果您想覆盖默认值,可以添加它们。提示:要查看调度程序的所有运行选项,请使用 。$key = $value
torchx runopts <scheduler_name>
带有占位符的部分是必需的运行配置 由调度程序。将这些值替换为适用于您的值。
FIXME
重要:如果您对调度程序为特定的 运行 config,则不应使用 相同的默认值。这是因为调度程序可能会决定更改默认值 值,这将使您获得过时的默认值。
.torchxconfig
现在,您无需指定调度程序运行配置即可运行组件 每次。只需确保您运行 cli 的目录实际上是 有 !
torchx
.torchxconfig
$ ls .torchxconfig .torchxconfig $ torchx run -s local_cwd ./my_component.py:train
此外,还可以指定 .torchxconfig 以外的其他配置来 load 在运行时加载。要求配置路径由环境指定 变量 TORCHX_CONFIG。它还禁用了来自多个 目录。
用户级别 .torchxconfig 除了项目目录根目录下的项目级 .torchxconfig 之外, 您可以在 IN 中创建一个 IN 来覆盖或指定其他默认配置。 此配置文件将覆盖在项目根目录中定义的配置文件之上。
$HOME/.torchxconfig
- Config 选项的优先级如下(从高到低):
直接从 CLI 指定的选项
如果设置了 TORCHXCONFIG 环境变量,则该文件中指定的选项
- 如果未设置 TORCHXCONFIG 环境变量,
在用户级别 .torchxconfig 中指定的选项 (
$HOME/.torchxconfig
)在 .torchxconfig 中指定的选项
代码中的任何默认值
请注意,格式错误或无法识别的选项只会被跳过而不应用
组件配置
您可以通过添加前缀为 的节来指定组件默认值。component:
[component:dist.ddp]
j=2x8
cpu=4
现在,当您运行组件时,这些配置会自动
捡起来。dist.ddp
$ torchx run -s local_cwd dist.ddp
... runs with -j 2x8 --cpu 4
CLI 子命令配置
可以覆盖子命令的默认参数。任何参数都可以通过相应的设置进行设置
块。torchx
--foo FOO
[cli:<cmd>]
对于该命令,您还可以设置以将
default 组件运行。run
component
[cli:run]
component=dist.ddp
scheduler=local_docker
workspace=file://some_workspace
编程用法¶
与 cli 不同,文件不会自动选取
from (如果你以编程方式运行组件).torchxconfig
CWD
torchx.runner.Runner
.
您必须手动指定包含 ..torchxconfig
下面是一个示例
from torchx.runner import get_runner
from torchx.runner.config import apply
import torchx.specs as specs
def my_component(a: int) -> specs.AppDef:
# <... component body omitted for brevity ...>
pass
scheduler = "local_cwd"
cfg = {"log_dir": "/these/take/outmost/precedence"}
apply(scheduler, cfg, dirs=["/home/bob"]) # looks for /home/bob/.torchxconfig
get_runner().run(my_component(1), scheduler, cfg)
您还可以指定多个目录(按前面的顺序),这在以下情况下很有用 您希望将 Personal Config Overrides 保留在 Project defined default 之上。
配置 API 函数¶
- torchx.runner.config 的 Git.apply(scheduler: str, cfg: Dict[str, 可选[Union[str、 int、 float、 bool、 List[str]]]]、目录: 可选[List[str]] = 无) 无 [来源]¶
从指定的目录加载 INI 文件 前面的 order 并将调度程序的运行配置应用于 给定的 .
.torchxconfig
cfg
如果未指定 no,则它会在 当前工作目录。如果指定的目录没有,则忽略该目录。
dirs
.torchxconfig
.torchxconfig
请注意,给定中已经存在的配置优先 在配置文件中的配置上,并且仅添加新的配置。同样的情况 true,用于按列表顺序加载的配置。
cfg
例如,如果 和 配置文件为:
cfg={"foo":"bar"}
# dir_1/.torchxconfig [local_cwd] foo = baz hello = world # dir_2/.torchxconfig [local_cwd] hello = bob
然后在方法调用之后, .
cfg={"foo":"bar","hello":"world"}
- torchx.runner.config 的 Git.load(scheduler: str, f: TextIO, cfg: Dict[str, 可选[Union[str, int, float, bool, List[str]]]]) → 无[来源]¶
从给定的 configfile(在 .INI 格式)添加到提供的 当前不在给定的 Config 中(例如,没有 覆盖 中的现有值)。如果未找到截面,则不执行任何作。
[{scheduler}]
f
runcfg
runcfg
runcfg
- torchx.runner.config 的 Git.dump(f: TextIO, schedulers: 可选[List[str]] = 无,required_only:bool = False)无[来源]¶
转储默认的 INI 样式配置模板,其中包含 :p y:class:torchx.specs.runopts 的 给定的调度程序名称放入 指定的类文件对象中。 如果指定了 no,则转储所有已知的已注册调度程序。
f
schedulers
可选的 runopts 预先填充了其默认值。 必需的 runopts 使用占位符进行设置。 要仅转储所需的 runopts pass .
FIXME: ...
required_only=True
每个调度程序的 runopts 都写在名为 的部分中。
[{scheduler_name}]
例如:
[kubernetes] namespace = default queue = #FIXME (str)Volcano queue to schedule job in
- 提升:
ValueError – 如果给定的调度程序名称未知
- torchx.runner.config 的 Git.find_configs(dirs: Optional[Iterable[str]] = None) List[str] [来源]¶
查找并返回基于文件的文件路径 在以下逻辑上:
.torchxconfig
如果环境变量存在,则其值 在单元素列表中返回,并且通过 不搜索参数。
TORCHXCONFIG
dirs
否则,将在 和 中查找文件 返回现有配置文件的文件路径。如果是 未指定或为空,则默认为 CWD 是当前工作目录的位置。
.torchxconfig
dirs
dirs
dirs
[$HOME, $CWD]
- torchx.runner.config 的 Git.get_configs(前缀: str, 名称: str, 目录: 可选[List[str]] = 无) Dict[str, str] [来源]¶
获取 section 中的所有 config 值。 或者如果该部分不存在,则为空地图。
["{prefix}:{name}"]
例:
# for config file: # [foo:bar] # baz = 1 get_configs(prefix="foo", name="bar") # returns {"baz": "1"} get_config(prefix="foo", name="barr") # returns {}
- torchx.runner.config 的 Git.get_config(前缀:str,名称:str,键:str,目录: 可选[List[str]] = None) 可选[str] [source]¶
获取 section 中 的 config 值。 或者,如果不存在部分或键
key
["{prefix}:{name}"]
None
例:
# for config file: # [foo:bar] # baz = 1 get_config(prefix="foo", name="bar", key="baz") == 1 get_config(prefix="foo", name="bar", key="bazz") == None get_config(prefix="foo", name="barr", key="baz") == None get_config(prefix="fooo", name="bar", key="baz") == None
- torchx.runner.config 的 Git.load_sections(前缀: str, dirs: 可选[List[str]] = 无) Dict[str, Dict[str, str] ][来源]¶
加载给定文件中各部分的内容 以指定的前缀开头。返回 section name 不带加载的 section 内容的前缀 导入到地图中。 用作前缀分隔符。
.torchxconfig
":"
为内置 组件如下所示:
dist.ddp
[component:dist.ddp] j = 1x2 image = ghcr.io/foo:1 # calling `load_sections(prefix="component")` returns # { # "dist.ddp": { # "j":"1x2", # "image":"ghcr.io/foo:1", # }, # }
该部分中的键必须与组件函数的参数名称匹配。 下面的示例显示了如何表示允许的各种类型 作为组件参数类型。
[component:foo.bar] int = 1 float = 1.2 bool = True # or False str = foobar list = a,b,c map = A=B,C=D vararg = -a b --c=d e # to call the component as: foo.bar( "-a", "b", "--c=d", "e", int=1, float=1.2, bool=True, str="foobar", list=["a", "b", "c"], map={"A":"B", "C": "D"})