MCPcopy Index your code
hub / github.com/FlashSampling/FlashSampling / shard_weights

Function shard_weights

src/fused_mm_sampling/testing.py:94–102  ·  view source on GitHub ↗

Shard weights along vocab dim (same as vLLM's VocabParallelEmbedding.weight_loader).

(weights: torch.Tensor, tp: TPInfo)

Source from the content-addressed store, hash-verified

92
93
94def shard_weights(weights: torch.Tensor, tp: TPInfo) -> torch.Tensor:
95 """Shard weights along vocab dim (same as vLLM's VocabParallelEmbedding.weight_loader)."""
96 if tp.size == 1:
97 return weights # early return for single-GPU case
98 shard_size = weights.shape[0] // tp.size
99 start_idx = tp.rank * shard_size
100 shard = weights.narrow(0, start_idx, shard_size)
101 assert shard.is_contiguous()
102 return shard
103
104
105def assert_sampling_distribution(

Callers 4

mainFunction · 0.90
make_synthetic_inputsFunction · 0.85
benchmarkFunction · 0.85
make_fn_kwargsMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected