Text Generation
Transformers
Safetensors
English
Chinese
qwen3_moe
code-generation
npu
ascend
chain-of-thought
conversational
Instructions to use AscendKernelGen/KernelGen-LM-MoE-30B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use AscendKernelGen/KernelGen-LM-MoE-30B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="AscendKernelGen/KernelGen-LM-MoE-30B") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("AscendKernelGen/KernelGen-LM-MoE-30B") model = AutoModelForCausalLM.from_pretrained("AscendKernelGen/KernelGen-LM-MoE-30B") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use AscendKernelGen/KernelGen-LM-MoE-30B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "AscendKernelGen/KernelGen-LM-MoE-30B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "AscendKernelGen/KernelGen-LM-MoE-30B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/AscendKernelGen/KernelGen-LM-MoE-30B
- SGLang
How to use AscendKernelGen/KernelGen-LM-MoE-30B 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 "AscendKernelGen/KernelGen-LM-MoE-30B" \ --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": "AscendKernelGen/KernelGen-LM-MoE-30B", "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 "AscendKernelGen/KernelGen-LM-MoE-30B" \ --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": "AscendKernelGen/KernelGen-LM-MoE-30B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use AscendKernelGen/KernelGen-LM-MoE-30B with Docker Model Runner:
docker model run hf.co/AscendKernelGen/KernelGen-LM-MoE-30B
File size: 7,652 Bytes
73cbbc9 393189c 73cbbc9 393189c e32a16d 73cbbc9 2d517e0 73cbbc9 76caa57 73cbbc9 c5b8232 73cbbc9 be83788 73cbbc9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | ---
language:
- en
- zh
license: apache-2.0
library_name: transformers
pipeline_tag: text-generation
datasets:
- AscendKernelGen/Ascend-COT-v2-json
base_model:
- Qwen/Qwen3-Coder-30B-A3B-Instruct
tags:
- code-generation
- npu
- ascend
- chain-of-thought
---
# AscendKernelGen/KernelGen-LM-MoE-30B

[](https://arxiv.org/abs/2601.07160)
## Overview
**KernelGen-LM-MoE-30B** is a state-of-the-art domain-adaptive large language model designed for low-level NPU kernel generation, targeting Huawei Ascend hardware with the AscendC programming language.
Built upon the **Qwen3-Coder-30B-A3B-Instruct (Mixture-of-Experts, MoE) backbone**, the model is further specialized through domain-adaptive post-training on the Ascend-CoT dataset, followed by reinforcement learning with execution feedback.
---
## Links
- **Paper:** https://huggingface.co/papers/2601.07160
- **Code:** https://github.com/weich97/NPUKernelBench
- **Datasets:** https://huggingface.co/AscendKernelGen/datasets
---
## Introduction
Our framework, **AscendKernelGen (AKGen)**, systematically bridges the gap between general-purpose code generation and hardware-specific programming via a closed-loop pipeline of data construction, training, and evaluation.
### Ascend-CoT Dataset
A high-quality, domain-specific dataset enriched with **Chain-of-Thought (CoT)** reasoning. It integrates:
- Documentation-grounded reasoning
- Code-centric reasoning from real-world kernel implementations
- General structured reasoning chains
This enables the model to capture the intricate logic required for low-level NPU kernel development.
---
### Domain-Adaptive Post-Training
We introduce a two-stage optimization pipeline to obtain **KernelGen-LM**:
- **Supervised Fine-Tuning (SFT):**
Leveraging error-derived supervision to correct API misuse and numerical inaccuracies
- **Reinforcement Learning (DPO):**
Guided by execution-based correctness and performance feedback
This combination significantly enhances both syntactic validity and runtime reliability.
---
### Hardware-Grounded Evaluation
We validate performance using **NPUKernelBench**, a comprehensive benchmark evaluating:
- Compilation success
- Functional correctness
- Runtime performance (latency)
All evaluations are conducted on real Ascend hardware across varying task complexities.
---
### Performance Highlights
KernelGen-LM demonstrates substantial improvements on complex Level-2 kernel generation tasks, successfully solving problems where general-purpose LLMs (e.g., Qwen3, Llama3.1) completely fail.
---
## Representative Case Studies
### Example: Effect of Knowledge Injection
The following case study, which concerns the usage of the `Muls` instruction in AscendC, demonstrates the qualitative improvement brought by CoT-based domain knowledge injection in both professional knowledge comprehension and code generation capability.

**🤔 Original response (before training):**
The response exhibits substantial uncertainty, as indicated by expressions such as “possibly” and “assuming.” The model attempts to reason by analogy from general programming knowledge, yet lacks an accurate understanding of AscendC-specific APIs, the precise usage of the `Muls` instruction, and its architectural context within the Ascend processor. The provided code example (e.g., involving `hip/hip_runtime.h`) is incorrect and explicitly reveals the model’s lack of domain-specific knowledge, as evidenced by statements such as “insufficient documentation” and “cannot be implemented.”
**🎓 Improved response (after training):**
The response demonstrates clear expert-level reasoning.
* **🧠 Structured reasoning (`<think>`)**: The model first analyzes the `Muls` instruction in terms of its operational background (vector multiplication), key parameters (e.g., `src0`, `dst`), and essential data layout constraints (e.g., whether `src0` must be a scalar or allocated in a specific region).
* **✅ Accurate implementation**: It then provides correct and concrete implementation steps, including initialization, local tensor memory management through `InQueue` and `OutQueue`, data movement (`CopyIn`), and the core computation invocation (`ScalarValue`).
* **⌨️ Code correctness**: The final generated code example (`aicore__void Compute()`) correctly employs the AscendC API and demonstrates an accurate understanding of both data queuing and vector instructions.
### Example: Comparison of Generated Operators
The following example, which concerns the implementation of a `Swish` operator in AscendC, illustrates the qualitative improvement brought by CoT-based domain knowledge injection in handling complex operator implementation and tiling strategy design.

**🤔 Original response (before training):**
The response exhibits substantial uncertainty in the critical tiling strategy, with phrases such as “possibly,” “obviously not feasible,” and “assuming.” Although the model attempts a simple arithmetic division (`1024/48 = 21.33`), it fails to understand Ascend core scheduling mechanisms and cannot handle non-divisible remainders appropriately. Its implementation of the `Swish` operator itself is also confused, with an inaccurate composition of operations such as `Negate`, `Reciprocal`, and `Multiply`, and an imprecise understanding of the required APIs. The response ultimately concludes that compilation would fail.
**🎓 Improved response (after training):**
The response demonstrates clear expert-level reasoning.
* **🧠 Structured reasoning (`<think>`)**: The model first accurately analyzes the mathematical formulation of the `Swish` operator, namely $y = x \times \mathrm{sigmoid}(x)$, together with the input specification. More importantly, it designs a robust tiling strategy by correctly identifying the total workload (`1024`) and the number of cores (`48`), and by formulating an uneven remainder-aware workload distribution scheme (the first 47 cores process 21 elements each, while the last core processes 37 elements).
* **✅ Accurate implementation**: The model then correctly realizes this tiling strategy in the `Init()` function by computing `blockLength` and `remainder`. In the `Compute()` function, it provides a correct and concrete operator implementation pipeline, combining AscendC instructions such as `Muls`, `Exp`, `Adds`, and `Div` to construct the sigmoid function step by step and ultimately complete the `Swish` computation.
* **⌨️ Code correctness**: The final generated code examples (`aicore__void Init()` and `aicore__void Compute()`) correctly employ the AscendC API, demonstrating not only an accurate understanding of the operator’s mathematical logic, but also a deep mastery of multi-core parallelization and tiling strategies.
## Citation
```bibtex
@article{cao2026ascendkernelgen,
title={AscendKernelGen: A Systematic Study of LLM-Based Kernel Generation for Neural Processing Units},
author={Xinzi Cao and Jianyang Zhai and Pengfei Li and Zhiheng Hu and Cen Yan and Bingxu Mu and Guanghuan Fang and Bin She and Jiayu Li and Yihan Su and Dongyang Tao and Xiansong Huang and Fan Xu and Feidiao Yang and Yao Lu and Chang-Dong Wang and Yutong Lu and Weicheng Xue and Bin Zhou and Yonghong Tian},
journal={arXiv preprint arXiv:2601.07160},
year={2026},
url={https://arxiv.org/abs/2601.07160}
} |