Optimize single-group grouped MLP quantization#3184
Conversation
Signed-off-by: Siddhartha Raman Sundara Raman <sraman@nvidia.com>
|
/te-ci pytorch |
| if metadata_key not in self._single_group_split_metadata_cache: | ||
| self._single_group_split_metadata_cache[metadata_key] = ( | ||
| _single_group_split_metadata( | ||
| in_shape[0], | ||
| device, | ||
| fc1_in_features=fc1_weight_shape[1], | ||
| fc2_in_features=fc2_weight_shape[1], | ||
| fc2_out_features=fc2_weight_shape[0], | ||
| ) | ||
| ) | ||
| ( | ||
| split_sizes, | ||
| split_points, | ||
| base_split_offsets, | ||
| fc1_x_tensor_offsets, | ||
| fc2_x_tensor_offsets, | ||
| fc2_out_tensor_offsets, | ||
| ) = self._single_group_split_metadata_cache[metadata_key] |
There was a problem hiding this comment.
Unbounded cache growth for variable token counts
_single_group_split_metadata_cache is a plain dict with no eviction policy. The key includes in_shape[0] (the token count), which changes on every call with a different batch/sequence length. Even though tokens must be multiples of 128, a long-running inference service with variable-length inputs will accumulate one cache entry per unique token count encountered — each entry holding six GPU tensors. Over time this is a steady memory leak.
| and isinstance(grouped_x.quantizer, (MXFP8Quantizer, NVFP4Quantizer)) | ||
| and isinstance(grouped_dy.quantizer, grouped_x.quantizer.__class__) |
There was a problem hiding this comment.
The quantizer-type guard for the single-group wgrad optimization uses
isinstance(grouped_dy.quantizer, grouped_x.quantizer.__class__). This is asymmetric: if grouped_x carries a subclass of MXFP8Quantizer, the check requires grouped_dy to be that same subclass (or a further subclass), not just a compatible MXFP8Quantizer. The symmetrical pattern used everywhere else in the file is more robust.
| and isinstance(grouped_x.quantizer, (MXFP8Quantizer, NVFP4Quantizer)) | |
| and isinstance(grouped_dy.quantizer, grouped_x.quantizer.__class__) | |
| and isinstance(grouped_x.quantizer, (MXFP8Quantizer, NVFP4Quantizer)) | |
| and type(grouped_x.quantizer) == type(grouped_dy.quantizer) |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Description
Please include a brief summary of the changes, relevant motivation and context.
Fixes # (issue)
Type of change
Changes
Please list the changes introduced in this PR:
Checklist: