Diff Coverage

Diff: origin/master...HEAD, staged and unstaged changes

Source File Diff Coverage (%) Missing Lines
hyper_parallel/components/modules/module_family.py 100%  
hyper_parallel/components/modules/moe/grouped_experts/__init__.py 100%  
hyper_parallel/components/modules/moe/grouped_experts/ep/moonep_grouped_experts.py 100%  
hyper_parallel/components/modules/moe/grouped_experts/grouped_experts.py 100%  
hyper_parallel/components/modules/moe/grouped_experts/grouped_experts_family.py 100%  
hyper_parallel/components/modules/moe/grouped_experts/low_precision_grouped_experts.py 89.1% 75-77,179,188-189,239-242,246-253,271,318
hyper_parallel/components/quantization/functional/fake_w4a8_gmm_func.py 100%  
hyper_parallel/components/quantization/functional/hifloat8_gmm_func.py 100%  
hyper_parallel/components/quantization/functional/mxfp8_fused_grouped_swiglu.py 83.8% 35-36,50-51,110,161
hyper_parallel/components/quantization/functional/mxfp8_gmm_func.py 100%  
hyper_parallel/components/quantization/functional/w4a8_gmm_func.py 0.0% 121,124
hyper_parallel/components/quantization/modules/replacement.py 100%  
hyper_parallel/components/modules/moe/grouped_experts/low_precision_grouped_experts.py
71
72
73
74
75
76
77
78
79
80
81
            weight_format="mxfp4", act_format="mxfp8", is_fake_quantize=True, block_size=block_size,
        )
    if low_precision_mode == "hif8":
        return LowPrecisionDtypeScheme(weight_format="hif8", act_format="hif8")
    if isinstance(configured, LowPrecisionDtypeScheme):
        return configured
    raise ValueError(f"Unsupported low-precision grouped-expert mode: {low_precision_mode!r}")


def _is_deepseek_v4_experts(module: nn.Module) -> bool:
    """Identify DeepSeek-V4/V4.1 packed experts without eagerly importing Transformers models."""
175
176
177
178
179
180
181
182
183
        **_: Any,
    ) -> None:
        cfg = owner.config
        if cfg.activation is not None:
            raise ValueError(f"{prefix} requires standard or clamped SwiGLU activation")
        if cfg.routing_weight_mode != "output":
            raise ValueError(f"{prefix}: fused MXFP8 SwiGLU requires routing_weight_mode='output'")
        if cfg.activation_dtype != "input":
            raise ValueError(f"{prefix}: fused MXFP8 SwiGLU requires activation_dtype='input'")
184
185
186
187
188
189
190
191
192
193
        _validate_tile_alignment("mxfp8", block_size, tile_shapes)
        try:
            validate_npu_gmm_runtime()
            validate_npu_swiglu_runtime(clamp_limit=owner.clamp_limit)
        except RuntimeError as exc:
            raise RuntimeError(f"{prefix}: {exc}") from exc
        owner._quantizer = MXFP8Quantizer()  # pylint: disable=protected-access

    def execute(
        self,
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
    def quantizer(self) -> Any:
        """Expose the active quantizer for fused executors and single-quantizer strategies."""
        if "_quantizer" in self.__dict__:
            return self._quantizer
        grouped_linear = self.__dict__.get("grouped_linear")
        if grouped_linear is not None and hasattr(grouped_linear, "quantizer"):
            return grouped_linear.quantizer
        raise AttributeError(f"{type(self).__name__!r} has no single quantizer attribute")

    @quantizer.setter
    def quantizer(self, value: Any) -> None:
        if "_quantizer" in self.__dict__:
            self._quantizer = value
            return
        grouped_linear = self.__dict__.get("grouped_linear")
        if grouped_linear is not None and hasattr(grouped_linear, "quantizer"):
            grouped_linear.quantizer = value
            return
        self._quantizer = value

    def _init_low_precision_executor(
        self,
        *,
267
268
269
270
271
272
273
274
275
        self.clamp_limit = self.config.swiglu_limit
        self.activation_func = self._apply_swiglu
        executor_cls = _EXECUTOR_CLASSES.get(low_precision_mode)
        if executor_cls is None:
            raise ValueError(f"Unsupported low-precision grouped-expert mode: {low_precision_mode!r}")
        tile_shapes = (tuple(self.gate_up_proj.shape), tuple(self.down_proj.shape))
        block_size = getattr(effective_context.get("low_precision"), "block_size", MX_BLOCK_SIZE_32)
        self.executor = executor_cls(
            self,
314
315
316
317
318
319
320
321
322
            or gate_up.shape[0] < 1
            or gate_up.shape[1:] != (2 * cfg.intermediate_size, cfg.hidden_size)
            or down.shape != (gate_up.shape[0], cfg.hidden_size, cfg.intermediate_size)
        ):
            raise ValueError("expert compute requires complete [C,2I,H] and [C,H,I] matrices; ETP is unsupported")
        if tokens_per_expert.ndim != 1 or tokens_per_expert.shape != (gate_up.shape[0],):
            raise ValueError(f"{self.fqn}: counts must contain one count per local expert")
        if tokens_per_expert.dtype not in (torch.int32, torch.int64):
            raise ValueError(f"{self.fqn}: counts must be integers")
hyper_parallel/components/quantization/functional/mxfp8_fused_grouped_swiglu.py
31
32
33
34
35
36
37
38
39
40
    metadata = []
    buffers = []
    for operand in operands:
        if operand is None:
            metadata.append(None)
            buffers.extend((None,) * 4)
        else:
            metadata.append((tuple(operand.shape), operand.dtype, operand.quantizer))
            buffers.extend((operand.row_data, operand.row_scale, operand.col_data, operand.col_scale))
    ctx.operand_metadata = tuple(metadata)
46
47
48
49
50
51
52
53
54
55
    counts, projected, *buffers = ctx.saved_tensors
    operands = []
    for index, meta in enumerate(ctx.operand_metadata):
        if meta is None:
            operands.append(None)
            continue
        shape, dtype, quantizer = meta
        row, row_scale, col, col_scale = buffers[4 * index:4 * index + 4]
        operands.append(MXFP8Tensor(shape, dtype, quantizer=quantizer, row_data=row,
                                   row_scale=row_scale, col_data=col, col_scale=col_scale))
106
107
108
109
110
111
112
113
114
        ctx.dtype, ctx.device, ctx.quantizer = inputs.dtype, inputs.device, quantizer
        ctx.clamp_limit = clamp_limit
        if inputs.shape[0] == 0:
            ctx.save_for_backward()
            return inputs.new_empty((0, down.shape[1]))
        needs_input = inputs.requires_grad
        needs_gate = gate_up.requires_grad
        needs_down = down.requires_grad
        needs_swiglu_bwd = needs_input or needs_gate
157
158
159
160
161
162
163
164
165
            grads = [torch.zeros(shape, device=ctx.device, dtype=ctx.dtype) if needed else None
                     for shape, needed in zip(ctx.shapes, (needs_input, needs_gate, needs_down))]
            return *grads, None, None, None
        if not (needs_input or needs_gate or needs_down):
            return None, None, None, None, None, None
        counts, projected, (input_q, gate_up_q, activated_q, down_q) = _restore_operands(ctx)
        grad_q = ctx.quantizer.quantize(
            gradient.contiguous(), group_list=counts if needs_down else None, group_list_type=1,
            rowwise=needs_input or needs_gate, colwise=needs_down,
hyper_parallel/components/quantization/functional/w4a8_gmm_func.py
117
118
119
120
121
122
123
124
125
126
127
128

    @staticmethod
    def _select_operands(left, right, layout: str):
        """Select directional data and scales for one native GMM layout on ``[E, O, K]`` weights."""
        if layout == "NT":
            left_data, left_scale = left.row_data, left.row_scale
            right_data, right_scale = right.row_data, right.row_scale
        elif layout == "NN":
            left_data, left_scale = left.row_data, left.row_scale
            right_data, right_scale = right.col_data, right.col_scale
        elif layout == "TN":
            # Preserve transpose strides so the native MX kernel sees the