Text Generation
Transformers
Safetensors
Kernels
English
laguna_dense
moe-to-dense
densification
laguna
cuda
sft
code
conversational
custom_code
Instructions to use EvanOLeary/laguna-xs2-dense-k8-cuda-sft with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use EvanOLeary/laguna-xs2-dense-k8-cuda-sft with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="EvanOLeary/laguna-xs2-dense-k8-cuda-sft", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("EvanOLeary/laguna-xs2-dense-k8-cuda-sft", trust_remote_code=True, device_map="auto") - Kernels
How to use EvanOLeary/laguna-xs2-dense-k8-cuda-sft with Kernels:
# !pip install kernels from kernels import get_kernel # a version (or an explicit revision) is required; see the "Files and versions" tab for the available ones kernel = get_kernel("EvanOLeary/laguna-xs2-dense-k8-cuda-sft", version=1) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use EvanOLeary/laguna-xs2-dense-k8-cuda-sft with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "EvanOLeary/laguna-xs2-dense-k8-cuda-sft" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EvanOLeary/laguna-xs2-dense-k8-cuda-sft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/EvanOLeary/laguna-xs2-dense-k8-cuda-sft
- SGLang
How to use EvanOLeary/laguna-xs2-dense-k8-cuda-sft with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "EvanOLeary/laguna-xs2-dense-k8-cuda-sft" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EvanOLeary/laguna-xs2-dense-k8-cuda-sft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "EvanOLeary/laguna-xs2-dense-k8-cuda-sft" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EvanOLeary/laguna-xs2-dense-k8-cuda-sft", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use EvanOLeary/laguna-xs2-dense-k8-cuda-sft with Docker Model Runner:
docker model run hf.co/EvanOLeary/laguna-xs2-dense-k8-cuda-sft
Upload README.md with huggingface_hub
Browse files
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 |
+

|
| 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.*
|