Skip to content

Detailed size estimation + fix #193 (overestimating fused QKV storage)#194

Open
mratsim wants to merge 2 commits into
turboderp-org:masterfrom
mratsim:detailed-size-est
Open

Detailed size estimation + fix #193 (overestimating fused QKV storage)#194
mratsim wants to merge 2 commits into
turboderp-org:masterfrom
mratsim:detailed-size-est

Conversation

@mratsim

@mratsim mratsim commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

This PR does 2 things related to size:

  1. Fix [Bug] storage_size (TP) overestimates allocation of fused linear layers like QKV / QKVZ #193, for fused QKV layers, when key_q, key_k, key_v are not set, self.key is undefined and storage will used the FP16 formula here:

    @cached_property
    def _storage_size(self):
    # alt_key is only used when loading unquantized model
    if self.is_exl3_storage(self.key):
    return sum(self.config.stc.get_tensor_sizes(prefix = self.key))
    else:
    return 2 * self.in_features * self.out_features
    def storage_size(self):
    return self._storage_size
    def recons_size(self):
    return 2 * self.in_features * self.out_features
    def make_tp_allocation(self, options: dict) -> list[TPAllocation]:
    storage = 0
    storage += self.storage_size()
    overhead_d = self.out_features * (self.out_dtype or torch.half).itemsize
    overhead_s = self.out_features * (self.out_dtype or torch.half).itemsize
    recons = self.recons_size()
    tpa = TPAllocation(
    key = self.key,
    channel_width = 128,
    channel_unit = "channels",
    storage_per_device = 0,
    storage_to_split = storage,
    overhead_per_device = overhead_d,
    overhead_to_split = overhead_s,
    recons_temp = recons,
    channels_to_split = self.out_features // 128,
    limit_key = "linear"
    )
    return [tpa]

    This can be fixed simply by setting those keys at the model architecture level.

  2. This expands model.py with get_detailed_weights_info that is then used by size_estimation.py for detailed statistics.

I noticed 2 things:

  • Convolution has no weights_numel set if weights are not loaded so I added a formula to compute it from metadata.
  • Linear doesn't count the number of elements in the bias, that might affect TP allocation and might be a bug. I don't count the number of elements in convolution bias to mirror Linear layers.

@mratsim

mratsim commented Apr 16, 2026

Copy link
Copy Markdown
Contributor Author

The output of size_estimation.py looks like this now
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] storage_size (TP) overestimates allocation of fused linear layers like QKV / QKVZ

1 participant