Python class
WeightPathParser
WeightPathParser
class max.pipelines.lib.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:
>>> 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:
-
Returns:
-
A tuple of
(processed_weight_paths, weights_repo_id). -
Raises:
-
ValueError – If weight paths are invalid or cannot be processed.
-
Return type:
Was this page helpful?
Thank you! We'll create more content like this.
Thank you for helping us improve!