Unrecognized attribute: axes for operator ReduceMean
Labels: module: onnx, triaged

### 🐛 Describe the bug

llama2_base_path = "./modules/Llama-2-13b-chat-hf"
onnx_file_path = "./onnx_model/llama/Llama-2-13b-chat-hf.onnx"

if not os.path.exists(os.path.dirname(onnx_file_path)):
    os.mkdir(os.path.dirname(onnx_file_path))

load_type = torch.float16

tokenizer = LlamaTokenizer.from_pretrained(llama2_base_path, trust_remote_code=True)
model = LlamaForCausalLM.from_pretrained(
    llama2_base_path,
    device_map=DEVICE,
    torch_dtype=load_type,
    trust_remote_code=True
).eval()

inputs = tokenizer("登鹳雀楼->王之涣\n夜雨寄北->", return_tensors="pt")

inputs.to(DEVICE)

torch.onnx.export(
    model,
    (inputs['input_ids'], inputs['attention_mask']),
    onnx_file_path,
    verbose=True,
    opset_version=19,
    export_params=False,
    do_constant_folding=False,
    input_names=["input_ids", "attention_mask"],
    output_names=["output"],
    dynamic_axes={
        'input_ids': {0: 'batch_size', 1: 'sequence_length'},
        'attention_mask': {0: 'batch_size', 1: 'sequence_length'},
        'output': {0: 'batch_size', 1: 'sequence_length'}
    }
)

print("export llama2 to onnx success")


Traceback (most recent call last):
  File "/root/anaconda3/envs/ry_pytorch_gpu/lib/python3.10/site-packages/torch/onnx/utils.py", line 1686, in _export
    _C._check_onnx_proto(proto)
RuntimeError: Unrecognized attribute: axes for operator ReduceMean

==> Context: Bad node spec for node. Name: /model/layers.0/input_layernorm/ReduceMean OpType: ReduceMean

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/data01/ry/pt2onnx/pt2onnx.py", line 137, in <module>
    convert_baichuan2_onnx()
  File "/data01/ry/pt2onnx/pt2onnx.py", line 60, in convert_baichuan2_onnx
    torch.onnx.export(
  File "/root/anaconda3/envs/ry_pytorch_gpu/lib/python3.10/site-packages/torch/onnx/utils.py", line 516, in export
    _export(
  File "/root/anaconda3/envs/ry_pytorch_gpu/lib/python3.10/site-packages/torch/onnx/utils.py", line 1688, in _export
    raise errors.CheckerError(e) from e
torch.onnx.errors.CheckerError: Unrecognized attribute: axes for operator ReduceMean

==> Context: Bad node spec for node. Name: /model/layers.0/input_layernorm/ReduceMean OpType: ReduceMean

### Versions

PyTorch version: 2.1.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: CentOS Linux 7 (Core) (x86_64)
GCC version: (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44)
Clang version: Could not collect
CMake version: version 3.27.5
Libc version: glibc-2.17

Python version: 3.10.13 (main, Sep 11 2023, 13:44:35) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-3.10.0-1160.90.1.el7.x86_64-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: 12.2.140
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA A800-SXM4-80GB
GPU 1: NVIDIA A800-SXM4-80GB
GPU 2: NVIDIA A800-SXM4-80GB
GPU 3: NVIDIA A800-SXM4-80GB
GPU 4: NVIDIA A800-SXM4-80GB
GPU 5: NVIDIA A800-SXM4-80GB
GPU 6: NVIDIA A800-SXM4-80GB
GPU 7: NVIDIA A800-SXM4-80GB

Nvidia driver version: 535.104.05
cuDNN version: Probably one of the following:
/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudnn.so.8
/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudnn_adv_infer.so.8
/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudnn_adv_train.so.8
/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudnn_cnn_infer.so.8
/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudnn_cnn_train.so.8
/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudnn_ops_infer.so.8
/usr/local/cuda-12.2/targets/x86_64-linux/lib/libcudnn_ops_train.so.8
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                128
On-line CPU(s) list:   0-127
Thread(s) per core:    2
Core(s) per socket:    32
座：                 2
NUMA 节点：         2
厂商 ID：           GenuineIntel
CPU 系列：          6
型号：              106
型号名称：        Intel(R) Xeon(R) Platinum 8358P CPU @ 2.60GHz
步进：              6
CPU MHz：             800.000
CPU max MHz:           2601.0000
CPU min MHz:           800.0000
BogoMIPS：            5200.00
虚拟化：           VT-x
L1d 缓存：          48K
L1i 缓存：          32K
L2 缓存：           1280K
L3 缓存：           49152K
NUMA 节点0 CPU：    0-31,64-95
NUMA 节点1 CPU：    32-63,96-127
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 invpcid_single ssbd mba rsb_ctxsw ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq md_clear pconfig spec_ctrl intel_stibp flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.0
[pip3] torch==2.1.0+cu121
[pip3] torchaudio==2.1.0+cu121
[pip3] torchvision==0.16.0+cu121
[pip3] triton==2.1.0
[conda] numpy                     1.26.0                    <pip>
[conda] torch                     2.1.0+cu121               <pip>
[conda] torchaudio                2.1.0+cu121               <pip>
[conda] torchvision               0.16.0+cu121              <pip>
[conda] triton                    2.1.0                     <pip>