IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Python class

WeightPathParser

WeightPathParser​

class max.pipelines.weights.WeightPathParser

source

Bases: object

Parses and validates weight paths for model configuration.

parse()​

static parse(model_path, weight_path)

source

Parses weight paths and extracts any weights repo ID.

For example:

>>> WeightPathParser.parse("org/model", "path/to/weights.safetensors")
(["path/to/weights.safetensors"], None)

>>> WeightPathParser.parse("org/model", ["path/to/weights1.safetensors", "path/to/weights2.safetensors"])
(["path/to/weights1.safetensors", "path/to/weights2.safetensors"], None)

>>> WeightPathParser.parse("org/model", Path("path/to/weights.safetensors"))
([Path("path/to/weights.safetensors")], None)

>>> WeightPathParser.parse("org/model", "org/model/weights.safetensors")
([Path("weights.safetensors")], "org/model")

>>> WeightPathParser.parse("org/model", ["local_weights.safetensors", "other_org/other_model/remote_weights.safetensors"])
([Path("local_weights.safetensors"), Path("remote_weights.safetensors")], "other_org/other_model")

When the weight path does not have a Hugging Face prefix, file_exists returns False and the whole path is treated as a local path:

>>> WeightPathParser.parse("org/model", "very/nested/subfolder/another_nested/weights.safetensors")
([Path("very/nested/subfolder/another_nested/weights.safetensors")], None)

If model_path is empty and the repo ID cannot be derived, a ValueError is raised.

Parameters:

  • model_path (str) – The model path to use for parsing the weight path(s).
  • weight_path (list[Path] | list[str] | tuple[Path, ...] | tuple[str, ...] | Path | str) – The weight path(s) to parse. Can be a single path, tuple, or list.

Returns:

A tuple of (processed_weight_paths, weights_repo_id).

Raises:

ValueError – If weight paths are invalid or cannot be processed.

Return type:

tuple[list[Path], str | None]