MCPcopy Create free account
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 hidden_states = torch.nn.functional.pad(hidden_states, (0, pad))
93 return weights, hidden_states
94
95
96def shard_weights(weights: torch.Tensor, tp: TPInfo) -> torch.Tensor:
97 """Shard weights along vocab dim (same as vLLM's VocabParallelEmbedding.weight_loader)."""
98 if tp.size == 1:
99 return weights # early return for single-GPU case
100 shard_size = weights.shape[0] // tp.size
101 start_idx = tp.rank * shard_size
102 shard = weights.narrow(0, start_idx, shard_size)
103 assert shard.is_contiguous()
104 return shard
105

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