公用程式¶
這包含 TorchX 公用程式元件,這些元件是 開箱即用 的。這些元件只是執行眾所周知的二進制檔案(例如 cp
),並且旨在用作教學材料或工作流程中有意義的階段之間的黏合操作。
- torchx.components.utils.echo(msg: str = 'hello world', image: str = 'ghcr.io/pytorch/torchx:0.7.0', num_replicas: int = 1) AppDef [原始碼]¶
將訊息回顯到 stdout(呼叫 echo)
- 參數:
msg – 要回顯的訊息
image – 要使用的映像檔
num_replicas – 要執行的副本數量
- torchx.components.utils.touch(file: str, image: str = 'ghcr.io/pytorch/torchx:0.7.0') AppDef [原始碼]¶
觸碰檔案(呼叫 touch)
- 參數:
file – 要建立的檔案
image – 要使用的映像檔
- torchx.components.utils.sh(*args: str, image: str = 'ghcr.io/pytorch/torchx:0.7.0', num_replicas: int = 1, cpu: int = 1, gpu: int = 0, memMB: int = 1024, h: Optional[str] = None, env: Optional[Dict[str, str]] = None, max_retries: int = 0, mounts: Optional[List[str]] = None) AppDef [原始碼]¶
透過 sh 執行提供的命令。目前 sh 不支援環境變數替換。
- 參數:
args – bash 參數
image – 要使用的映像檔
num_replicas – 要執行的副本數量
cpu – 每個複本的 CPU 數量
gpu – 每個複本的 GPU 數量
memMB – 每個複本的 CPU 記憶體,單位為 MB
h – 已註冊的命名資源(如果指定,則優先於 cpu、gpu、memMB)
env – 要傳遞到執行的環境變數(例如 ENV1=v1,ENV2=v2,ENV3=v3)
max_retries – 允許的排程器重試次數
mounts – 掛載到工作環境/容器的掛載點(例如 type=<bind/volume>,src=/host,dst=/job[,readonly])。如需更多資訊,請參閱排程器文件。
- torchx.components.utils.copy(src: str, dst: str, image: str = 'ghcr.io/pytorch/torchx:0.7.0') AppDef [原始碼]¶
copy 會將檔案從 src 複製到 dst。src 和 dst 可以是任何有效的 fsspec url。
這不支援遞迴複製或目錄。
- 參數:
src – 來源 fsspec 檔案位置
dst – 目的地 fsspec 檔案位置
image – 包含複製應用程式的映像檔
- torchx.components.utils.python(*args: str, m: Optional[str] = None, c: Optional[str] = None, script: Optional[str] = None, image: str = 'ghcr.io/pytorch/torchx:0.7.0', name: str = 'torchx_utils_python', cpu: int = 1, gpu: int = 0, memMB: int = 1024, h: Optional[str] = None, num_replicas: int = 1) AppDef [原始碼]¶
在指定的映像檔和主機上,使用指定的模組、指令或指令碼執行
python
。使用--
區分元件參數和程式參數(例如torchx run utils.python --m foo.main -- --args to --main
)- 注意:(cpu、gpu、memMB) 參數與
h
(命名資源)互斥,其中 如果指定使用
h
來設定資源需求,則h
優先。請參閱註冊命名資源。
- 參數:
args – 傳遞到 sys.argv[1:] 中程式的參數(使用 –c 時會忽略)
m – 將程式庫模組作為指令碼執行
c – 以字串形式傳遞的程式(如果排程器對參數有長度限制,可能會發生錯誤)
script – 要執行的 .py 指令碼
image – 要執行的映像檔
name – 作業的名稱
cpu – 每個複本的 CPU 數量
gpu – 每個複本的 GPU 數量
memMB – 每個複本的 CPU 記憶體,單位為 MB
h – 已註冊的命名資源(如果指定,則優先於 cpu、gpu、memMB)
num_replicas – 要執行的副本數(每個副本都在自己的容器中)
- 傳回值:
- 注意:(cpu、gpu、memMB) 參數與
- torchx.components.utils.booth(x1: float, x2: float, trial_idx: int = 0, tracker_base: str = '/tmp/torchx-util-booth', image: str = 'ghcr.io/pytorch/torchx:0.7.0') AppDef [原始碼]¶
評估 booth 函數,
f(x1, x2) = (x1 + 2*x2 - 7)^2 + (2*x1 + x2 - 5)^2
。輸出結果可透過FsspecResultTracker(outdir)[trial_idx]
存取- 參數:
x1 – x1
x2 – x2
trial_idx – 如果沒有執行 hpo,請忽略
tracker_base – 追蹤器基本輸出目錄的 URI(例如 s3://foo/bar)
image – 包含 booth 應用程式的映像檔
- torchx.components.utils.binary(*args: str, entrypoint: str, name: str = 'torchx_utils_binary', num_replicas: int = 1, cpu: int = 1, gpu: int = 0, memMB: int = 1024, h: Optional[str] = None) AppDef [source]¶
測試組件
- 參數:
args – 傳遞到 sys.argv[1:] 中程式的參數(使用 –c 時會忽略)
name – 作業的名稱
num_replicas – 要執行的副本數(每個副本都在自己的容器中)
cpu – 每個複本的 CPU 數量
gpu – 每個複本的 GPU 數量
memMB – 每個複本的 CPU 記憶體,單位為 MB
h – 已註冊的命名資源(如果指定,則優先於 cpu、gpu、memMB)
- 傳回值: