Pypto case elemwise gelu

From mindspore-ai/akg · View interactive version

Pypto case elemwise gelu is an AI agent skill from the GitHub repository mindspore-ai/akg. 模式 A 示例:1D elementwise — GELU 激活,展示展平、无 tanh 时的手写公式、运算符使用

How to use this skill

Skill file

模式 A:1D Elementwise — GELU

def create_gelu_kernel(flat_size):
    @pypto.frontend.jit(runtime_options=..., debug_options=...)
    def gelu_kernel(
        x: pypto.Tensor((flat_size,), pypto.DT_FP32),
    ) -> pypto.Tensor((flat_size,), pypto.DT_FP32):
        output = pypto.tensor([flat_size], pypto.DT_FP32)
        pypto.set_vec_tile_shapes(8192)
        x_cubed = x * x * x
        inner = x + x_cubed * 0.044715
        tanh_arg = inner * 0.7978845608028654
        exp_pos = pypto.exp(tanh_arg * 2.0)
        tanh_val = (exp_pos - 1.0) / (exp_pos + 1.0)
        output[:] = x * 0.5 * (1.0 + tanh_val)
        return output
    return gelu_kernel

forward:reshape(-1) → kernel → reshape(x.shape)

模式要点

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.