已关闭
[Bug-Report|缺陷反馈]: 用例异常值执行中有拦截但最后出现coredump #1095
丛吉钰创建于  2月24日关闭于  2月24日
丛吉钰
丛吉钰成员
2月24日 创建

Thanks for sending an issue! Please fill in the following template to help quickly solve your problem.

Describe the current behavior / 问题描述 (Mandatory / 必填)

torch.nn.TransformerDecoderLayer.forward接口用例异常值执行中有拦截但最后出现coredump,aclnnBatchMatMul报错

Environment / 环境信息 (Mandatory / 必填)

使用2/13日newest,python3.10执行,torch使用的是2.7.1

Steps to reproduce the issue / 重现步骤 (Mandatory / 必填)

import torch
import torch_npu
from torch_npu.contrib import transfer_to_npu
import os
import numpy as np
from util_test import data_compare_v2, fixed_random
fixed_random(2025, "torch")
src = torch.randn(15, 24, 256, dtype=torch.float32, requires_grad=True)
memory = torch.randn(10, 24, 256, dtype=torch.float32, requires_grad=True)
tgt_mask = torch.randn(15, 15) > 0
memory_mask = torch.randn(15, 10) > 0
tgt_key_padding_mask = torch.randn(24, 15) > 0
memory_key_padding_mask = torch.randn(24, 10) > 0
decoder_layer = torch.nn.TransformerDecoderLayer(d_model=256, nhead=4, dim_feedforward=1024, dropout=0.1, activation="gelu")
if torch.cuda.is_available():
src_gpu = src.cuda()
memory_gpu = memory.cuda()
tgt_mask_gpu = tgt_mask.cuda()
memory_mask_gpu = memory_mask.cuda()
tgt_key_padding_mask_gpu = tgt_key_padding_mask.cuda()
memory_key_padding_mask_gpu = memory_key_padding_mask.cuda()
decoder_layer_gpu = decoder_layer.cuda()
########gpu_start########
profile_path = "profile_path/" + os.path.basename(file)
experimental_config = torch_npu.profiler.ExperimentalConfig(profiler_level=torch_npu.profiler.ProfilerLevel.Level1,aic_metrics=torch_npu.profiler.AiCMetrics.PipeUtilization,l2_cache=True)
torch.npu.synchronize()
with torch_npu.profiler.profile(activities=[torch_npu.profiler.ProfilerActivity.CPU, torch_npu.profiler.ProfilerActivity.NPU],with_stack=True,record_shapes=True,profile_memory=True, schedule=torch_npu.profiler.schedule(wait=0, warmup=0, active=1, repeat=1, skip_first=0),on_trace_ready=torch_npu.profiler.tensorboard_trace_handler(profile_path),experimental_config=experimental_config) as prof:
output_data = decoder_layer_gpu(src_gpu, memory_gpu, tgt_mask=tgt_mask_gpu, memory_mask=memory_mask_gpu, tgt_key_padding_mask=tgt_key_padding_mask_gpu, memory_key_padding_mask=memory_key_padding_mask_gpu)
loss = output_data.sum()
loss.backward()
########gpu_end########
src_cpu = src.detach().cpu().requires_grad
(True)
memory_cpu = memory.detach().cpu().requires_grad_(True)
tgt_mask_cpu = tgt_mask.detach().cpu()
memory_mask_cpu = memory_mask.detach().cpu()
tgt_key_padding_mask_cpu = tgt_key_padding_mask.detach().cpu()
memory_key_padding_mask_cpu = memory_key_padding_mask.detach().cpu()
decoder_layer_cpu = torch.nn.TransformerDecoderLayer(d_model=256, nhead=4, dim_feedforward=1024, dropout=0.1, activation="gelu")
decoder_layer_cpu.load_state_dict(decoder_layer.state_dict())
else:
src_cpu = src
memory_cpu = memory
tgt_mask_cpu = tgt_mask
memory_mask_cpu = memory_mask
tgt_key_padding_mask_cpu = tgt_key_padding_mask
memory_key_padding_mask_cpu = memory_key_padding_mask
decoder_layer_cpu = decoder_layer
output_data_cpu = decoder_layer_cpu(src_cpu, memory_cpu, tgt_mask=tgt_mask_cpu, memory_mask=memory_mask_cpu, tgt_key_padding_mask=tgt_key_padding_mask_cpu, memory_key_padding_mask=memory_key_padding_mask_cpu)
loss_cpu = output_data_cpu.sum()
loss_cpu.backward()
data_compare_v2(output_data, output_data_cpu, 0.001, 0.001)
print("case execute end")

Describe the expected behavior / 预期结果 (Mandatory / 必填)

当输入的值存在异常时,应立刻报错并退出。

[ERROR] OP(3045388,python3):2026-02-13-16:36:50.001.184 [op_executor.cpp:989][NNOP][CreateView][3046002] errno[561000] OpName:[aclnnBatchMatMul_195] The tensor's offset is invalid with the specified storageShape

Special notes for this issue/备注 (Optional / 选填)

likedislike
丛吉钰丛吉钰成员
2月24日 将 cong-jiyu 设为负责人
丛吉钰丛吉钰成员
2月24日 关联了pull request:fix bmm trans nd nullptr
CANN-robotCANN-robot成员
2月24日 关闭了 issue
CANN-robotCANN-robot成员
3月20日 添加了label:resolved