liangsu9988 commited on
Commit
ef7c44b
·
verified ·
1 Parent(s): edf46cb

Add torch211-cxx11-cu130-aarch64-linux aarch64 artifact

Browse files
build/torch211-cxx11-cu130-aarch64-linux/__init__.py CHANGED
@@ -206,6 +206,57 @@ def _qkv_split_rope_kvcache_bf16_fake(
206
  return None
207
 
208
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  @torch.library.register_fake(add_op_namespace_prefix("qkv_split_bf16"))
210
  def _qkv_split_bf16_fake(
211
  packed_qkv: torch.Tensor,
@@ -500,6 +551,83 @@ def qkv_split_rope_kvcache_bf16(
500
  return q_out, k_cache, v_cache
501
 
502
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
503
  def qkv_split_per_head_norm_rope_bf16(
504
  packed_qkv: torch.Tensor,
505
  q_norm_weight: torch.Tensor,
@@ -867,6 +995,8 @@ __all__ = [
867
  "qkv_split_bias_rope_fp16",
868
  "qkv_split_bf16",
869
  "qkv_split_rope_kvcache_bf16",
 
 
870
  "qkv_split_norm_rope_bf16",
871
  "qkv_split_bias_norm_rope_v_bf16",
872
  "qkv_split_bias_norm_rope_v_cat_bf16",
 
206
  return None
207
 
208
 
209
+ @torch.library.register_fake(add_op_namespace_prefix("qkv_split_rope_kvcache_fp16"))
210
+ def _qkv_split_rope_kvcache_fp16_fake(
211
+ packed_qkv: torch.Tensor,
212
+ rope: torch.Tensor,
213
+ q_heads: int,
214
+ kv_heads: int,
215
+ head_dim: int,
216
+ cache_offset: int,
217
+ device_position: torch.Tensor | None,
218
+ q_out: torch.Tensor,
219
+ k_cache: torch.Tensor,
220
+ v_cache: torch.Tensor,
221
+ ) -> None:
222
+ _check_packed_gqa_qkv(packed_qkv, q_heads, kv_heads, head_dim)
223
+ batch, seq_len, _ = packed_qkv.shape
224
+ if packed_qkv.dtype != torch.float16 or rope.dtype != torch.float16:
225
+ raise RuntimeError("packed_qkv and rope must have dtype torch.float16")
226
+ if rope.dim() != 2 or rope.shape[0] < seq_len or rope.shape[1] != head_dim:
227
+ raise RuntimeError("rope must have shape (>= seq_len, head_dim)")
228
+ if q_out.shape != (batch, seq_len, q_heads, head_dim):
229
+ raise RuntimeError("q_out has an invalid shape")
230
+ if k_cache.dim() != 4 or k_cache.shape[0] != batch or k_cache.shape[2:] != (kv_heads, head_dim):
231
+ raise RuntimeError("k_cache must have shape (batch, max_seq_len, kv_heads, head_dim)")
232
+ if v_cache.shape != k_cache.shape:
233
+ raise RuntimeError("v_cache must have the same shape as k_cache")
234
+ if cache_offset < 0:
235
+ raise RuntimeError("cache_offset must be non-negative")
236
+ if device_position is not None and (device_position.dtype != torch.int32 or device_position.numel() != 1):
237
+ raise RuntimeError("device_position must contain one int32 element")
238
+ return None
239
+
240
+
241
+ @torch.library.register_fake(add_op_namespace_prefix("qk_norm_rope_strided_bf16"))
242
+ def _qk_norm_rope_strided_bf16_fake(
243
+ q_in, k_in, q_weight, k_weight, cos, sin,
244
+ q_heads: int, k_heads: int, eps: float, q_out, k_out,
245
+ ) -> None:
246
+ rows = q_in.shape[0]
247
+ if q_in.dim() != 2 or k_in.dim() != 2 or k_in.shape[0] != rows:
248
+ raise RuntimeError("q_in and k_in must be rank-2 with the same row count")
249
+ if q_in.shape[1] < q_heads * 128 or k_in.shape[1] < k_heads * 128:
250
+ raise RuntimeError("input row widths must cover heads * 128")
251
+ if q_weight.shape != (128,) or k_weight.shape != (128,):
252
+ raise RuntimeError("Q/K weights must have shape (128,)")
253
+ if cos.shape != (rows, 128) or sin.shape != cos.shape:
254
+ raise RuntimeError("cos and sin must have shape (rows, 128)")
255
+ if q_out.shape != (rows, q_heads, 128) or k_out.shape != (rows, k_heads, 128):
256
+ raise RuntimeError("output shapes must be (rows, heads, 128)")
257
+ return None
258
+
259
+
260
  @torch.library.register_fake(add_op_namespace_prefix("qkv_split_bf16"))
261
  def _qkv_split_bf16_fake(
262
  packed_qkv: torch.Tensor,
 
551
  return q_out, k_cache, v_cache
552
 
553
 
554
+ def qkv_split_rope_kvcache_fp16(
555
+ packed_qkv: torch.Tensor,
556
+ rope: torch.Tensor,
557
+ q_heads: int,
558
+ kv_heads: int,
559
+ head_dim: int,
560
+ cache_offset: int = 0,
561
+ device_position: torch.Tensor | None = None,
562
+ q_out: torch.Tensor | None = None,
563
+ k_cache: torch.Tensor | None = None,
564
+ v_cache: torch.Tensor | None = None,
565
+ max_seq_len: int | None = None,
566
+ ) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
567
+ """Split FP16 GQA QKV, apply interleaved RoPE, and update K/V caches.
568
+
569
+ ``device_position`` is an optional CUDA int32 scalar used by CUDA Graph
570
+ decode loops. When provided, cache rows start at
571
+ ``cache_offset + device_position[0]`` without a host synchronization.
572
+ """
573
+ batch, seq_len, _ = packed_qkv.shape
574
+ if q_out is None:
575
+ q_out = torch.empty(
576
+ (batch, seq_len, q_heads, head_dim),
577
+ device=packed_qkv.device,
578
+ dtype=torch.float16,
579
+ )
580
+ if k_cache is None or v_cache is None:
581
+ if max_seq_len is None:
582
+ if device_position is not None:
583
+ raise ValueError("max_seq_len is required when device_position is used")
584
+ max_seq_len = cache_offset + seq_len
585
+ cache_shape = (batch, int(max_seq_len), kv_heads, head_dim)
586
+ if k_cache is None:
587
+ k_cache = torch.empty(cache_shape, device=packed_qkv.device, dtype=torch.float16)
588
+ if v_cache is None:
589
+ v_cache = torch.empty(cache_shape, device=packed_qkv.device, dtype=torch.float16)
590
+ ops.qkv_split_rope_kvcache_fp16(
591
+ packed_qkv,
592
+ rope,
593
+ int(q_heads),
594
+ int(kv_heads),
595
+ int(head_dim),
596
+ int(cache_offset),
597
+ device_position,
598
+ q_out,
599
+ k_cache,
600
+ v_cache,
601
+ )
602
+ return q_out, k_cache, v_cache
603
+
604
+
605
+ def qk_norm_rope_strided_bf16(
606
+ q_in: torch.Tensor,
607
+ k_in: torch.Tensor,
608
+ q_weight: torch.Tensor,
609
+ k_weight: torch.Tensor,
610
+ cos: torch.Tensor,
611
+ sin: torch.Tensor,
612
+ q_heads: int,
613
+ k_heads: int,
614
+ eps: float = 1e-6,
615
+ q_out: torch.Tensor | None = None,
616
+ k_out: torch.Tensor | None = None,
617
+ ) -> tuple[torch.Tensor, torch.Tensor]:
618
+ """Per-head RMSNorm and rotate-half RoPE from padded Q/K row strides."""
619
+ rows = q_in.shape[0]
620
+ if q_out is None:
621
+ q_out = torch.empty((rows, q_heads, 128), device=q_in.device, dtype=torch.bfloat16)
622
+ if k_out is None:
623
+ k_out = torch.empty((rows, k_heads, 128), device=k_in.device, dtype=torch.bfloat16)
624
+ ops.qk_norm_rope_strided_bf16(
625
+ q_in, k_in, q_weight, k_weight, cos, sin,
626
+ int(q_heads), int(k_heads), float(eps), q_out, k_out,
627
+ )
628
+ return q_out, k_out
629
+
630
+
631
  def qkv_split_per_head_norm_rope_bf16(
632
  packed_qkv: torch.Tensor,
633
  q_norm_weight: torch.Tensor,
 
995
  "qkv_split_bias_rope_fp16",
996
  "qkv_split_bf16",
997
  "qkv_split_rope_kvcache_bf16",
998
+ "qkv_split_rope_kvcache_fp16",
999
+ "qk_norm_rope_strided_bf16",
1000
  "qkv_split_norm_rope_bf16",
1001
  "qkv_split_bias_norm_rope_v_bf16",
1002
  "qkv_split_bias_norm_rope_v_cat_bf16",
build/torch211-cxx11-cu130-aarch64-linux/_ops.py CHANGED
@@ -1,6 +1,6 @@
1
  import torch
2
- from . import _flashrt_qkv_cache_rope_cuda_7781728
3
- ops = torch.ops._flashrt_qkv_cache_rope_cuda_7781728
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
- return f"_flashrt_qkv_cache_rope_cuda_7781728::{op_name}"
 
1
  import torch
2
+ from . import flashrt_qkv_cache_rope_test
3
+ ops = torch.ops.flashrt_qkv_cache_rope_test
4
 
5
  def add_op_namespace_prefix(op_name: str):
6
+ return f"flashrt_qkv_cache_rope_test::{op_name}"
build/torch211-cxx11-cu130-aarch64-linux/flashrt_qkv_cache_rope_test.abi3.so ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0511d29a589f1fb1380c7555f54b673d4e055350a98a6b6b3e6a24cc40d4046b
3
+ size 764184
build/torch211-cxx11-cu130-aarch64-linux/metadata.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "name": "flashrt-qkv-cache-rope",
3
- "id": "_flashrt_qkv_cache_rope_cuda_7781728",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
@@ -13,10 +13,20 @@
13
  "digest": {
14
  "algorithm": "sha256",
15
  "files": {
16
- "__init__.py": "A5t1ELQb0pbOoFMjZR7VzYvIds3qUO94UZ/4ZbqHd6U=",
17
- "_flashrt_qkv_cache_rope_cuda_7781728.abi3.so": "Lwrt2ZZRrbXY/3OleQGifvVdwC402AyVLXzfUhG1Qls=",
18
- "_ops.py": "IZnrJOS3RgtEaCdzR1d8T8OPo0IQT2EeJ3J00gc4lrw=",
19
  "flashrt_qkv_cache_rope/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
20
  }
 
 
 
 
 
 
 
 
 
 
21
  }
22
  }
 
1
  {
2
  "name": "flashrt-qkv-cache-rope",
3
+ "id": "flashrt_qkv_cache_rope_test",
4
  "version": 1,
5
  "license": "Apache-2.0",
6
  "python-depends": [],
 
13
  "digest": {
14
  "algorithm": "sha256",
15
  "files": {
16
+ "__init__.py": "Izk+vnt9b4h2bryy/G+JK29rnXtvBhAbTLxsiNQGCSk=",
17
+ "flashrt_qkv_cache_rope_test.abi3.so": "BRHSmlifH7E4DHVV9UtnPU4FU1CpimtrPmokzEDUBGs=",
18
+ "_ops.py": "ZSIUGrzgBBffx37jx/znR0nnvtuaR3+G3FSvPKa9UHQ=",
19
  "flashrt_qkv_cache_rope/__init__.py": "v6p5XMfQzddhi1fLSAw4HX9CyS0rQsidvu9VsT01xi4="
20
  }
21
+ },
22
+ "provenance": {
23
+ "kernel": {
24
+ "sha": "7db5ebe",
25
+ "dirty": false
26
+ },
27
+ "validation": {
28
+ "torch": "2.11.0+cu130",
29
+ "cuda": "13.0"
30
+ }
31
  }
32
  }