(测试版).torchxconfig 文件¶
您可以存储项目的调度程序 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
编程用法¶
与 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]]]], dirs: 可选[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, Optional[Union[str, int, float, bool, List[str]]]]) → None[来源]¶
从给定的 configfile(在 .INI 格式)添加到提供的 当前不在给定的 Config 中(例如,没有 覆盖 中的现有值)。如果未找到截面,则不执行任何作。
[{scheduler}]
f
runcfg
runcfg
runcfg
- torchx.runner.config 的 Git.dump(f: TextIO, schedulers: 可选[List[str]] = None, 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 – 如果给定的调度程序名称未知