Skip to content

llmcompressor.entrypoints.model_free.helpers

build_weights_map

build_weights_map(
    weight_map: dict[str, str], model_files: dict[str, str]
) -> dict[str, str]

Build a mapping of tensor name -> resolved file path from the model's weight_map (index.json). This allows any process to locate fused partner tensors from other shards without loading entire files.

Parameters:

  • weight_map (dict[str, str]) –

    mapping of tensor name -> shard filename (from index.json)

  • model_files (dict[str, str]) –

    mapping of shard filename -> resolved absolute path

Returns:

  • dict[str, str]

    mapping of tensor name -> resolved absolute path

Source code in src/llmcompressor/entrypoints/model_free/helpers.py
def build_weights_map(
    weight_map: dict[str, str],
    model_files: dict[str, str],
) -> dict[str, str]:
    """
    Build a mapping of tensor name -> resolved file path from the model's
    weight_map (index.json). This allows any process to locate fused partner
    tensors from other shards without loading entire files.

    :param weight_map: mapping of tensor name -> shard filename (from index.json)
    :param model_files: mapping of shard filename -> resolved absolute path
    :return: mapping of tensor name -> resolved absolute path
    """
    return {
        tensor_name: model_files[shard_name]
        for tensor_name, shard_name in weight_map.items()
        if shard_name in model_files
    }