autokernel icon indicating copy to clipboard operation
autokernel copied to clipboard

module 'triton.language.math' has no attribute 'tanh'

Open NoahBPeterson opened this issue 3 months ago • 0 comments

https://github.com/RightNow-AI/autokernel/blob/78435821cc3d5756ba6ee1785c397f6d8fa8c90d/kernels/fused_mlp.py#L92

Here's a minimal reproduction of this bug, using fused_mlp.py as an example:

import triton
import triton.language as tl
from triton.backends.compiler import GPUTarget
from triton.compiler import ASTSource


@triton.jit
def gelu_kernel(x_ptr, out_ptr, N, BLOCK: tl.constexpr):
    offs = tl.program_id(0) * BLOCK + tl.arange(0, BLOCK)
    mask = offs < N
    x = tl.load(x_ptr + offs, mask=mask)
    y = 0.5 * x * (1.0 + tl.math.tanh(0.7978845608 * (x + 0.044715 * x * x * x)))
    tl.store(out_ptr + offs, y, mask=mask)


src = ASTSource(
    fn=gelu_kernel,
    signature={"x_ptr": "*fp32", "out_ptr": "*fp32", "N": "i32", "BLOCK": "constexpr"},
    constexprs={"BLOCK": 256},
)
triton.compile(src, target=GPUTarget("cuda", 89, 32))
Traceback (most recent call last):
  File "/workspace/repro_tanh.py", line 27, in <module>
    triton.compile(src, target=GPUTarget("cuda", 89, 32))
  File ".../triton/compiler/compiler.py", line 307, in compile
    module = src.make_ir(target, options, codegen_fns, module_map, context)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../triton/compiler/compiler.py", line 80, in make_ir
    return ast_to_ttir(self.fn, self, context=context, options=options, codegen_fns=codegen_fns,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
triton.compiler.errors.CompilationError: at 5:25:
def gelu_kernel(x_ptr, out_ptr, N, BLOCK: tl.constexpr):
    offs = tl.program_id(0) * BLOCK + tl.arange(0, BLOCK)
    mask = offs < N
    x = tl.load(x_ptr + offs, mask=mask)
    y = 0.5 * x * (1.0 + tl.math.tanh(0.7978845608 * (x + 0.044715 * x * x * x)))
                         ^
AttributeError("module 'triton.language.math' has no attribute 'tanh'")

NoahBPeterson avatar Aug 16 '26 14:08 NoahBPeterson