Diff Coverage

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

Source File Diff Coverage (%) Missing Lines
hyper_parallel/components/modules/family.py 92.0% 85,169
hyper_parallel/components/modules/linear.py 100%  
hyper_parallel/components/modules/low_precision_grouped_experts.py 91.1% 63,68,88-89,91
hyper_parallel/components/modules/low_precision_linear.py 82.4% 43,45,47
hyper_parallel/components/quantization/modules/replacement.py 100%  
hyper_parallel/trainer/config/parallelism.py 80.0% 664,667
hyper_parallel/trainer/config/replacement.py 92.6% 53,82
hyper_parallel/trainer/config/resolver.py 100%  
hyper_parallel/components/modules/family.py
81
82
83
84
85
86
87
88
        _validate_selector_value(family, name, spec.default)
        for alias in spec.aliases:
            if (not isinstance(alias, str) or not alias.isidentifier()
                    or alias in names or alias in _RESERVED_SELECTORS):
                raise ValueError(f"ModuleFamily {family.name}: invalid selector alias {alias!r}")
            names.add(alias)
        defaults[name] = spec.default
    return defaults
165
166
167
168
169
170
171
172
173
        Read-only declarations including aliases, or an empty mapping.
    """
    family = get_module_family(target)
    if family is None:
        return {}
    return MappingProxyType({
        spelling: spec for name, spec in family.selector_specs.items()
        for spelling in (name, *spec.aliases)
    })
hyper_parallel/components/modules/low_precision_grouped_experts.py
59
60
61
62
63
64
65
66
67
68
69
70
71
72
            context: Existing replacement context containing the resolved low_precision policy.
        """
        prefix = f"{module_fqn or '<root>'}: LowPrecisionGroupedExperts"
        if any(context.get(axis) for axis in ("tp", "cp", "ep", "pp")) or context.get("ep_size", 1) != 1:
            raise NotImplementedError(f"{prefix} requires TP=CP=EP=PP=1")
        super().__init__(module=module, module_fqn=module_fqn, context=context)
        activation = getattr(self.config, "hidden_act", "silu")
        if (not self.has_gate or self.add_bias or self.use_2d_experts
                or not self.router_gating_in_fp32 or activation not in ("silu", "swiglu")):
            raise ValueError(f"{prefix} requires 3D bias-free SwiGLU with routing scores after GMM2")
        self.grouped_linear = strategy
        _validate_tile_alignment(
            "fake_w4a8" if isinstance(strategy, FakeW4A8GroupedLinear) else strategy.FORMAT_NAME,
            context["low_precision"].block_size,
84
85
86
87
88
89
90
91
92
93
94

    def _grouped_gemm_expert_forward(self, gate_up_proj, down_proj, permuted,
                                     tokens_per_expert, permuted_probs):
        """Adapt layout at the shared strategy boundary; outer routing applies scores."""
        del permuted_probs
        projected = _GroupedLinearFunction.apply(
            permuted, gate_up_proj.transpose(-2, -1), tokens_per_expert, self.grouped_linear, 1)
        return _GroupedLinearFunction.apply(
            self.activation_func(projected), down_proj.transpose(-2, -1),
            tokens_per_expert, self.grouped_linear, 1)

hyper_parallel/components/modules/low_precision_linear.py
39
40
41
42
43
44
45
46
47
48
49
    Returns:
        The existing low-precision Linear with an MXFP8 strategy.
    """
    if type(module) is not nn.Linear:  # pylint: disable=unidiomatic-typecheck
        raise TypeError(f"{module_fqn!r} must be exact nn.Linear, got {type(module).__name__}")
    if module.in_features % 32 or module.out_features % 32:
        raise ValueError(f"{module_fqn!r}: MXFP8 Linear requires feature dimensions divisible by 32")
    if context.get("pp"):
        raise NotImplementedError(f"{module_fqn!r}: MXFP8 Linear does not support pipeline parallelism")
    validate_npu_runtime()
    return LowPrecisionLinear.from_linear(module, strategy=MXFP8LinearStrategy())
hyper_parallel/trainer/config/parallelism.py
660
661
662
663
664
665
666
667
668
669
670
671
        policy = None
        scheme_name = getattr(entry.replace.implementation, "low_precision_dtype_scheme", None)
        if scheme_name is not None:
            if entry.low_precision_dtype_scheme is not None:
                raise ValueError(
                    f"plan_overrides match={entry.match!r}: specify dtype scheme only inside replace.implementation")
            if low_precision_config is None:
                raise ValueError(f"plan_overrides match={entry.match!r}: dtype scheme requires training.low_precision")
            policy = low_precision_config.resolve_dtype_scheme(scheme_name)
        elif entry.when == "low_precision" and effective_config is not None:
            policy = effective_config.resolve_dtype_scheme(entry.low_precision_dtype_scheme)
        rules.append(
hyper_parallel/trainer/config/replacement.py
49
50
51
52
53
54
55
56
57
        if low_precision_dtype_scheme is None:
            resolved, arguments = resolve_module_family_target(_target_, kwargs)
        else:
            if not isinstance(low_precision_dtype_scheme, str) or not low_precision_dtype_scheme.strip():
                raise ValueError("low_precision_dtype_scheme must be a non-empty catalog name")
            # The catalog belongs to training configuration and is unavailable while parsing this Target.
            resolved = _target_
            arguments = {name: value for name, value in kwargs.items() if name not in selector_specs}
        super().__init__(resolved, target_path=target_path, **arguments)
78
79
80
81
82
83
84
85
86

    def build(self, **runtime_kwargs: Any) -> Any:
        """Build only after a named scheme has been bound by the replacement planner."""
        if self.low_precision_dtype_scheme is not None:
            raise ValueError("Bind low_precision_dtype_scheme through the replacement plan before building")
        return super().build(**runtime_kwargs)

    def get_family_selector_spec(self, name: str) -> SelectorSpec | None:
        """Query the requested baseline's schema for Target-level overrides.