For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).
Python class
WeightPathParser
WeightPathParser
class max.pipelines.weights.WeightPathParser
Bases: object
Parses and validates weight paths for model configuration.
parse()
static parse(model_path, weight_path)
Parses weight paths and extracts any weights repo ID.
For example:
from pathlib import Path
from max.pipelines.weights.weight_path_parser import WeightPathParser
WeightPathParser.parse("org/model", "path/to/weights.safetensors")
WeightPathParser.parse(
"org/model",
["path/to/weights1.safetensors", "path/to/weights2.safetensors"],
)
# -> ([Path("path/to/weights1.safetensors"),
# Path("path/to/weights2.safetensors")], None)
WeightPathParser.parse("org/model", Path("path/to/weights.safetensors"))
# -> ([Path("path/to/weights.safetensors")], None)
# A path under model_path's own repo is relative to that repo.
WeightPathParser.parse("org/model", "org/model/weights.safetensors")
# -> ([Path("weights.safetensors")], None)
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:
-
Returns:
-
A tuple of
(processed_weight_paths, weights_repo_id). -
Raises:
-
ValueError – If weight paths are invalid or cannot be processed.
-
Return type: