lightseekorg--tokenspeed
59a0a3844c
PR Test AMD / cancel-on-close (push) Has been skipped
PR Test NVIDIA ARM / scan (push) Has been skipped
PR Test NVIDIA / cancel-on-close (push) Has been skipped
PR Test AMD / scan (push) Has been skipped
PR Test NVIDIA ARM / cancel-on-close (push) Has been skipped
PR Test NVIDIA / scan (push) Has been skipped
Release Docker Images / build (cu129-torch-2.11.0) (push) Has been skipped
Release Docker Images / build (cu130-torch-2.11.0) (push) Has been skipped
Release PyPI / publish (push) Has been skipped
Scheduler Python Test / test (push) Successful in 27m19s
Docs / build (push) Successful in 28m8s
Scheduler C++ Test / test (push) Successful in 28m19s
Scheduler C++ Test / test-flat (push) Successful in 28m18s
Docs / deploy (push) Has been cancelled
PR Test AMD / finish (push) Has been cancelled
PR Test NVIDIA / finish (push) Has been cancelled
PR Test NVIDIA ARM / finish (push) Has been cancelled
PR Test NVIDIA ARM / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
PR Test AMD / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
PR Test NVIDIA / ${{ matrix.name }} (${{ matrix.runner }}) (push) Has been cancelled
48 行
1.3 KiB
Python
48 行
1.3 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
import torch
|
|
|
|
from tokenspeed.runtime.layers.moe import topk as topk_module
|
|
from tokenspeed.runtime.layers.moe.topk import TopKConfig, select_experts
|
|
|
|
|
|
@pytest.mark.parametrize("renormalize", [False, True])
|
|
def test_correction_bias_route_forwards_renormalize(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
renormalize: bool,
|
|
) -> None:
|
|
calls: list[bool] = []
|
|
|
|
def fake_cuda_routing_flash(
|
|
_router_logits: torch.Tensor,
|
|
_correction_bias: torch.Tensor,
|
|
topk_ids: torch.Tensor,
|
|
topk_weights: torch.Tensor,
|
|
_num_real_experts: int,
|
|
_routed_scaling_factor: float,
|
|
renorm: bool,
|
|
) -> None:
|
|
calls.append(renorm)
|
|
topk_ids.fill_(0)
|
|
topk_weights.fill_(1.0)
|
|
|
|
monkeypatch.setattr(
|
|
topk_module,
|
|
"cuda_routing_flash",
|
|
fake_cuda_routing_flash,
|
|
)
|
|
|
|
select_experts(
|
|
hidden_states=torch.empty((1, 4), dtype=torch.float32),
|
|
router_logits=torch.empty((1, 8), dtype=torch.float32),
|
|
topk_config=TopKConfig(
|
|
top_k=2,
|
|
renormalize=renormalize,
|
|
correction_bias=torch.zeros((8,), dtype=torch.float32),
|
|
routed_scaling_factor=1.0,
|
|
),
|
|
)
|
|
|
|
assert calls == [renormalize]
|