Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/mindspore-ai/akg --skill pypto-case-reduction-sum명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SOC 직업 분류 기준
SKILL.md 표시 중
| name | pypto-case-reduction-sum |
| description | 单轴归约示例:3D Sum reduction — 保持原始维度,最简 kernel |
| category | example |
| version | 1.0.0 |
| metadata | {"backend":"ascend","dsl":"pypto","operator_patterns":"reduction"} |
最简单的模式——不需要 loop/view/assemble,kernel 只有 3 行。
def create_sum_reduction_kernel(in_shape, out_shape):
@pypto.frontend.jit(runtime_options=..., debug_options=...)
def kernel(
x: pypto.Tensor(in_shape, pypto.DT_FP32),
) -> pypto.Tensor(out_shape, pypto.DT_FP32):
output = pypto.tensor(list(out_shape), pypto.DT_FP32)
pypto.set_vec_tile_shapes(1, 16, 256)
output[:] = pypto.sum(x, dim=1, keepdim=True)
return output
return kernel
forward:保持原始维度,不降维。
def forward(self, x):
assert x.dim() == 3
assert tuple(x.shape) == (16, 256, 256)
assert self.dim == 1
x = x.contiguous()
batch, _, dim2 = x.shape
return create_sum_reduction_kernel(
tuple(x.shape), (batch, 1, dim2)
)(x)
set_tile + sum + return,无需 loop/view/assemblepypto.amin / pypto.amax 同理,只换 APIsum * (1.0 / size)(无内建 mean API)(16, 256, 256), dim=1 的 3D 单轴归约,默认首选从 (1, 16, 256) 起步,再按 32/64 对照实测。(1, 16, 256) 作为默认实现。(1, 32, 256) 与 (1, 64, 256) 不作为默认模板,仅作为对照候选。get_init_inputs() 返回值是本次固定参数(例如 dim=1)。Example, change to desired dimension 是题库说明,不是当前实现目标。ModelNew.__init__(dim) 签名;forward 中 assert self.dim == <固定值>;dim=<固定值>,不要写 if dim == ... 分支;create_*_kernel 不再接收 dim 运行时参数。反例(不要这样写):
def create_xxx_kernel(in_shape, out_shape, dim):
...
output[:] = pypto.amin(x, dim=dim, keepdim=True)
正例(固定 dim 写死):
FIXED_DIM = 1
def create_xxx_kernel(in_shape, out_shape):
...
output[:] = pypto.amin(x, dim=FIXED_DIM, keepdim=True)