Add binary group quantization and WebGPU sampler fixes for Bonsai/WebLLM - #3472
Add binary group quantization and WebGPU sampler fixes for Bonsai/WebLLM#3472HMDRAMS-DEV wants to merge 1 commit into
Conversation
Register q1f16_0 for Qwen3 models, fix target-kind checks used by WebGPU compiler passes, and add a regression test for sampler attachment on WebGPU. Made-with: Cursor
There was a problem hiding this comment.
Code Review
This pull request introduces binary group quantization (1-bit weights with per-group FP16 scales) to the MLC LLM framework. It includes the implementation of BinaryGroupQuantize, BinaryGroupQuantizeLinear, and BinaryGroupQuantizeEmbedding modules, along with integration into the Qwen3 model configuration. Additionally, the PR refactors target kind checks across several compiler passes to use .kind.name for consistency and adds unit tests for the GPU sampler attachment logic. Feedback is provided regarding the tensor parallel alignment check in the new quantization module, where using tirx.ceildiv is recommended to ensure consistent group count calculations when dimensions are not multiples of the group size.
| if num_shards > 1 and (in_features * num_shards // config.group_size) % num_shards != 0: | ||
| raise ValueError( | ||
| f"The linear dimension {in_features * num_shards} has " | ||
| f"{in_features * num_shards // config.group_size} groups under group size " | ||
| f"{config.group_size}. The groups cannot be evenly distributed on " | ||
| f"{num_shards} GPUs.\n" | ||
| "Possible solutions: reduce number of GPUs, or use quantization with smaller " | ||
| "group size." | ||
| ) |
There was a problem hiding this comment.
The tensor parallel alignment check uses in_features * num_shards // config.group_size to calculate the total number of groups. However, if the global input dimension is not a multiple of the group size, this floor division will underestimate the total group count compared to the ceildiv used for num_group on line 285. This could lead to a ValueError even if the shards are correctly sized, or conversely, allow an invalid configuration if the total groups cannot be evenly distributed. It is safer to use tirx.ceildiv for the global group count calculation to ensure consistency with the per-shard allocation.
| if num_shards > 1 and (in_features * num_shards // config.group_size) % num_shards != 0: | |
| raise ValueError( | |
| f"The linear dimension {in_features * num_shards} has " | |
| f"{in_features * num_shards // config.group_size} groups under group size " | |
| f"{config.group_size}. The groups cannot be evenly distributed on " | |
| f"{num_shards} GPUs.\n" | |
| "Possible solutions: reduce number of GPUs, or use quantization with smaller " | |
| "group size." | |
| ) | |
| if num_shards > 1 and (tirx.ceildiv(in_features * num_shards, config.group_size)) % num_shards != 0: | |
| raise ValueError( | |
| f"The linear dimension {in_features * num_shards} has " | |
| f"{tirx.ceildiv(in_features * num_shards, config.group_size)} groups under group size " | |
| f"{config.group_size}. The groups cannot be evenly distributed on " | |
| f"{num_shards} GPUs.\n" | |
| "Possible solutions: reduce number of GPUs, or use quantization with smaller " | |
| "group size." | |
| ) |
Summary
q1f16_0binary group quantization support and wire it into Qwen3 quantization registrationwebgpucorrectlyTest plan
tests/python/compiler_pass/test_attach_sampler.pyregression testq1f16_0path can be selected for Qwen3 modelsNotes
mlc-llmchanges onlyMade with Cursor