# Triton Cuda Error Fix

> triton-cuda常见错误及修复方法，用于代码生成时避免同类问题

- Skill: `wenyi-li/triton-cuda-error-fix` (Agent Skill)
- Install (CLI): `npx skillmds@latest add wenyi-li/triton-cuda-error-fix`
- Raw SKILL.md: https://api.skillmd.com/api/skills/wenyi-li/triton-cuda-error-fix/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: AI & ML
- Author: wenyi-li (https://skillmd.com/u/wenyi-li)
- Updated: 2026-09-22
- Page: https://skillmd.com/skills/wenyi-li/triton-cuda-error-fix

---


### 数学函数调用错误

- **报错特征**: `AttributeError: module 'triton.language' has no attribute 'tanh'`
- **修复**:
  - Triton CUDA 后端的数学函数需通过 `tl.extra.cuda.libdevice` 模块调用
  - 避免直接使用 `tl.math.xxx` 或 `tl.xxx`

```python
# 错误：直接使用 tl.tanh
result = 0.5 * x * (1.0 + tl.tanh(inner))

# 正确：通过 libdevice 调用
result = 0.5 * x * (1.0 + tl.extra.cuda.libdevice.tanh(inner))
```
