跳到主要内容
版本:0.6.4

swcli runtime

概述

swcli [全局选项] runtime [选项] <SUBCOMMAND> [参数]...

runtime 命令包括以下子命令:

  • activate(actv)
  • build
  • copy(cp)
  • dockerize
  • extract
  • history
  • info
  • list(ls)
  • recover
  • remove(rm)
  • tag

swcli runtime activate

swcli [全局选项] runtime activate [选项] <RUNTIME>

runtime activate 根据指定的运行时创建一个全新的 Python 环境,类似 source venv/bin/activateconda activate xxx 的效果。关闭当前 shell 或切换到其他 shell 后,需要重新激活 Runtime。URI 参数为 Runtime URI。

对于已经激活的 Starwhale 运行时,如果想要退出该环境,需要在 venv 环境中执行 deactivate 命令或conda环境中执行 conda deactivate 命令。

runtime activate 命令首次激活环境的时候,会根据 Starwhale 运行时的定义,构建一个 Python 隔离环境,并下载相关的 Python Packages ,可能会花费比较的时间。

swcli runtime build

swcli [全局选项] runtime build [选项]

runtime build 命令可以从多种环境或 runtime.yaml ,构建一个可以分享、可以复现的适合 ML/DL 领域的运行环境。

参数说明

  • 运行时构建方式的相关参数:
选项必填项类型默认值说明
-c--condaNString通过 conda env name 寻找对应的 conda 环境,导出 Python 依赖后生成 Starwhale 运行时。
-cp--conda-prefixNString通过 conda env prefix 路径寻找对应的 conda 环境,导出 Python 依赖后生成 Starwhale 运行时。
-v--venvNString通过 venv 目录地址寻找对应的 venv 环境,导出 Python 依赖后生成 Starwhale 运行时。
-s--shellNString根据当前 shell 环境,导出 Python 依赖后生成 Starwhale 运行时。
-y--yamlNcwd 目录的 runtime.yaml根据用户自定义的 runtime.yaml 构建 Starwhale 运行时。
-d--dockerNString将 docker image 作为 Starwhale 运行时。

运行时构建方式的相关参数是互斥的,只能指定一种方式,如果不指定,则会采用 --yaml 方式读取 cwd 目录下的 runtime.yaml 文件进行 Starwhale 运行时的构建。

  • 其他参数:
选项必填项作用域类型默认值说明
--project-pN全局String默认项目项目URI
-del--disable-env-lockNruntime.yaml 模式BooleanFalse是否安装 runtime.yaml 中的依赖,并锁定相关依赖的版本信息。默认会锁定依赖。
-nc--no-cacheNruntime.yaml 模式BooleanFalse是否删除隔离环境,全新安装相关依赖。默认会在之前的隔离环境中安装依赖。
--cudaNconda/venv/shell 模式Choice[11.3/11.4/11.5/11.6/11.7/]CUDA 版本,默认不使用 CUDA。
--cudnnNconda/venv/shell 模式Choice[8/]cuDNN 版本,默认不使用 cuDNN。
--archNconda/venv/shell 模式Choice[amd64/arm64/noarch]noarch体系结构
-dpo--dump-pip-optionsN全局BooleanFalse~/.pip/pip.conf 导出 pip 的配置参数。
-dcc--dump-condarcN全局BooleanFalse~/.condarc 导出 conda 的配置参数。
-t--tagN全局String用户自定义标签,可以指定多次。

Starwhale 运行时构建的例子

#- from runtime.yaml:
swcli runtime build # use the current directory as the workdir and use the default runtime.yaml file
swcli runtime build -y example/pytorch/runtime.yaml # use example/pytorch/runtime.yaml as the runtime.yaml file
swcli runtime build --yaml runtime.yaml # use runtime.yaml at the current directory as the runtime.yaml file
swcli runtime build --tag tag1 --tag tag2

#- from conda name:
swcli runtime build -c pytorch # lock pytorch conda environment and use `pytorch` as the runtime name
swcli runtime build --conda pytorch --name pytorch-runtime # use `pytorch-runtime` as the runtime name
swcli runtime build --conda pytorch --cuda 11.4 # specify the cuda version
swcli runtime build --conda pytorch --arch noarch # specify the system architecture

#- from conda prefix path:
swcli runtime build --conda-prefix /home/starwhale/anaconda3/envs/pytorch # get conda prefix path by `conda info --envs` command

#- from venv prefix path:
swcli runtime build -v /home/starwhale/.virtualenvs/pytorch
swcli runtime build --venv /home/starwhale/.local/share/virtualenvs/pytorch --arch amd64

#- from docker image:
swcli runtime build --docker pytorch/pytorch:1.9.0-cuda11.1-cudnn8-runtime # use the docker image as the runtime directly

#- from shell:
swcli runtime build -s --cuda 11.4 --cudnn 8 # specify the cuda and cudnn version
swcli runtime build --shell --name pytorch-runtime # lock the current shell environment and use `pytorch-runtime` as the runtime name

swcli runtime copy

swcli [全局选项] runtime copy [选项] <SRC> <DEST>

runtime copy 将 runtime 从 SRC 复制到 DEST,可以实现不同实例之间的运行时分享。这里 SRCDEST 都是运行时URI

Starwhale 运行时复制时,默认会带上用户自定义的所有标签,可以使用 --ignore-tag 参数,忽略某些标签。另外,latest^v\d+$ 标签是 Starwhale 系统内建标签,只在当前实例中使用,不会拷贝到其他实例中。

选项必填项类型默认值说明
--force-fNBooleanFalse如果为true,DEST已经存在时会被强制覆盖。否则此命令会显示一条错误消息。另外,如果复制时携带的标签已经被其他版本使用,通过该参数可以强制更新标签到此版本上。
-i--ignore-tagNString可以指定多次,忽略多个用户自定义标签。

Starwhale 运行时复制的例子

#- copy cloud instance(pre-k8s) mnist project's mnist-cloud runtime to local project(myproject) with a new runtime name 'mnist-local'
swcli runtime cp cloud://pre-k8s/project/mnist/mnist-cloud/version/ge3tkylgha2tenrtmftdgyjzni3dayq local/project/myproject/mnist-local

#- copy cloud instance(pre-k8s) mnist project's mnist-cloud runtime to local default project(self) with the cloud instance runtime name 'mnist-cloud'
swcli runtime cp cloud://pre-k8s/project/runtime/mnist/mnist-cloud/version/ge3tkylgha2tenrtmftdgyjzni3dayq .

#- copy cloud instance(pre-k8s) mnist project's mnist-cloud runtime to local project(myproject) with the cloud instance runtime name 'mnist-cloud'
swcli runtime cp cloud://pre-k8s/project/mnist/mnist-cloud/version/ge3tkylgha2tenrtmftdgyjzni3dayq . -dlp myproject

#- copy cloud instance(pre-k8s) mnist project's mnist-cloud runtime to local default project(self) with a runtime name 'mnist-local'
swcli runtime cp cloud://pre-k8s/project/runtime/mnist/mnist-cloud/version/ge3tkylgha2tenrtmftdgyjzni3dayq mnist-local

#- copy cloud instance(pre-k8s) mnist project's mnist-cloud runtime to local project(myproject) with a runtime name 'mnist-local'
swcli runtime cp cloud://pre-k8s/project/mnist/mnist-cloud/version/ge3tkylgha2tenrtmftdgyjzni3dayq mnist-local -dlp myproject

#- copy standalone instance(local) default project(self)'s mnist-local runtime to cloud instance(pre-k8s) mnist project with a new runtime name 'mnist-cloud'
swcli runtime cp mnist-local/version/latest cloud://pre-k8s/project/mnist/mnist-cloud

#- copy standalone instance(local) default project(self)'s mnist-local runtime to cloud instance(pre-k8s) mnist project with standalone instance runtime name 'mnist-local'
swcli runtime cp mnist-local/version/latest cloud://pre-k8s/project/mnist

#- copy standalone instance(local) default project(self)'s mnist-local runtime to cloud instance(pre-k8s) mnist project without 'cloud://' prefix
swcli runtime cp mnist-local/version/latest pre-k8s/project/mnist

#- copy standalone instance(local) project(myproject)'s mnist-local runtime to cloud instance(pre-k8s) mnist project with standalone instance runtime name 'mnist-local'
swcli runtime cp local/project/myproject/runtime/mnist-local/version/latest cloud://pre-k8s/project/mnist

#- copy without some tags
swcli runtime cp pytorch cloud://cloud.starwhale.cn/project/starwhale:public --ignore-tag t1

swcli runtime dockerize

swcli [全局选项] runtime dockerize [选项] <RUNTIME>

runtime dockerize 基于指定的 runtime 创建一个 docker 镜像。Starwhale 使用 docker buildx 来创建镜像。运行此命令需要预先安装 Docker 19.03 以上的版本。

RUNTIME是一个运行时URI

选项必填项类型默认值说明
--tag or -tNStringDocker镜像的tag,该选项可以重复多次。
--pushNBooleanFalse是否将创建的镜像推送到docker registry。
--platformNStringamd64镜像的运行平台,可以是amd64或者arm64。该选项可以重复多次用于创建多平台镜像。
--dry-runNBooleanFalse只生成 Dockerfile 不实际生成和推送镜像。

swcli runtime extract

swcli [全局选项] runtime extract [选项] <RUNTIME>

Starwhale 运行时以压缩包的方式分发,使用 runtime extract 命令可以解压运行时 Package,然后进行后续的自定义修改。

选项必填项类型默认值说明
--force-fNBooleanFalse如果目标目录已经有解压好的 Starwhale 运行时,是否删除后重新解压。
--target-dirNString自定义解压的目录,如果不指定则会放到 Starwhale 默认的运行时 workdir 目录中,命令输出日志中会提示。

swcli runtime history

swcli [全局选项] runtime history [选项] <RUNTIME>

runtime history输出指定Starwhale运行时的所有历史版本。

RUNTIME是一个运行时URI

选项必填项类型默认值说明
--fullnameNBooleanFalse显示完整的版本名称。如果没有使用该选项,则仅显示前 12 个字符。

swcli runtime info

swcli [全局选项] runtime info [选项] <RUNTIME>

runtime info输出指定Starwhale运行时版本的详细信息。

RUNTIME是一个运行时URI

选项必填项类型默认值说明
--output-filter-ofNChoice of [basic/runtime_yaml/manifest/lock/all]basic设置输出的过滤规则,比如只显示Runtime的runtime.yaml。目前该参数仅对Standalone Instance的Runtime生效。

Starwhale 运行时查看详情的例子

swcli runtime info pytorch # show basic info from the latest version of runtime
swcli runtime info pytorch/version/v0 # show basic info
swcli runtime info pytorch/version/v0 --output-filter basic # show basic info
swcli runtime info pytorch/version/v1 -of runtime_yaml # show runtime.yaml content
swcli runtime info pytorch/version/v1 -of lock # show auto lock file content
swcli runtime info pytorch/version/v1 -of manifest # show _manifest.yaml content
swcli runtime info pytorch/version/v1 -of all # show all info of the runtime

swcli runtime list

swcli [全局选项] runtime list [选项]

runtime list显示所有的 Starwhale 运行时。

选项必填项类型默认值说明
--projectNString要查看的项目的URI。如果未指定此选项,则使用默认项目替代。
--fullnameNBooleanFalse显示完整的版本名称。如果没有使用该选项,则仅显示前 12 个字符。
--show-removedNBooleanFalse如果使用了该选项,则结果中会包含已删除但未被垃圾回收的运行时。
--pageNInteger1起始页码。仅限Server和Cloud实例。
--sizeNInteger20一页中的运行时数量。仅限Server和Cloud实例。
--filter-flNString仅显示符合条件的运行时。该选项可以在一个命令中被多次重复使用。
过滤器类型说明范例
nameKey-Value运行时名称前缀--filter name=pytorch
ownerKey-Value运行时所有者名字--filter owner=starwhale
latestFlag如果指定了该选项,结果中仅显示最新版本。--filter latest

swcli runtime recover

swcli [全局选项] runtime recover [选项] <RUNTIME>

runtime recover 命令可以恢复以前删除的 Starwhale 运行时。

RUNTIME是一个运行时URI。如果URI不包含版本,则会恢复所有删除的版本。

已经被垃圾回收或者使用 --force 选项删除的 Starwhale 运行时或版本无法使用本命令恢复。

选项必填项类型默认值说明
--force-fNBooleanFalse如果使用了该选项,当前同名的Starwhale运行时或版本会被强制覆盖。

swcli runtime remove

swcli [全局选项] runtime remove [选项] <RUNTIME>

runtime remove 命令可以删除指定的 Starwhale 运行时或某个版本。

RUNTIME 是一个运行时URI。如果 URI 不包含版本,则删除所有版本。

被删除的 Starwhale 运行时或版本可以在垃圾回收之前通过 swcli runtime recover 命令恢复。要永久删除某个 Starwhale 运行时或版本,您可以使用 --force 选项。

被删除的 Starwhale 运行时或版本可以通过 swcli runtime list --show-removed 列出。

选项必填项类型默认值说明
--force-fNBooleanFalse使用此选项永久删除某个 Starwhale 运行时或版本。删除后不可恢复。

swcli runtime tag

swcli [全局选项] runtime tag [选项] <RUNTIME> [TAGS]...

runtime tag 命令将标签附加到指定的 Starwhale 运行时版本,同时支持删除和列出所有标签的功能。可以在运行时URI中使用标签替代版本 ID。

RUNTIME 是一个运行时URI

每个运行时版本可以包含任意数量的标签,但同一运行时中不允许有重复的标签名称。

runtime tag仅适用于 Standalone 实例.

选项必填项类型默认值说明
--remove-rNBooleanFalse使用该选项删除标签
--quiet-qNBooleanFalse使用该选项以忽略错误,例如删除不存在的标签。
--force-add-fNBooleanFalse当向 server/cloud 实例中添加标签时,若遇到其他版本的运行时已经使用该标签会提示报错,强制更新时可以使用 --force-add 参数。

Starwhale 运行时标签的例子

#- list tags of the pytorch runtime
swcli runtime tag pytorch

#- add tags for the pytorch runtime
swcli runtime tag mnist t1 t2
swcli runtime tag cloud://cloud.starwhale.cn/project/public:starwhale/runtime/pytorch/version/latest t1 --force-add
swcli runtime tag mnist t1 --quiet

#- remove tags for the pytorch runtime
swcli runtime tag mnist -r t1 t2
swcli runtime tag cloud://cloud.starwhale.cn/project/public:starwhale/runtime/pytorch --remove t1