Skip to content

cli

Functions:

  • clear

    Delete downloaded ONNX models or built TensorRT & MIGraphxX artifacts.

  • config

    Write or update vsscale configuration in pyproject.toml or vsjet.toml.

  • download

    Download ONNX models.

  • meta_main
  • show

    List downloaded ONNX models or built TensorRT & MIGraphxX artifacts.

  • show_config

    Display the currently active vsscale configuration.

Attributes:

MAX_CONCURRENCY module-attribute

MAX_CONCURRENCY = os.cpu_count() or 4

app module-attribute

app = cyclopts.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(stderr=True),
    config=[
        cyclopts.config.Env("VSSCALE_"),
        cyclopts.config.Toml(
            TOML_CONFIG[0], root_keys=TOML_KEYS[0], allow_unknown=True
        ),
        cyclopts.config.Toml(
            TOML_CONFIG[1], root_keys=TOML_KEYS[1], allow_unknown=True
        ),
    ],
    help_formatter=_custom_help_formatter,
)

artifact_app module-attribute

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

config_app module-attribute

config_app = cyclopts.App(name='config', help='Manage vsscale configuration.')

logger module-attribute

logger = getLogger(__name__)

onnx_app module-attribute

onnx_app = cyclopts.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
@artifact_app.command(help="Clear built TensorRT & MIGraphxX artifacts.")
@onnx_app.command(help="Clear downloaded ONNX models.")
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 "onnx":
            folder = get_onnx_folder(global_=global_)
        case "artifact":
            folder = get_artifacts_folder(global_=global_)
        case _:
            raise ValueError

    return shutil.rmtree(folder, ignore_errors=True)

config

config(
    file: Path | None = None,
    /,
    *provider: str,
    latest: bool | None = None,
    auto: bool | None = None,
    global_: bool | None = None,
    fallback: bool | None = None,
    assumeyes: Annotated[
        bool, Parameter(alias=-y, negative=(), show_default=False)
    ] = False,
) -> None

Write or update vsscale configuration in pyproject.toml or vsjet.toml.

Parameters:

  • file

    (Path | None, default: None ) –

    Target configuration file ('pyproject.toml' or 'vsjet.toml').

  • provider

    (str, default: () ) –

    Default ONNX model(s) to configure (e.g. 'ArtCNN', 'DPIR', 'Waifu2x').

  • latest

    (bool | None, default: None ) –

    Whether to download latest model releases by default.

  • auto

    (bool | None, default: None ) –

    Whether to automatically download missing models on demand.

  • global_

    (bool | None, default: None ) –

    Whether to use global cache directory by default.

  • fallback

    (bool | None, default: None ) –

    Whether to enable global cache fallback.

  • assumeyes

    (Annotated[bool, Parameter(alias=-y, negative=(), show_default=False)], default: False ) –

    Answer yes for all questions and skip interactive wizard.

Source code in vsscale/mlrt/cli.py
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
@config_app.default
def config(
    file: Path | None = None,
    /,
    *provider: str,
    latest: bool | None = None,
    auto: bool | None = None,
    global_: bool | None = None,
    fallback: bool | None = None,
    assumeyes: Annotated[bool, cyclopts.Parameter(alias="-y", negative=(), show_default=False)] = False,
) -> None:
    """
    Write or update vsscale configuration in pyproject.toml or vsjet.toml.

    Args:
        file: Target configuration file ('pyproject.toml' or 'vsjet.toml').
        provider: Default ONNX model(s) to configure (e.g. 'ArtCNN', 'DPIR', 'Waifu2x').
        latest: Whether to download latest model releases by default.
        auto: Whether to automatically download missing models on demand.
        global_: Whether to use global cache directory by default.
        fallback: Whether to enable global cache fallback.
        assumeyes: Answer yes for all questions and skip interactive wizard.
    """
    if file is None:
        toml = "pyproject.toml" if Path("pyproject.toml").exists() else "vsjet.toml"
        if assumeyes:
            target_path = Path(toml)
        else:
            choices = [
                quest.Choice("pyproject.toml", value="pyproject.toml"),
                quest.Choice("vsjet.toml", value="vsjet.toml"),
            ]
            selected = quest.select("Select configuration file target:", choices, toml, qmark="📝").ask()
            if selected is None:
                raise SystemExit(0)
            target_path = Path(selected)
    else:
        target_path = Path(file)

    if not assumeyes:
        if global_ is None:
            global_ = quest.confirm("Use global cache directory by default?", default=False, qmark="🌐").ask()
            if global_ is None:
                raise SystemExit(0)

        if fallback is None:
            fallback = quest.confirm(
                "Enable global cache fallback if local model is missing?", default=True, qmark="🔄"
            ).ask()
            if fallback is None:
                raise SystemExit(0)

        if not provider:
            choices = [quest.Choice(title=name, value=name, checked=True) for name in Feed.all_feeds]
            providers = quest.checkbox("Select default ONNX models to configure:", choices=choices, qmark="📦").ask()
            if providers is None:
                raise SystemExit(0)
            provider = tuple(providers)

        if latest is None:
            latest = quest.confirm("Download latest model release automatically?", default=True, qmark="🏷️").ask()
            if latest is None:
                raise SystemExit(0)

        if auto is None:
            auto = quest.confirm("Auto-download models when used in Python?", default=True, qmark="⚡").ask()
            if auto is None:
                raise SystemExit(0)

    written_path = write_toml_config(
        target_path,
        global_=global_,
        fallback=fallback,
        provider=provider,
        latest=latest,
        auto=auto,
    )

    _display(INFO, "[green]✔ Successfully updated configuration in [bold]%s[/bold][/green]", written_path.name)

download async

download(
    *provider: Annotated[str, Parameter(name=--provider)],
    latest: Annotated[
        bool, Parameter(negative=(), show_default=False, env_var=VSSCALE_LATEST)
    ] = False,
    global_: Annotated[
        bool, Parameter(negative=(), show_default=False, env_var=VSSCALE_GLOBAL)
    ] = False,
    assumeyes: Annotated[
        bool, Parameter(alias=-y, negative=(), show_default=False)
    ] = False,
    console: Annotated[Console | None, Parameter(parse=False)] = None,
) -> 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_LATEST)], default: False ) –

    Whether to automatically download all models from the latest release.

  • global_

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

    Whether to download models to the global folder.

  • assumeyes

    (Annotated[bool, Parameter(alias=-y, negative=(), show_default=False)], default: False ) –

    Answer yes for all questions.

Source code in vsscale/mlrt/cli.py
 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
@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_LATEST"),
    ] = False,
    global_: Annotated[
        bool,
        cyclopts.Parameter(negative=(), show_default=False, env_var="VSSCALE_GLOBAL"),
    ] = False,
    assumeyes: Annotated[
        bool,
        cyclopts.Parameter(alias="-y", negative=(), show_default=False),
    ] = False,
    console: Annotated[Console | None, cyclopts.Parameter(parse=False)] = None,
) -> 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.
        assumeyes: Answer yes for all questions.
    """
    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)
        dest_folder = get_onnx_folder(global_=global_) / feed.display_name.lower() / release.tag
        if not assumeyes:
            await _confirm_download(dest_folder)
        return await _download_assets(feed, assets, dest_folder)

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

        releases = await _fetch_releases(feed, console=console)

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

            if not release:
                raise ValueError(
                    f"Version {pinned_version} not found. Available versions: {', '.join(r.tag for r in releases[:10])}"
                )

            assets = release.assets
        elif latest:
            release = releases[0]
            assets = release.assets
            _display(
                INFO,
                "[bold]Latest release for %s: %s (%s)[/bold]",
                feed.display_name,
                release.tag,
                release.published_at[:10],
            )
        else:
            release = await _select_tag(releases)
            assets = await _select_assets(release)

        dest_folder = get_onnx_folder(global_=global_) / feed.display_name.lower() / release.tag

        if not assumeyes:
            await _confirm_download(dest_folder)
        await _download_assets(feed, assets, dest_folder, console=console)
        _display(INFO, "")

meta_main

meta_main(
    *tokens: Annotated[str, Parameter(show=False, allow_leading_hyphen=True)],
    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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
@app.meta.default
def meta_main(
    *tokens: Annotated[str, cyclopts.Parameter(show=False, allow_leading_hyphen=True)],
    no_config: Annotated[
        bool,
        cyclopts.Parameter(
            negative=(),
            show_default=False,
            help="Ignore TOML configuration files and environment variables.",
        ),
    ] = False,
) -> None:
    os.environ["VSSCALE_CLI"] = "1"
    if no_config:
        app.config = None
    try:
        app(tokens)
    except Exception as e:  # noqa: BLE001
        app.console.print(f"[red]{e.__class__.__name__}:[/red] {e}")
        raise SystemExit(1)

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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
@artifact_app.command(help="List built TensorRT & MIGraphxX artifacts.")
@onnx_app.command(help="List downloaded ONNX models.")
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 "onnx":
            folder = get_onnx_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)))

show_config

show_config() -> None

Display the currently active vsscale configuration.

Source code in vsscale/mlrt/cli.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
@config_app.command(name="show")
def show_config() -> None:
    """Display the currently active vsscale configuration."""
    config = get_toml_config()
    detected_file = None
    for config_file in TOML_CONFIG:
        p = Path(config_file).expanduser().resolve().absolute()
        if p.exists():
            detected_file = p
            break

    if detected_file:
        _display(INFO, "[bold]Active configuration file:[/bold] [cyan]%s[/cyan]", detected_file)
    else:
        _display(WARNING, "No active configuration file found.")

    _display(INFO, pretty_repr(config))