Download code/offload/dspark/spark/remote_dspark/probability_buffers.py from ProprietaryLegal/dsv41-sampled-drafting: direct link, hf CLI and curl.
- Browser
- Download file 1.3 kB
-
https://huggingface.co/ProprietaryLegal/dsv41-sampled-drafting/resolve/main/code/offload/dspark/spark/remote_dspark/probability_buffers.py
- Command line
-
hf download hf://ProprietaryLegal/dsv41-sampled-drafting/code/offload/dspark/spark/remote_dspark/probability_buffers.py
-
curl -L -o probability_buffers.py https://huggingface.co/ProprietaryLegal/dsv41-sampled-drafting/resolve/main/code/offload/dspark/spark/remote_dspark/probability_buffers.py
1.3 kB
| """Sparse transport -> FP32 full-vocabulary probabilities for standard rejection. | |
| The target vocabulary is never truncated to the sparse proposal support. State | |
| is indexed by engine request slots, not current batch order. Failed replies have | |
| valid=False; the probability-aware runner must invalidate every draft for them. | |
| """ | |
| from __future__ import annotations | |
| import torch | |
| class ProbabilityBuffers: | |
| def __init__(self, slots: int, depth: int, vocab: int, device: torch.device): | |
| self.probs = torch.zeros(slots, depth, vocab, dtype=torch.float32, device=device) | |
| self.valid = torch.zeros(slots, dtype=torch.bool, device=device) | |
| self.batch = torch.empty_like(self.probs) | |
| def update(self, mapping: torch.Tensor, support: torch.Tensor, q: torch.Tensor, | |
| ok: torch.Tensor) -> None: | |
| n = mapping.numel() | |
| if (support.shape != (n, self.probs.shape[1], 32) or q.shape != support.shape | |
| or q.dtype != torch.float32 or ok.shape != (n,)): | |
| raise ValueError('sparse probability GPU buffer ABI mismatch') | |
| dense = self.batch[:n] | |
| dense.zero_() | |
| dense.scatter_(2, support.long(), q) | |
| idx = mapping.long() | |
| self.probs.index_copy_(0, idx, dense) | |
| self.valid.index_copy_(0, idx, ok.bool()) | |