Skip to content

cli

Functions:

  • clear

    Delete downloaded ONNX models or built TensorRT & MIGraphxX artifacts.

  • download

    Download ONNX models.

  • meta_main
  • show

    List downloaded ONNX models or built TensorRT & MIGraphxX artifacts.

Attributes:

MAX_CONCURRENCY module-attribute

MAX_CONCURRENCY = cpu_count() or 4

app module-attribute

app = App(
    name="vsscale",
    version=__version__,
    help="CLI utility for managing machine learning models and TensorRT/MIGraphX artifacts for VapourSynth.",
    help_on_error=True,
    console=console,
    config=[
        Env("VSSCALE_"),
        Toml(TOML_CONFIG[0], root_keys=TOML_KEYS[0], allow_unknown=True),
        Toml(TOML_CONFIG[1], root_keys=TOML_KEYS[1], allow_unknown=True),
    ],
)

artifact_app module-attribute

artifact_app = App(
    name="artifact", help="Manage built TensorRT and MIGraphxX artifacts."
)

console module-attribute

console = Console(stderr=True)

onnx_app module-attribute

onnx_app = App(name='onnx', help='Manage downloaded ONNX models.')

clear

clear(
    global_: Annotated[
        bool,
        Parameter(
            negative=(),
            show_default=False,
            env_var=[VSSCALE_CLEAR_GLOBAL, VSSCALE_GLOBAL],
        ),
    ] = False,
) -> None

Delete downloaded ONNX models or built TensorRT & MIGraphxX artifacts.

If no model specs are provided, the entire directory is cleared.

Parameters:

  • global_

    (Annotated[bool, Parameter(negative=(), show_default=False, env_var=[VSSCALE_CLEAR_GLOBAL, VSSCALE_GLOBAL])], default: False ) –

    Whether to clear files in the global folder.

Source code in vsscale/mlrt/cli.py
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
@artifact_app.command(help="Clear built TensorRT & MIGraphxX artifacts.", help_formatter=_custom_help_formatter)
@onnx_app.command(help="Clear downloaded ONNX models.", help_formatter=_custom_help_formatter)
def clear(
    global_: Annotated[
        bool,
        cyclopts.Parameter(negative=(), show_default=False, env_var=["VSSCALE_CLEAR_GLOBAL", "VSSCALE_GLOBAL"]),
    ] = False,
) -> None:
    """
    Delete downloaded ONNX models or built TensorRT & MIGraphxX artifacts.

    If no model specs are provided, the entire directory is cleared.

    Args:
        global_: Whether to clear files in the global folder.
    """
    (cmd, *_), _, _ = app.parse_commands()

    match cmd:
        case "provider":
            folder = get_provider_folder(global_=global_)
        case "artifact":
            folder = get_artifacts_folder(global_=global_)
        case _:
            raise ValueError

    return shutil.rmtree(folder, ignore_errors=True)

download async

download(
    *provider: Annotated[str, Parameter(name=--provider)],
    latest: Annotated[
        bool,
        Parameter(
            negative=(),
            show_default=False,
            env_var=[VSSCALE_ONNX_DOWNLOAD_LATEST, VSSCALE_LATEST],
        ),
    ] = False,
    global_: Annotated[
        bool,
        Parameter(
            negative=(),
            show_default=False,
            env_var=[VSSCALE_ONNX_DOWNLOAD_GLOBAL, VSSCALE_GLOBAL],
        ),
    ] = False,
) -> None

Download ONNX models.

Supports multiple invocation styles
  • Interactive: vsscale onnx download
  • Pick tag for model: vsscale onnx download ArtCNN
  • Pinned version: vsscale onnx download ArtCNN==v1.6.2
  • Latest release: vsscale onnx download ArtCNN --latest

If a vsjet.toml or a pyproject.toml file is detected with a valid configuration, the interactive mode may be partially or fully skipped.

Parameters:

  • provider

    (Annotated[str, Parameter(name=--provider)], default: () ) –

    The ONNX model(s) to download. Possible choices: "ArtCNN", "DPIR", "Waifu2X". Use '==' syntax to pin a version (e.g. ArtCNN==v1.6.2).

  • latest

    (Annotated[bool, Parameter(negative=(), show_default=False, env_var=[VSSCALE_ONNX_DOWNLOAD_LATEST, VSSCALE_LATEST])], default: False ) –

    Whether to automatically download all models from the latest release.

  • global_

    (Annotated[bool, Parameter(negative=(), show_default=False, env_var=[VSSCALE_ONNX_DOWNLOAD_GLOBAL, VSSCALE_GLOBAL])], default: False ) –

    Whether to download models to the global folder.

Source code in vsscale/mlrt/cli.py
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
@onnx_app.command(help_formatter=_custom_help_formatter)
async def download(
    *provider: Annotated[str, cyclopts.Parameter(name="--provider")],
    latest: Annotated[
        bool,
        cyclopts.Parameter(
            negative=(),
            show_default=False,
            env_var=["VSSCALE_ONNX_DOWNLOAD_LATEST", "VSSCALE_LATEST"],
        ),
    ] = False,
    global_: Annotated[
        bool,
        cyclopts.Parameter(
            negative=(),
            show_default=False,
            env_var=["VSSCALE_ONNX_DOWNLOAD_GLOBAL", "VSSCALE_GLOBAL"],
        ),
    ] = False,
) -> None:
    """
    Download ONNX models.

    Supports multiple invocation styles:
      - Interactive:        vsscale onnx download
      - Pick tag for model: vsscale onnx download ArtCNN
      - Pinned version:     vsscale onnx download ArtCNN==v1.6.2
      - Latest release:     vsscale onnx download ArtCNN --latest

    If a `vsjet.toml` or a `pyproject.toml` file is detected with a valid configuration,
    the interactive mode may be partially or fully skipped.

    Args:
        provider: The ONNX model(s) to download. Possible choices: "ArtCNN", "DPIR", "Waifu2X".
            Use '==' syntax to pin a version (e.g. ArtCNN==v1.6.2).
        latest: Whether to automatically download all models from the latest release.
        global_: Whether to download models to the global folder.
    """
    if not provider:
        # Fully interactive: pick model, then tag, then assets
        feed = await _select_model()
        releases = await _fetch_releases(feed)
        release = await _select_tag(releases)
        assets = await _select_assets(release)
        return await _download_assets(feed, release, assets, global_=global_)

    for spec in provider:
        model_name, pinned_version = _parse_model_spec(spec)
        feed = _find_feed(model_name)

        releases = await _fetch_releases(feed)

        if pinned_version is not None:
            release = next((r for r in releases if r.tag == pinned_version), None)

            if not release:
                console.print(f"[red]Error: Version '{pinned_version}' not found.[/red]")
                available_tags = ", ".join(r.tag for r in releases[:10])
                console.print(f"[yellow]Available versions: {available_tags}[/yellow]")
                raise SystemExit(1)

            assets = release.assets
        elif latest:
            release = releases[0]
            assets = release.assets
            console.print(f"[bold]Latest release: {release.tag} ({release.published_at[:10]})[/bold]")
        else:
            release = await _select_tag(releases)
            assets = await _select_assets(release)

        await _download_assets(feed, release, assets, global_=global_)
        console.print()

meta_main

meta_main(
    *tokens: Annotated[str, Parameter(show=False)],
    no_config: Annotated[
        bool,
        Parameter(
            negative=(),
            show_default=False,
            help="Ignore TOML configuration files and environment variables.",
        ),
    ] = False,
) -> None
Source code in vsscale/mlrt/cli.py
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
@app.meta.default
def meta_main(
    *tokens: Annotated[str, cyclopts.Parameter(show=False)],
    no_config: Annotated[
        bool,
        cyclopts.Parameter(
            negative=(),
            show_default=False,
            help="Ignore TOML configuration files and environment variables.",
        ),
    ] = False,
) -> None:
    if no_config:
        app.config = None
    app(tokens)

show

show(
    global_: Annotated[
        bool,
        Parameter(
            negative=(),
            show_default=False,
            env_var=[VSSCALE_SHOW_GLOBAL, VSSCALE_GLOBAL],
        ),
    ] = False,
) -> None

List downloaded ONNX models or built TensorRT & MIGraphxX artifacts.

Parameters:

  • global_

    (Annotated[bool, Parameter(negative=(), show_default=False, env_var=[VSSCALE_SHOW_GLOBAL, VSSCALE_GLOBAL])], default: False ) –

    Whether to show models in the global folder.

Source code in vsscale/mlrt/cli.py
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
@artifact_app.command(help="List built TensorRT & MIGraphxX artifacts.", help_formatter=_custom_help_formatter)
@onnx_app.command(help="List downloaded ONNX models.", help_formatter=_custom_help_formatter)
def show(
    global_: Annotated[
        bool,
        cyclopts.Parameter(
            negative=(),
            show_default=False,
            env_var=["VSSCALE_SHOW_GLOBAL", "VSSCALE_GLOBAL"],
        ),
    ] = False,
) -> None:
    """
    List downloaded ONNX models or built TensorRT & MIGraphxX artifacts.

    Args:
        global_: Whether to show models in the global folder.
    """
    (cmd, *_), _, _ = app.parse_commands()

    match cmd:
        case "provider":
            folder = get_provider_folder(global_=global_)
            ext = [".onnx"]
        case "artifact":
            folder = get_artifacts_folder(global_=global_)
            ext = [".mxr", ".engine", ".cache"]
        case _:
            raise ValueError

    files = (f for f in folder.glob("**/*", case_sensitive=False) if f.suffix in ext)
    return print(pretty_repr(sorted(files, reverse=True)))