EvanOLeary commited on
Commit
7bf8383
·
verified ·
1 Parent(s): e71a74f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +79 -0
README.md ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: poolside/Laguna-XS.2
4
+ pipeline_tag: text-generation
5
+ library_name: transformers
6
+ tags: [moe-to-dense, densification, laguna, cuda, kernels, sft, code]
7
+ language: [en]
8
+ ---
9
+
10
+ # Laguna-XS.2 → Dense (K=8) · **CUDA-SFT** (kernel generation)
11
+
12
+ A **~3.0 B dense** model that turns PyTorch modules into **CUDA kernels**. Lineage:
13
+ **[poolside/Laguna-XS.2](https://huggingface.co/poolside/Laguna-XS.2)** MoE → densify → DO-ACP warm-start →
14
+ [kernel-mixture reconstruction (V2)](https://huggingface.co/EvanOLeary/laguna-xs2-dense-k8-kernelmix)
15
+ → **SFT on `SakanaAI/AI-CUDA-Engineer-Archive`** (this model). Sibling:
16
+ [OpenCodeInstruct/Python flavour](https://huggingface.co/EvanOLeary/laguna-xs2-dense-k8-recon).
17
+
18
+ > SFT-stage checkpoint. Generates CUDA in chat format; **not yet RL-optimized for speedup** (that's the next RFT stage).
19
+
20
+ ## It works — sample output
21
+ **Prompt** (chat): "Convert this PyTorch module into an optimized CUDA kernel" + a ReLU `nn.Module` → **model returns a correct CUDA kernel:**
22
+ ```cpp
23
+ __global__ void relu_kernel(const float* __restrict__ input, float* __restrict__ output, const int64_t size) {
24
+ const int idx = blockIdx.x * blockDim.x + threadIdx.x;
25
+ if (idx < size) { float v = input[idx]; output[idx] = v > 0 ? v : 0; }
26
+ }
27
+ torch::Tensor forward(torch::Tensor input) {
28
+ auto output = torch::empty_like(input);
29
+ const int threads = 256, blocks = (input.numel()+threads-1)/threads;
30
+ relu_kernel<<<blocks, threads>>>(input.data_ptr<float>(), output.data_ptr<float>(), input.numel());
31
+ return output;
32
+ }
33
+ ```
34
+ (Correct `__global__`, bounds check, ReLU logic, torch-extension wrapper. Chat format restored vs the pretrained checkpoint.)
35
+
36
+ ## How to use
37
+ ```python
38
+ import torch
39
+ from transformers import AutoModelForCausalLM, AutoTokenizer
40
+ repo="EvanOLeary/laguna-xs2-dense-k8-cuda-sft"
41
+ tok=AutoTokenizer.from_pretrained(repo, trust_remote_code=True)
42
+ m=AutoModelForCausalLM.from_pretrained(repo, trust_remote_code=True, torch_dtype=torch.bfloat16, device_map="cuda")
43
+ SYS="You are an expert GPU kernel engineer. Convert PyTorch modules into correct, optimized CUDA kernels."
44
+ user="Convert this PyTorch module into an optimized CUDA kernel:\n\n```python\n<your nn.Module>\n```"
45
+ s=tok.apply_chat_template([{"role":"system","content":SYS},{"role":"user","content":user}], add_generation_prompt=True, tokenize=False)
46
+ ids=tok(s, add_special_tokens=False, return_tensors="pt").input_ids.to(m.device)
47
+ print(tok.decode(m.generate(ids, max_new_tokens=512, do_sample=True, temperature=0.7, top_k=20, pad_token_id=9)[0][ids.shape[-1]:], skip_special_tokens=True))
48
+ ```
49
+
50
+ ## Training recipe (SFT)
51
+ | | |
52
+ |---|---|
53
+ | Base | V2 kernel-mixture reconstruction checkpoint (this repo's parent) |
54
+ | Data | `SakanaAI/AI-CUDA-Engineer-Archive` (level_1+2, **correct kernels only**), PyTorch→CUDA, chat-formatted, **prompt masked** |
55
+ | Objective | causal-LM cross-entropy on the CUDA completion only |
56
+ | Trainable | `routed_dense` + `lm_head` + norms (1.19 B); attention frozen |
57
+ | Optimizer | AdamW 2e-... lr **1e-5**, grad-clip 1.0, grad-accum 8 (eff-batch 8), seq 2048 |
58
+ | Steps | 400 (~3,200 CUDA examples), ~21 min, 1× H100 (27 GB) |
59
+ | Result | **CE 0.68 → 0.32** |
60
+
61
+ ![SFT curve](https://huggingface.co/EvanOLeary/laguna-xs2-dense-k8-cuda-sft/resolve/main/sft_curve.png)
62
+
63
+ ## Training data
64
+ `SakanaAI/AI-CUDA-Engineer-Archive` — ~30k verified PyTorch→CUDA kernel pairs from Sakana's AI CUDA
65
+ Engineer (CC-BY-4.0). We filter to `Correct==True` and format as `system + user(PyTorch) → assistant(CUDA)`.
66
+
67
+ ## Intended use
68
+ Research: generate CUDA kernels from PyTorch modules; a base for **RFT** (RL on verified speedup). Not production — kernels are not yet correctness/perf-verified at generation time.
69
+
70
+ ## Next steps
71
+ 1. **RFT (GRPO/RLVR)** — sample K kernels/prompt, reward = **compile + correct + speedup** via
72
+ [`SakanaAI/robust-kbench`](https://github.com/SakanaAI/robust-kbench); optimize the real metric.
73
+ 2. **Benchmark** — **KernelBench** (`fast_0` correctness, `fast_1` correct-and-faster) vs teacher.
74
+ 3. **NVFP4 quantize → vLLM serve** as a `generate_kernel` tool.
75
+
76
+ ## Limitations
77
+ SFT only — emits plausible CUDA (simple ops correct) but **not guaranteed to compile/be fast**; RFT + KernelBench verification come next. Add `winglian/cuda-engineer-augment` reasoning data for CoT.
78
+
79
+ *Refs: RADLADS 2505.03005 · MoE→Dense 2605.28207 · Sakana AI CUDA Engineer / robust-kbench 2509.14279 · KernelBench.*