Promote latest kernel artifacts to main
Browse files- .gitattributes +3 -35
- README.md +0 -9
- benchmarks/benchmark.py +90 -0
- build/torch211-cxx11-cu128-x86_64-linux/__init__.py +105 -0
- build/torch211-cxx11-cu128-x86_64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu128-x86_64-linux/_speculative_draft_primitives_cuda_6ee7cab.abi3.so +3 -0
- build/torch211-cxx11-cu128-x86_64-linux/metadata.json +23 -0
- build/torch211-cxx11-cu128-x86_64-linux/speculative_draft_primitives/__init__.py +26 -0
- build/torch211-cxx11-cu130-x86_64-linux/__init__.py +105 -0
- build/torch211-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch211-cxx11-cu130-x86_64-linux/_speculative_draft_primitives_cuda_6ee7cab.abi3.so +3 -0
- build/torch211-cxx11-cu130-x86_64-linux/metadata.json +22 -0
- build/torch211-cxx11-cu130-x86_64-linux/speculative_draft_primitives/__init__.py +26 -0
- build/torch212-cxx11-cu130-x86_64-linux/__init__.py +105 -0
- build/torch212-cxx11-cu130-x86_64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu130-x86_64-linux/_speculative_draft_primitives_cuda_6ee7cab.abi3.so +3 -0
- build/torch212-cxx11-cu130-x86_64-linux/metadata.json +22 -0
- build/torch212-cxx11-cu130-x86_64-linux/speculative_draft_primitives/__init__.py +26 -0
- build/torch212-cxx11-cu132-x86_64-linux/__init__.py +105 -0
- build/torch212-cxx11-cu132-x86_64-linux/_ops.py +9 -0
- build/torch212-cxx11-cu132-x86_64-linux/_speculative_draft_primitives_cuda_6ee7cab.abi3.so +3 -0
- build/torch212-cxx11-cu132-x86_64-linux/metadata.json +22 -0
- build/torch212-cxx11-cu132-x86_64-linux/speculative_draft_primitives/__init__.py +26 -0
.gitattributes
CHANGED
|
@@ -1,35 +1,3 @@
|
|
| 1 |
-
*.
|
| 2 |
-
*.
|
| 3 |
-
*.
|
| 4 |
-
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
-
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
-
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
-
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
-
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
-
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
-
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
-
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
-
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
-
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
-
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
-
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
-
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
-
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
-
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
-
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
-
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
-
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
-
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
-
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
-
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
-
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
-
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
-
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
-
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
-
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
-
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
-
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
-
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
-
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
-
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
-
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
| 1 |
+
*.so filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.pyd filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.dylib filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
# flashrt/speculative-draft-primitives
|
| 2 |
-
|
| 3 |
-
This repository is a compatibility mirror for older `kernels` clients
|
| 4 |
-
that resolve repositories through the default Hugging Face model repo API.
|
| 5 |
-
|
| 6 |
-
Canonical Kernel Hub repo: https://huggingface.co/kernels/flashrt/speculative-draft-primitives
|
| 7 |
-
|
| 8 |
-
Do not edit this mirror by hand. It is generated from the Kernel Hub
|
| 9 |
-
`vN` branches and contains the same `build/**` artifacts.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
benchmarks/benchmark.py
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Benchmark speculative-draft-primitives."""
|
| 3 |
+
|
| 4 |
+
from __future__ import annotations
|
| 5 |
+
|
| 6 |
+
import argparse
|
| 7 |
+
import time
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
import sys
|
| 10 |
+
|
| 11 |
+
import torch
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[2]
|
| 14 |
+
sys.path.insert(0, str(ROOT / "speculative-draft-primitives" / "tests"))
|
| 15 |
+
from test_speculative_draft_primitives import load_installed_ops, load_source_ops # noqa: E402
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def time_us(fn, warmup: int, iters: int) -> float:
|
| 19 |
+
for _ in range(warmup):
|
| 20 |
+
fn()
|
| 21 |
+
torch.cuda.synchronize()
|
| 22 |
+
start = time.perf_counter()
|
| 23 |
+
for _ in range(iters):
|
| 24 |
+
fn()
|
| 25 |
+
torch.cuda.synchronize()
|
| 26 |
+
return (time.perf_counter() - start) * 1e6 / iters
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def main() -> int:
|
| 30 |
+
parser = argparse.ArgumentParser()
|
| 31 |
+
parser.add_argument("--backend", choices=["source", "installed"], default="source")
|
| 32 |
+
parser.add_argument("--artifact", default=None)
|
| 33 |
+
parser.add_argument("--mode", choices=["headline", "full"], default="headline")
|
| 34 |
+
parser.add_argument("--warmup", type=int, default=50)
|
| 35 |
+
parser.add_argument("--iters", type=int, default=200)
|
| 36 |
+
args = parser.parse_args()
|
| 37 |
+
|
| 38 |
+
ops = load_source_ops() if args.backend == "source" else load_installed_ops(args.artifact)
|
| 39 |
+
shapes = [(16, 32000), (16, 248320)] if args.mode == "headline" else [
|
| 40 |
+
(1, 1024),
|
| 41 |
+
(4, 4096),
|
| 42 |
+
(16, 32000),
|
| 43 |
+
(16, 248320),
|
| 44 |
+
]
|
| 45 |
+
print("rows,vocab,op,flashrt_us,torch_us,speedup,notes")
|
| 46 |
+
for rows, vocab in shapes:
|
| 47 |
+
logits = torch.randn((rows, vocab), device="cuda", dtype=torch.float32).to(torch.bfloat16)
|
| 48 |
+
drafts = torch.argmax(logits.float(), dim=1)[: min(rows, 15)].contiguous()
|
| 49 |
+
argmax_out = torch.empty((rows,), device=logits.device, dtype=torch.int64)
|
| 50 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 51 |
+
parts = 32 if vocab >= 131072 else (16 if vocab >= 65536 else (1 if vocab <= 4096 else 8))
|
| 52 |
+
partial_vals = torch.empty((rows, parts), device=logits.device, dtype=torch.float32)
|
| 53 |
+
partial_idx = torch.empty((rows, parts), device=logits.device, dtype=torch.int32)
|
| 54 |
+
|
| 55 |
+
if hasattr(ops, "ops"):
|
| 56 |
+
raw = ops.ops
|
| 57 |
+
|
| 58 |
+
def flash_argmax():
|
| 59 |
+
raw.argmax_bf16(logits, argmax_out)
|
| 60 |
+
|
| 61 |
+
def flash_accept_partitioned():
|
| 62 |
+
raw.accept_partitioned_bf16(
|
| 63 |
+
logits, drafts, argmax_out, accept_n, partial_vals, partial_idx, min(rows, 15), parts
|
| 64 |
+
)
|
| 65 |
+
else:
|
| 66 |
+
def flash_argmax():
|
| 67 |
+
ops.argmax_bf16(logits, out=argmax_out)
|
| 68 |
+
|
| 69 |
+
def flash_accept_partitioned():
|
| 70 |
+
ops.accept_partitioned_bf16(
|
| 71 |
+
logits,
|
| 72 |
+
drafts,
|
| 73 |
+
min(rows, 15),
|
| 74 |
+
parts,
|
| 75 |
+
argmax_out=argmax_out,
|
| 76 |
+
accept_n=accept_n,
|
| 77 |
+
partial_vals=partial_vals,
|
| 78 |
+
partial_idx=partial_idx,
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
flash_us = time_us(flash_argmax, args.warmup, args.iters)
|
| 82 |
+
torch_us = time_us(lambda: torch.argmax(logits.float(), dim=1), args.warmup, args.iters)
|
| 83 |
+
print(f"{rows},{vocab},argmax_bf16,{flash_us:.3f},{torch_us:.3f},{torch_us / flash_us:.2f},static-output")
|
| 84 |
+
flash_us = time_us(flash_accept_partitioned, args.warmup, args.iters)
|
| 85 |
+
print(f"{rows},{vocab},accept_partitioned_bf16,{flash_us:.3f},n/a,n/a,static-workspace parts={parts}")
|
| 86 |
+
return 0
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
if __name__ == "__main__":
|
| 90 |
+
raise SystemExit(main())
|
build/torch211-cxx11-cu128-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT speculative decoding helper kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.library.register_fake(add_op_namespace_prefix("argmax_bf16"))
|
| 13 |
+
def _argmax_bf16_fake(logits: torch.Tensor, argmax_out: torch.Tensor) -> None:
|
| 14 |
+
if logits.dim() != 2 or argmax_out.shape != (logits.shape[0],):
|
| 15 |
+
raise RuntimeError("argmax_bf16 expects logits (rows,vocab), argmax_out (rows,)")
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@torch.library.register_fake(add_op_namespace_prefix("accept_greedy_bf16"))
|
| 20 |
+
def _accept_greedy_bf16_fake(
|
| 21 |
+
logits: torch.Tensor,
|
| 22 |
+
drafts: torch.Tensor,
|
| 23 |
+
argmax_out: torch.Tensor,
|
| 24 |
+
accept_n: torch.Tensor,
|
| 25 |
+
spec_k: int,
|
| 26 |
+
) -> None:
|
| 27 |
+
if logits.dim() != 2 or argmax_out.shape != (logits.shape[0],):
|
| 28 |
+
raise RuntimeError("accept_greedy_bf16 expects logits (rows,vocab), argmax_out (rows,)")
|
| 29 |
+
if drafts.dim() != 1 or drafts.numel() < spec_k or accept_n.numel() < 1:
|
| 30 |
+
raise RuntimeError("drafts/accept_n shape mismatch")
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@torch.library.register_fake(add_op_namespace_prefix("accept_partitioned_bf16"))
|
| 35 |
+
def _accept_partitioned_bf16_fake(
|
| 36 |
+
logits: torch.Tensor,
|
| 37 |
+
drafts: torch.Tensor,
|
| 38 |
+
argmax_out: torch.Tensor,
|
| 39 |
+
accept_n: torch.Tensor,
|
| 40 |
+
partial_vals: torch.Tensor,
|
| 41 |
+
partial_idx: torch.Tensor,
|
| 42 |
+
spec_k: int,
|
| 43 |
+
parts: int,
|
| 44 |
+
) -> None:
|
| 45 |
+
if partial_vals.shape != (logits.shape[0], parts) or partial_idx.shape != (logits.shape[0], parts):
|
| 46 |
+
raise RuntimeError("partial buffers must have shape (rows, parts)")
|
| 47 |
+
return _accept_greedy_bf16_fake(logits, drafts, argmax_out, accept_n, spec_k)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def argmax_bf16(logits: torch.Tensor, *, out: Optional[torch.Tensor] = None) -> torch.Tensor:
|
| 51 |
+
if out is None:
|
| 52 |
+
out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 53 |
+
ops.argmax_bf16(logits, out)
|
| 54 |
+
return out
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def accept_greedy_bf16(
|
| 58 |
+
logits: torch.Tensor,
|
| 59 |
+
drafts: torch.Tensor,
|
| 60 |
+
spec_k: int,
|
| 61 |
+
*,
|
| 62 |
+
argmax_out: Optional[torch.Tensor] = None,
|
| 63 |
+
accept_n: Optional[torch.Tensor] = None,
|
| 64 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 65 |
+
if argmax_out is None:
|
| 66 |
+
argmax_out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 67 |
+
if accept_n is None:
|
| 68 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 69 |
+
ops.accept_greedy_bf16(logits, drafts, argmax_out, accept_n, int(spec_k))
|
| 70 |
+
return argmax_out, accept_n
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def accept_partitioned_bf16(
|
| 74 |
+
logits: torch.Tensor,
|
| 75 |
+
drafts: torch.Tensor,
|
| 76 |
+
spec_k: int,
|
| 77 |
+
parts: Optional[int] = None,
|
| 78 |
+
*,
|
| 79 |
+
argmax_out: Optional[torch.Tensor] = None,
|
| 80 |
+
accept_n: Optional[torch.Tensor] = None,
|
| 81 |
+
partial_vals: Optional[torch.Tensor] = None,
|
| 82 |
+
partial_idx: Optional[torch.Tensor] = None,
|
| 83 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 84 |
+
if parts is None:
|
| 85 |
+
vocab = int(logits.shape[1])
|
| 86 |
+
parts = 32 if vocab >= 131072 else (16 if vocab >= 65536 else 8)
|
| 87 |
+
if argmax_out is None:
|
| 88 |
+
argmax_out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 89 |
+
if accept_n is None:
|
| 90 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 91 |
+
if partial_vals is None:
|
| 92 |
+
partial_vals = torch.empty((logits.shape[0], parts), device=logits.device, dtype=torch.float32)
|
| 93 |
+
if partial_idx is None:
|
| 94 |
+
partial_idx = torch.empty((logits.shape[0], parts), device=logits.device, dtype=torch.int32)
|
| 95 |
+
ops.accept_partitioned_bf16(
|
| 96 |
+
logits, drafts, argmax_out, accept_n, partial_vals, partial_idx, int(spec_k), int(parts)
|
| 97 |
+
)
|
| 98 |
+
return argmax_out, accept_n
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
__all__ = [
|
| 102 |
+
"argmax_bf16",
|
| 103 |
+
"accept_greedy_bf16",
|
| 104 |
+
"accept_partitioned_bf16",
|
| 105 |
+
]
|
build/torch211-cxx11-cu128-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _speculative_draft_primitives_cuda_6ee7cab
|
| 3 |
+
ops = torch.ops._speculative_draft_primitives_cuda_6ee7cab
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_speculative_draft_primitives_cuda_6ee7cab::{op_name}"
|
build/torch211-cxx11-cu128-x86_64-linux/_speculative_draft_primitives_cuda_6ee7cab.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ef41b892ddb605ff2426c151e9f4be10dfc3920ee5f5dcf8fb81c0f645e5e3c6
|
| 3 |
+
size 363624
|
build/torch211-cxx11-cu128-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "speculative-draft-primitives",
|
| 3 |
+
"id": "_speculative_draft_primitives_cuda_6ee7cab",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"10.1",
|
| 12 |
+
"12.0+PTX",
|
| 13 |
+
"7.0",
|
| 14 |
+
"7.2",
|
| 15 |
+
"7.5",
|
| 16 |
+
"8.0",
|
| 17 |
+
"8.6",
|
| 18 |
+
"8.7",
|
| 19 |
+
"8.9",
|
| 20 |
+
"9.0"
|
| 21 |
+
]
|
| 22 |
+
}
|
| 23 |
+
}
|
build/torch211-cxx11-cu128-x86_64-linux/speculative_draft_primitives/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch211-cxx11-cu130-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT speculative decoding helper kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.library.register_fake(add_op_namespace_prefix("argmax_bf16"))
|
| 13 |
+
def _argmax_bf16_fake(logits: torch.Tensor, argmax_out: torch.Tensor) -> None:
|
| 14 |
+
if logits.dim() != 2 or argmax_out.shape != (logits.shape[0],):
|
| 15 |
+
raise RuntimeError("argmax_bf16 expects logits (rows,vocab), argmax_out (rows,)")
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@torch.library.register_fake(add_op_namespace_prefix("accept_greedy_bf16"))
|
| 20 |
+
def _accept_greedy_bf16_fake(
|
| 21 |
+
logits: torch.Tensor,
|
| 22 |
+
drafts: torch.Tensor,
|
| 23 |
+
argmax_out: torch.Tensor,
|
| 24 |
+
accept_n: torch.Tensor,
|
| 25 |
+
spec_k: int,
|
| 26 |
+
) -> None:
|
| 27 |
+
if logits.dim() != 2 or argmax_out.shape != (logits.shape[0],):
|
| 28 |
+
raise RuntimeError("accept_greedy_bf16 expects logits (rows,vocab), argmax_out (rows,)")
|
| 29 |
+
if drafts.dim() != 1 or drafts.numel() < spec_k or accept_n.numel() < 1:
|
| 30 |
+
raise RuntimeError("drafts/accept_n shape mismatch")
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@torch.library.register_fake(add_op_namespace_prefix("accept_partitioned_bf16"))
|
| 35 |
+
def _accept_partitioned_bf16_fake(
|
| 36 |
+
logits: torch.Tensor,
|
| 37 |
+
drafts: torch.Tensor,
|
| 38 |
+
argmax_out: torch.Tensor,
|
| 39 |
+
accept_n: torch.Tensor,
|
| 40 |
+
partial_vals: torch.Tensor,
|
| 41 |
+
partial_idx: torch.Tensor,
|
| 42 |
+
spec_k: int,
|
| 43 |
+
parts: int,
|
| 44 |
+
) -> None:
|
| 45 |
+
if partial_vals.shape != (logits.shape[0], parts) or partial_idx.shape != (logits.shape[0], parts):
|
| 46 |
+
raise RuntimeError("partial buffers must have shape (rows, parts)")
|
| 47 |
+
return _accept_greedy_bf16_fake(logits, drafts, argmax_out, accept_n, spec_k)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def argmax_bf16(logits: torch.Tensor, *, out: Optional[torch.Tensor] = None) -> torch.Tensor:
|
| 51 |
+
if out is None:
|
| 52 |
+
out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 53 |
+
ops.argmax_bf16(logits, out)
|
| 54 |
+
return out
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def accept_greedy_bf16(
|
| 58 |
+
logits: torch.Tensor,
|
| 59 |
+
drafts: torch.Tensor,
|
| 60 |
+
spec_k: int,
|
| 61 |
+
*,
|
| 62 |
+
argmax_out: Optional[torch.Tensor] = None,
|
| 63 |
+
accept_n: Optional[torch.Tensor] = None,
|
| 64 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 65 |
+
if argmax_out is None:
|
| 66 |
+
argmax_out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 67 |
+
if accept_n is None:
|
| 68 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 69 |
+
ops.accept_greedy_bf16(logits, drafts, argmax_out, accept_n, int(spec_k))
|
| 70 |
+
return argmax_out, accept_n
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def accept_partitioned_bf16(
|
| 74 |
+
logits: torch.Tensor,
|
| 75 |
+
drafts: torch.Tensor,
|
| 76 |
+
spec_k: int,
|
| 77 |
+
parts: Optional[int] = None,
|
| 78 |
+
*,
|
| 79 |
+
argmax_out: Optional[torch.Tensor] = None,
|
| 80 |
+
accept_n: Optional[torch.Tensor] = None,
|
| 81 |
+
partial_vals: Optional[torch.Tensor] = None,
|
| 82 |
+
partial_idx: Optional[torch.Tensor] = None,
|
| 83 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 84 |
+
if parts is None:
|
| 85 |
+
vocab = int(logits.shape[1])
|
| 86 |
+
parts = 32 if vocab >= 131072 else (16 if vocab >= 65536 else 8)
|
| 87 |
+
if argmax_out is None:
|
| 88 |
+
argmax_out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 89 |
+
if accept_n is None:
|
| 90 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 91 |
+
if partial_vals is None:
|
| 92 |
+
partial_vals = torch.empty((logits.shape[0], parts), device=logits.device, dtype=torch.float32)
|
| 93 |
+
if partial_idx is None:
|
| 94 |
+
partial_idx = torch.empty((logits.shape[0], parts), device=logits.device, dtype=torch.int32)
|
| 95 |
+
ops.accept_partitioned_bf16(
|
| 96 |
+
logits, drafts, argmax_out, accept_n, partial_vals, partial_idx, int(spec_k), int(parts)
|
| 97 |
+
)
|
| 98 |
+
return argmax_out, accept_n
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
__all__ = [
|
| 102 |
+
"argmax_bf16",
|
| 103 |
+
"accept_greedy_bf16",
|
| 104 |
+
"accept_partitioned_bf16",
|
| 105 |
+
]
|
build/torch211-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _speculative_draft_primitives_cuda_6ee7cab
|
| 3 |
+
ops = torch.ops._speculative_draft_primitives_cuda_6ee7cab
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_speculative_draft_primitives_cuda_6ee7cab::{op_name}"
|
build/torch211-cxx11-cu130-x86_64-linux/_speculative_draft_primitives_cuda_6ee7cab.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:8ca8ee5ce266bbd1d0379c2db5284cfa62899f826f791efa6396bc1f23a79f47
|
| 3 |
+
size 363696
|
build/torch211-cxx11-cu130-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "speculative-draft-primitives",
|
| 3 |
+
"id": "_speculative_draft_primitives_cuda_6ee7cab",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"11.0",
|
| 12 |
+
"12.0",
|
| 13 |
+
"12.1+PTX",
|
| 14 |
+
"7.5",
|
| 15 |
+
"8.0",
|
| 16 |
+
"8.6",
|
| 17 |
+
"8.7",
|
| 18 |
+
"8.9",
|
| 19 |
+
"9.0"
|
| 20 |
+
]
|
| 21 |
+
}
|
| 22 |
+
}
|
build/torch211-cxx11-cu130-x86_64-linux/speculative_draft_primitives/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch212-cxx11-cu130-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT speculative decoding helper kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.library.register_fake(add_op_namespace_prefix("argmax_bf16"))
|
| 13 |
+
def _argmax_bf16_fake(logits: torch.Tensor, argmax_out: torch.Tensor) -> None:
|
| 14 |
+
if logits.dim() != 2 or argmax_out.shape != (logits.shape[0],):
|
| 15 |
+
raise RuntimeError("argmax_bf16 expects logits (rows,vocab), argmax_out (rows,)")
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@torch.library.register_fake(add_op_namespace_prefix("accept_greedy_bf16"))
|
| 20 |
+
def _accept_greedy_bf16_fake(
|
| 21 |
+
logits: torch.Tensor,
|
| 22 |
+
drafts: torch.Tensor,
|
| 23 |
+
argmax_out: torch.Tensor,
|
| 24 |
+
accept_n: torch.Tensor,
|
| 25 |
+
spec_k: int,
|
| 26 |
+
) -> None:
|
| 27 |
+
if logits.dim() != 2 or argmax_out.shape != (logits.shape[0],):
|
| 28 |
+
raise RuntimeError("accept_greedy_bf16 expects logits (rows,vocab), argmax_out (rows,)")
|
| 29 |
+
if drafts.dim() != 1 or drafts.numel() < spec_k or accept_n.numel() < 1:
|
| 30 |
+
raise RuntimeError("drafts/accept_n shape mismatch")
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@torch.library.register_fake(add_op_namespace_prefix("accept_partitioned_bf16"))
|
| 35 |
+
def _accept_partitioned_bf16_fake(
|
| 36 |
+
logits: torch.Tensor,
|
| 37 |
+
drafts: torch.Tensor,
|
| 38 |
+
argmax_out: torch.Tensor,
|
| 39 |
+
accept_n: torch.Tensor,
|
| 40 |
+
partial_vals: torch.Tensor,
|
| 41 |
+
partial_idx: torch.Tensor,
|
| 42 |
+
spec_k: int,
|
| 43 |
+
parts: int,
|
| 44 |
+
) -> None:
|
| 45 |
+
if partial_vals.shape != (logits.shape[0], parts) or partial_idx.shape != (logits.shape[0], parts):
|
| 46 |
+
raise RuntimeError("partial buffers must have shape (rows, parts)")
|
| 47 |
+
return _accept_greedy_bf16_fake(logits, drafts, argmax_out, accept_n, spec_k)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def argmax_bf16(logits: torch.Tensor, *, out: Optional[torch.Tensor] = None) -> torch.Tensor:
|
| 51 |
+
if out is None:
|
| 52 |
+
out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 53 |
+
ops.argmax_bf16(logits, out)
|
| 54 |
+
return out
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def accept_greedy_bf16(
|
| 58 |
+
logits: torch.Tensor,
|
| 59 |
+
drafts: torch.Tensor,
|
| 60 |
+
spec_k: int,
|
| 61 |
+
*,
|
| 62 |
+
argmax_out: Optional[torch.Tensor] = None,
|
| 63 |
+
accept_n: Optional[torch.Tensor] = None,
|
| 64 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 65 |
+
if argmax_out is None:
|
| 66 |
+
argmax_out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 67 |
+
if accept_n is None:
|
| 68 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 69 |
+
ops.accept_greedy_bf16(logits, drafts, argmax_out, accept_n, int(spec_k))
|
| 70 |
+
return argmax_out, accept_n
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def accept_partitioned_bf16(
|
| 74 |
+
logits: torch.Tensor,
|
| 75 |
+
drafts: torch.Tensor,
|
| 76 |
+
spec_k: int,
|
| 77 |
+
parts: Optional[int] = None,
|
| 78 |
+
*,
|
| 79 |
+
argmax_out: Optional[torch.Tensor] = None,
|
| 80 |
+
accept_n: Optional[torch.Tensor] = None,
|
| 81 |
+
partial_vals: Optional[torch.Tensor] = None,
|
| 82 |
+
partial_idx: Optional[torch.Tensor] = None,
|
| 83 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 84 |
+
if parts is None:
|
| 85 |
+
vocab = int(logits.shape[1])
|
| 86 |
+
parts = 32 if vocab >= 131072 else (16 if vocab >= 65536 else 8)
|
| 87 |
+
if argmax_out is None:
|
| 88 |
+
argmax_out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 89 |
+
if accept_n is None:
|
| 90 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 91 |
+
if partial_vals is None:
|
| 92 |
+
partial_vals = torch.empty((logits.shape[0], parts), device=logits.device, dtype=torch.float32)
|
| 93 |
+
if partial_idx is None:
|
| 94 |
+
partial_idx = torch.empty((logits.shape[0], parts), device=logits.device, dtype=torch.int32)
|
| 95 |
+
ops.accept_partitioned_bf16(
|
| 96 |
+
logits, drafts, argmax_out, accept_n, partial_vals, partial_idx, int(spec_k), int(parts)
|
| 97 |
+
)
|
| 98 |
+
return argmax_out, accept_n
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
__all__ = [
|
| 102 |
+
"argmax_bf16",
|
| 103 |
+
"accept_greedy_bf16",
|
| 104 |
+
"accept_partitioned_bf16",
|
| 105 |
+
]
|
build/torch212-cxx11-cu130-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _speculative_draft_primitives_cuda_6ee7cab
|
| 3 |
+
ops = torch.ops._speculative_draft_primitives_cuda_6ee7cab
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_speculative_draft_primitives_cuda_6ee7cab::{op_name}"
|
build/torch212-cxx11-cu130-x86_64-linux/_speculative_draft_primitives_cuda_6ee7cab.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:fdc21e0fc928ce3a30076bf9252b67e3e800eba58359ca67070b4d3954f742c1
|
| 3 |
+
size 373872
|
build/torch212-cxx11-cu130-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "speculative-draft-primitives",
|
| 3 |
+
"id": "_speculative_draft_primitives_cuda_6ee7cab",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"11.0",
|
| 12 |
+
"12.0",
|
| 13 |
+
"12.1+PTX",
|
| 14 |
+
"7.5",
|
| 15 |
+
"8.0",
|
| 16 |
+
"8.6",
|
| 17 |
+
"8.7",
|
| 18 |
+
"8.9",
|
| 19 |
+
"9.0"
|
| 20 |
+
]
|
| 21 |
+
}
|
| 22 |
+
}
|
build/torch212-cxx11-cu130-x86_64-linux/speculative_draft_primitives/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|
build/torch212-cxx11-cu132-x86_64-linux/__init__.py
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""FlashRT speculative decoding helper kernels."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from typing import Optional
|
| 6 |
+
|
| 7 |
+
import torch
|
| 8 |
+
|
| 9 |
+
from ._ops import add_op_namespace_prefix, ops
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
@torch.library.register_fake(add_op_namespace_prefix("argmax_bf16"))
|
| 13 |
+
def _argmax_bf16_fake(logits: torch.Tensor, argmax_out: torch.Tensor) -> None:
|
| 14 |
+
if logits.dim() != 2 or argmax_out.shape != (logits.shape[0],):
|
| 15 |
+
raise RuntimeError("argmax_bf16 expects logits (rows,vocab), argmax_out (rows,)")
|
| 16 |
+
return None
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@torch.library.register_fake(add_op_namespace_prefix("accept_greedy_bf16"))
|
| 20 |
+
def _accept_greedy_bf16_fake(
|
| 21 |
+
logits: torch.Tensor,
|
| 22 |
+
drafts: torch.Tensor,
|
| 23 |
+
argmax_out: torch.Tensor,
|
| 24 |
+
accept_n: torch.Tensor,
|
| 25 |
+
spec_k: int,
|
| 26 |
+
) -> None:
|
| 27 |
+
if logits.dim() != 2 or argmax_out.shape != (logits.shape[0],):
|
| 28 |
+
raise RuntimeError("accept_greedy_bf16 expects logits (rows,vocab), argmax_out (rows,)")
|
| 29 |
+
if drafts.dim() != 1 or drafts.numel() < spec_k or accept_n.numel() < 1:
|
| 30 |
+
raise RuntimeError("drafts/accept_n shape mismatch")
|
| 31 |
+
return None
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
@torch.library.register_fake(add_op_namespace_prefix("accept_partitioned_bf16"))
|
| 35 |
+
def _accept_partitioned_bf16_fake(
|
| 36 |
+
logits: torch.Tensor,
|
| 37 |
+
drafts: torch.Tensor,
|
| 38 |
+
argmax_out: torch.Tensor,
|
| 39 |
+
accept_n: torch.Tensor,
|
| 40 |
+
partial_vals: torch.Tensor,
|
| 41 |
+
partial_idx: torch.Tensor,
|
| 42 |
+
spec_k: int,
|
| 43 |
+
parts: int,
|
| 44 |
+
) -> None:
|
| 45 |
+
if partial_vals.shape != (logits.shape[0], parts) or partial_idx.shape != (logits.shape[0], parts):
|
| 46 |
+
raise RuntimeError("partial buffers must have shape (rows, parts)")
|
| 47 |
+
return _accept_greedy_bf16_fake(logits, drafts, argmax_out, accept_n, spec_k)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def argmax_bf16(logits: torch.Tensor, *, out: Optional[torch.Tensor] = None) -> torch.Tensor:
|
| 51 |
+
if out is None:
|
| 52 |
+
out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 53 |
+
ops.argmax_bf16(logits, out)
|
| 54 |
+
return out
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def accept_greedy_bf16(
|
| 58 |
+
logits: torch.Tensor,
|
| 59 |
+
drafts: torch.Tensor,
|
| 60 |
+
spec_k: int,
|
| 61 |
+
*,
|
| 62 |
+
argmax_out: Optional[torch.Tensor] = None,
|
| 63 |
+
accept_n: Optional[torch.Tensor] = None,
|
| 64 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 65 |
+
if argmax_out is None:
|
| 66 |
+
argmax_out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 67 |
+
if accept_n is None:
|
| 68 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 69 |
+
ops.accept_greedy_bf16(logits, drafts, argmax_out, accept_n, int(spec_k))
|
| 70 |
+
return argmax_out, accept_n
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
def accept_partitioned_bf16(
|
| 74 |
+
logits: torch.Tensor,
|
| 75 |
+
drafts: torch.Tensor,
|
| 76 |
+
spec_k: int,
|
| 77 |
+
parts: Optional[int] = None,
|
| 78 |
+
*,
|
| 79 |
+
argmax_out: Optional[torch.Tensor] = None,
|
| 80 |
+
accept_n: Optional[torch.Tensor] = None,
|
| 81 |
+
partial_vals: Optional[torch.Tensor] = None,
|
| 82 |
+
partial_idx: Optional[torch.Tensor] = None,
|
| 83 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 84 |
+
if parts is None:
|
| 85 |
+
vocab = int(logits.shape[1])
|
| 86 |
+
parts = 32 if vocab >= 131072 else (16 if vocab >= 65536 else 8)
|
| 87 |
+
if argmax_out is None:
|
| 88 |
+
argmax_out = torch.empty((logits.shape[0],), device=logits.device, dtype=torch.int64)
|
| 89 |
+
if accept_n is None:
|
| 90 |
+
accept_n = torch.empty((1,), device=logits.device, dtype=torch.int32)
|
| 91 |
+
if partial_vals is None:
|
| 92 |
+
partial_vals = torch.empty((logits.shape[0], parts), device=logits.device, dtype=torch.float32)
|
| 93 |
+
if partial_idx is None:
|
| 94 |
+
partial_idx = torch.empty((logits.shape[0], parts), device=logits.device, dtype=torch.int32)
|
| 95 |
+
ops.accept_partitioned_bf16(
|
| 96 |
+
logits, drafts, argmax_out, accept_n, partial_vals, partial_idx, int(spec_k), int(parts)
|
| 97 |
+
)
|
| 98 |
+
return argmax_out, accept_n
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
__all__ = [
|
| 102 |
+
"argmax_bf16",
|
| 103 |
+
"accept_greedy_bf16",
|
| 104 |
+
"accept_partitioned_bf16",
|
| 105 |
+
]
|
build/torch212-cxx11-cu132-x86_64-linux/_ops.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
from . import _speculative_draft_primitives_cuda_6ee7cab
|
| 3 |
+
ops = torch.ops._speculative_draft_primitives_cuda_6ee7cab
|
| 4 |
+
|
| 5 |
+
def add_op_namespace_prefix(op_name: str):
|
| 6 |
+
"""
|
| 7 |
+
Prefix op by namespace.
|
| 8 |
+
"""
|
| 9 |
+
return f"_speculative_draft_primitives_cuda_6ee7cab::{op_name}"
|
build/torch212-cxx11-cu132-x86_64-linux/_speculative_draft_primitives_cuda_6ee7cab.abi3.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f7489f89c33a75c9bff23975bf4583b30d641f6e0e7b2e0a4b84d843ef90bfb8
|
| 3 |
+
size 373872
|
build/torch212-cxx11-cu132-x86_64-linux/metadata.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "speculative-draft-primitives",
|
| 3 |
+
"id": "_speculative_draft_primitives_cuda_6ee7cab",
|
| 4 |
+
"version": 1,
|
| 5 |
+
"license": "Apache-2.0",
|
| 6 |
+
"python-depends": [],
|
| 7 |
+
"backend": {
|
| 8 |
+
"type": "cuda",
|
| 9 |
+
"archs": [
|
| 10 |
+
"10.0",
|
| 11 |
+
"11.0",
|
| 12 |
+
"12.0",
|
| 13 |
+
"12.1+PTX",
|
| 14 |
+
"7.5",
|
| 15 |
+
"8.0",
|
| 16 |
+
"8.6",
|
| 17 |
+
"8.7",
|
| 18 |
+
"8.9",
|
| 19 |
+
"9.0"
|
| 20 |
+
]
|
| 21 |
+
}
|
| 22 |
+
}
|
build/torch212-cxx11-cu132-x86_64-linux/speculative_draft_primitives/__init__.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import ctypes
|
| 2 |
+
import importlib.util
|
| 3 |
+
import sys
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
from types import ModuleType
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def _import_from_path(file_path: Path) -> ModuleType:
|
| 9 |
+
# We cannot use the module name as-is, after adding it to `sys.modules`,
|
| 10 |
+
# it would also be used for other imports. So, we make a module name that
|
| 11 |
+
# depends on the path for it to be unique using the hex-encoded hash of
|
| 12 |
+
# the path.
|
| 13 |
+
path_hash = "{:x}".format(ctypes.c_size_t(hash(file_path.absolute())).value)
|
| 14 |
+
module_name = path_hash
|
| 15 |
+
spec = importlib.util.spec_from_file_location(module_name, file_path)
|
| 16 |
+
if spec is None:
|
| 17 |
+
raise ImportError(f"Cannot load spec for {module_name} from {file_path}")
|
| 18 |
+
module = importlib.util.module_from_spec(spec)
|
| 19 |
+
if module is None:
|
| 20 |
+
raise ImportError(f"Cannot load module {module_name} from spec")
|
| 21 |
+
sys.modules[module_name] = module
|
| 22 |
+
spec.loader.exec_module(module) # type: ignore
|
| 23 |
+
return module
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
globals().update(vars(_import_from_path(Path(__file__).parent.parent / "__init__.py")))
|