[GH-ISSUE #1411] [Bug] moe 算子开启numa功能, alloc和free 不一致,导致free 失效oom #943

Open
opened 2026-10-29 14:46:35 +00:00 by bsakaguchi · 1 comment
Owner

Originally created by @huanghaoXcore on GitHub (Jul 1, 2025).
Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/1411

检查清单

  • 1. 我已经搜索过相关问题,但未能获得预期的帮助
  • 2. 该问题在最新版本中尚未修复
  • 3. 请注意,如果您提交的BUG相关 issue 缺少对应环境信息和最小可复现示例,我们将难以复现和定位问题,降低获得反馈的可能性
  • 4. 如果您提出的不是bug而是问题,请在讨论区发起讨论 https://github.com/kvcache-ai/ktransformers/discussions。否则该 issue 将被关闭
  • 5. 为方便社区交流,我将使用中文/英文或附上中文/英文翻译(如使用其他语言)。未附带翻译的非中文/英语内容可能会被关闭

问题描述

moe 算子开启numa功能, alloc和free 不一致,导致free 失效oom

deepseek R1 模型, moe算子,free时候,计算free size时候, 超过int32 表示范围,导致free失效,numa内存没有回收,导致oom

fix patch
MOE::~MOE() {
shared_mem_buffer.dealloc(this);

#ifdef USE_NUMA
int numa_nodes = numa_num_configured_nodes();

for (int i = 0; i < numa_nodes; i++) {
    size_t exp_inter_hidden_mul_ = (size_t)config_.expert_num * config_.intermediate_size * config_.hidden_size;
    numa_free(gate_proj_numa_[i], exp_inter_hidden_mul_ * ggml_type_size(config_.gate_type) / ggml_blck_size(config_.gate_type));
    numa_free(up_proj_numa_[i], exp_inter_hidden_mul_ * ggml_type_size(config_.up_type) / ggml_blck_size(config_.up_type));
    numa_free(down_proj_numa_[i], exp_inter_hidden_mul_ * ggml_type_size(config_.down_type) / ggml_blck_size(config_.down_type));
}
#endif

}

复现步骤

./bin/llama-cli -m /home/weight/DeepSeek-R1-GGUF-UD/Q2_K/DeepSeek-R1-Q2_K-00001-of-00005.gguf -ngl 99 -c 16384 -n 20000 -ot exps=CPU --no-op-offload --override-kv "deepseek2.expert_used_count=int:6" -t 48 -fa -b 2048 -ub 1024 -no-cnv -f /home/weight/prompts/ds-prompts/code.txt --no-warmup

环境信息

nvidia-smi
Tue Jul 1 18:14:36 2025
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.133.07 Driver Version: 570.133.07 CUDA Version: 12.8 |
|-----------------------------------------+------------------------+----------------------+
| GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|=========================================+========================+======================|
| 0 NVIDIA GeForce RTX 4090 Off | 00000000:2A:00.0 Off | Off |
| 34% 38C P8 18W / 450W | 485MiB / 24564MiB | 0% Default |
| | | N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=========================================================================================|
+-----------------------------------------------------------------------------------------+

lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Address sizes: 52 bits physical, 57 bits virtual
Byte Order: Little Endian
CPU(s): 128
On-line CPU(s) list: 0-127
Vendor ID: GenuineIntel
BIOS Vendor ID: Intel(R) Corporation
Model name: Intel(R) Xeon(R) Platinum 8462Y+
BIOS Model name: Intel(R) Xeon(R) Platinum 8462Y+ CPU @ 2.8GHz
BIOS CPU family: 179
CPU family: 6
Model: 143
Thread(s) per core: 2
Core(s) per socket: 32
Socket(s): 2
Stepping: 8
CPU(s) scaling MHz: 22%
CPU max MHz: 4100.0000
CPU min MHz: 800.0000
BogoMIPS: 5600.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_pe
rfmon 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 intel_ppin cdp_l2 ssbd mba ibr
s ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap 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 user_shstk avx
_vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req hfi vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512
_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr ibt amx_bf16 avx512_fp16
amx_tile amx_int8 flush_l1d arch_capabilities
Virtualization features:
Virtualization: VT-x
Caches (sum of all):
L1d: 3 MiB (64 instances)
L1i: 2 MiB (64 instances)
L2: 128 MiB (64 instances)
L3: 120 MiB (2 instances)
NUMA:
NUMA node(s): 2
NUMA node0 CPU(s): 0-31,64-95
NUMA node1 CPU(s): 32-63,96-127
Vulnerabilities:
Gather data sampling: Not affected
Itlb multihit: Not affected
L1tf: Not affected
Mds: Not affected
Meltdown: Not affected
Mmio stale data: Not affected
Reg file data sampling: Not affected
Retbleed: Not affected
Spec rstack overflow: Not affected
Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl
Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Srbds: Not affected
Tsx async abort: Not affected

Originally created by @huanghaoXcore on GitHub (Jul 1, 2025). Original GitHub issue: https://github.com/kvcache-ai/ktransformers/issues/1411 ### 检查清单 - [ ] 1. 我已经搜索过相关问题,但未能获得预期的帮助 - [x] 2. 该问题在最新版本中尚未修复 - [ ] 3. 请注意,如果您提交的BUG相关 issue 缺少对应环境信息和最小可复现示例,我们将难以复现和定位问题,降低获得反馈的可能性 - [ ] 4. 如果您提出的不是bug而是问题,请在讨论区发起讨论 https://github.com/kvcache-ai/ktransformers/discussions。否则该 issue 将被关闭 - [ ] 5. 为方便社区交流,我将使用中文/英文或附上中文/英文翻译(如使用其他语言)。未附带翻译的非中文/英语内容可能会被关闭 ### 问题描述 moe 算子开启numa功能, alloc和free 不一致,导致free 失效oom deepseek R1 模型, moe算子,free时候,计算free size时候, 超过int32 表示范围,导致free失效,numa内存没有回收,导致oom fix patch MOE::~MOE() { shared_mem_buffer.dealloc(this); #ifdef USE_NUMA int numa_nodes = numa_num_configured_nodes(); for (int i = 0; i < numa_nodes; i++) { size_t exp_inter_hidden_mul_ = (size_t)config_.expert_num * config_.intermediate_size * config_.hidden_size; numa_free(gate_proj_numa_[i], exp_inter_hidden_mul_ * ggml_type_size(config_.gate_type) / ggml_blck_size(config_.gate_type)); numa_free(up_proj_numa_[i], exp_inter_hidden_mul_ * ggml_type_size(config_.up_type) / ggml_blck_size(config_.up_type)); numa_free(down_proj_numa_[i], exp_inter_hidden_mul_ * ggml_type_size(config_.down_type) / ggml_blck_size(config_.down_type)); } #endif } ### 复现步骤 ./bin/llama-cli -m /home/weight/DeepSeek-R1-GGUF-UD/Q2_K/DeepSeek-R1-Q2_K-00001-of-00005.gguf -ngl 99 -c 16384 -n 20000 -ot exps=CPU --no-op-offload --override-kv "deepseek2.expert_used_count=int:6" -t 48 -fa -b 2048 -ub 1024 -no-cnv -f /home/weight/prompts/ds-prompts/code.txt --no-warmup ### 环境信息 nvidia-smi Tue Jul 1 18:14:36 2025 +-----------------------------------------------------------------------------------------+ | NVIDIA-SMI 570.133.07 Driver Version: 570.133.07 CUDA Version: 12.8 | |-----------------------------------------+------------------------+----------------------+ | GPU Name Persistence-M | Bus-Id Disp.A | Volatile Uncorr. ECC | | Fan Temp Perf Pwr:Usage/Cap | Memory-Usage | GPU-Util Compute M. | | | | MIG M. | |=========================================+========================+======================| | 0 NVIDIA GeForce RTX 4090 Off | 00000000:2A:00.0 Off | Off | | 34% 38C P8 18W / 450W | 485MiB / 24564MiB | 0% Default | | | | N/A | +-----------------------------------------+------------------------+----------------------+ +-----------------------------------------------------------------------------------------+ | Processes: | | GPU GI CI PID Type Process name GPU Memory | | ID ID Usage | |=========================================================================================| +-----------------------------------------------------------------------------------------+ lscpu Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 52 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 128 On-line CPU(s) list: 0-127 Vendor ID: GenuineIntel BIOS Vendor ID: Intel(R) Corporation Model name: Intel(R) Xeon(R) Platinum 8462Y+ BIOS Model name: Intel(R) Xeon(R) Platinum 8462Y+ CPU @ 2.8GHz BIOS CPU family: 179 CPU family: 6 Model: 143 Thread(s) per core: 2 Core(s) per socket: 32 Socket(s): 2 Stepping: 8 CPU(s) scaling MHz: 22% CPU max MHz: 4100.0000 CPU min MHz: 800.0000 BogoMIPS: 5600.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_pe rfmon 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 intel_ppin cdp_l2 ssbd mba ibr s ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap 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 user_shstk avx _vnni avx512_bf16 wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req hfi vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512 _vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b enqcmd fsrm md_clear serialize tsxldtrk pconfig arch_lbr ibt amx_bf16 avx512_fp16 amx_tile amx_int8 flush_l1d arch_capabilities Virtualization features: Virtualization: VT-x Caches (sum of all): L1d: 3 MiB (64 instances) L1i: 2 MiB (64 instances) L2: 128 MiB (64 instances) L3: 120 MiB (2 instances) NUMA: NUMA node(s): 2 NUMA node0 CPU(s): 0-31,64-95 NUMA node1 CPU(s): 32-63,96-127 Vulnerabilities: Gather data sampling: Not affected Itlb multihit: Not affected L1tf: Not affected Mds: Not affected Meltdown: Not affected Mmio stale data: Not affected Reg file data sampling: Not affected Retbleed: Not affected Spec rstack overflow: Not affected Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S Srbds: Not affected Tsx async abort: Not affected
Author
Owner

@magikRUKKOLA commented on GitHub (Jul 3, 2025):

复现步骤

./bin/llama-cli

This is ktransformers project. NOT llama-cli project. Please find a proper project page.

<!-- gh-comment-id:3032637121 --> @magikRUKKOLA commented on GitHub (Jul 3, 2025): > 复现步骤 > > ./bin/llama-cli This is ktransformers project. NOT llama-cli project. Please find a proper project page.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
kvcache-ai/ktransformers#943
No description provided.