Skip to content

Memory corruption in test_transformers #115253

@Flamefire

Description

@Flamefire

🐛 Describe the bug

When running test_transformers the test_scaled_dot_product_fused_attention_vs_math_cpu subtest runs into memory corruption issues, i.e. either of:

.double free or corruption (!prev)
.python: malloc.c:3852: _int_malloc: Assertion `chunk_main_arena (bck->bk)' failed.
.munmap_chunk(): invalid pointer

Followed by "Aborted (core dumped)"

This can be easily reproduced with python test_transformers.py -k test_scaled_dot_product_fused_attention_vs_math_cpu

As the test is expanded via parametrization to 192 subtests I tried to narrow it down to those 8 tests:

  • TestSDPACPU.test_scaled_dot_product_fused_attention_vs_math_cpu_fused_kernel_SDPBackend_FLASH_ATTENTION_bfloat16_batch_size_12_seq_len_1030_n_head_1_head_dim_16_causal_False_train_True_cpu_bfloat16
  • TestSDPACPU.test_scaled_dot_product_fused_attention_vs_math_cpu_fused_kernel_SDPBackend_FLASH_ATTENTION_bfloat16_batch_size_12_seq_len_1030_n_head_1_head_dim_16_causal_True_train_True_cpu_bfloat16
  • TestSDPACPU.test_scaled_dot_product_fused_attention_vs_math_cpu_fused_kernel_SDPBackend_FLASH_ATTENTION_bfloat16_batch_size_12_seq_len_1030_n_head_3_head_dim_16_causal_False_train_True_cpu_bfloat16
  • TestSDPACPU.test_scaled_dot_product_fused_attention_vs_math_cpu_fused_kernel_SDPBackend_FLASH_ATTENTION_bfloat16_batch_size_12_seq_len_1030_n_head_3_head_dim_16_causal_True_train_True_cpu_bfloat16
  • TestSDPACPU.test_scaled_dot_product_fused_attention_vs_math_cpu_fused_kernel_SDPBackend_FLASH_ATTENTION_bfloat16_batch_size_2_seq_len_1030_n_head_1_head_dim_16_causal_False_train_True_cpu_bfloat16
  • TestSDPACPU.test_scaled_dot_product_fused_attention_vs_math_cpu_fused_kernel_SDPBackend_FLASH_ATTENTION_bfloat16_batch_size_2_seq_len_1030_n_head_1_head_dim_16_causal_True_train_True_cpu_bfloat16
  • TestSDPACPU.test_scaled_dot_product_fused_attention_vs_math_cpu_fused_kernel_SDPBackend_FLASH_ATTENTION_bfloat16_batch_size_2_seq_len_1030_n_head_3_head_dim_16_causal_False_train_True_cpu_bfloat16
  • TestSDPACPU.test_scaled_dot_product_fused_attention_vs_math_cpu_fused_kernel_SDPBackend_FLASH_ATTENTION_bfloat16_batch_size_2_seq_len_1030_n_head_3_head_dim_16_causal_True_train_True_cpu_bfloat16

Given that the corruption happens if the following conditions are met with the other parameters seemingly without impact:

  • dtype=bfloat16
  • seq_len=1030
  • head_dim=16
  • train=True

When running the test on PyTorch 2.0.1 I don't see that crash, so it seems to be a regression in 2.1.0

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: Red Hat Enterprise Linux release 8.7 (Ootpa) (x86_64)
GCC version: (GCC) 11.3.0
Clang version: Could not collect
CMake version: version 3.23.1
Libc version: glibc-2.28

Python version: 3.10.4 (main, Nov 3 2023, 13:46:23) [GCC 11.3.0] (64-bit runtime)
Python platform: Linux-4.18.0-425.19.2.el8_7.x86_64-x86_64-with-glibc2.28
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
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
Address sizes: 46 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 208
On-line CPU(s) list: 0-207
Vendor ID: GenuineIntel
Model name: Intel(R) Xeon(R) Platinum 8470
CPU family: 6
Model: 143
Thread(s) per core: 2
Core(s) per socket: 52
Socket(s): 2
Stepping: 8
Frequency boost: enabled
CPU(s) scaling MHz: 189%
CPU max MHz: 2001.0000
CPU min MHz: 800.0000
BogoMIPS: 4000.00
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 cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor 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 cpuid_fault epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_ppin cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local split_lock_detect avx_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities
Virtualization: VT-x
L1d cache: 4.9 MiB (104 instances)
L1i cache: 3.3 MiB (104 instances)
L2 cache: 208 MiB (104 instances)
L3 cache: 210 MiB (2 instances)
NUMA node(s): 8
NUMA node0 CPU(s): 0-12,104-116
NUMA node1 CPU(s): 13-25,117-129
NUMA node2 CPU(s): 26-38,130-142
NUMA node3 CPU(s): 39-51,143-155
NUMA node4 CPU(s): 52-64,156-168
NUMA node5 CPU(s): 65-77,169-181
NUMA node6 CPU(s): 78-90,182-194
NUMA node7 CPU(s): 91-103,195-207
Vulnerability Itlb multihit: Not affected
Vulnerability L1tf: Not affected
Vulnerability Mds: Not affected
Vulnerability Meltdown: Not affected
Vulnerability Mmio stale data: Not affected
Vulnerability Retbleed: Not affected
Vulnerability Spec store bypass: Vulnerable
Vulnerability Spectre v1: Vulnerable: __user pointer sanitization and usercopy barriers only; no swapgs barriers
Vulnerability Spectre v2: Vulnerable, IBPB: disabled, STIBP: disabled, PBRSB-eIBRS: Vulnerable
Vulnerability Srbds: Not affected
Vulnerability Tsx async abort: Not affected

Versions of relevant libraries:
[pip3] numpy==1.22.3
[pip3] torch==2.1.0
[pip3] triton==2.1.0
[conda] Could not collect

cc @mruberry @ZainRizvi @jbschlosser @bhosmer @cpuhrsch @erichan1 @drisspg @mikaylagawarecki

Metadata

Metadata

Assignees

Labels

module: testsIssues related to tests (not the torch.testing module)triagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate module

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions