1
1
数学库
新人贴
DTK 26.04的rocsolver在计算eigh似乎还是有问题。
2026-04-13 12:30:02
124
torch.linalg.eigh 计算321x321的矩阵,大概迭代10多轮就会变得超级慢。 torch: torch-2.7.1+das.opt1.dtk2604-cp310-cp310-manylinux_2_28_x86_64.whl dtk: 26.04 driver: rock-6.3.30-V1.4.1a.run bw200 看了一下后端的库是 librocsolver.so.0 => /opt/dtk-26.04/lib/librocsolver.so.0 librocblas.so.4 => /opt/dtk-26.04/lib/librocblas.so.4 测试代码片段如下: ``` def test_eigh_progressive_degradation(device, size=321, total_updates=100): """Key test: Simulate the exact pattern seen in opt.log where eigh becomes slow after ~10+ iterations. This progressively applies BFGS updates and times each eigh call.""" print("=" * 80) print(f"PROGRESSIVE DEGRADATION TEST: {total_updates} BFGS iterations, size={size}") print("=" * 80) alpha = 70.0 H = torch.eye(size, device=device, dtype=torch.float64) * alpha torch.manual_seed(42) pos = torch.randn(size, device=device, dtype=torch.float64) * 0.01 forces = torch.randn(size, device=device, dtype=torch.float64) * 0.1 print(f"{'Iter':>4} {'eigh_gpu_ms':>14} {'eigh_cpu_ms':>14} {'cond':>14} {'H_norm':>14} {'H_diag_diff':>14}") prev_diag_norm = torch.diag(H).norm().item() for iteration in range(total_updates): # Time eigh on GPU torch.cuda.synchronize() if device == "cuda" else None t0 = time.perf_counter() omega, V = torch.linalg.eigh(H) torch.cuda.synchronize() if device == "cuda" else None t1 = time.perf_counter() gpu_ms = (t1 - t0) * 1000 # Time eigh on CPU H_cpu = H.cpu() t0 = time.perf_counter() torch.linalg.eigh(H_cpu) t1 = time.perf_counter() cpu_ms = (t1 - t0) * 1000 eig_min = omega[0].item() eig_max = omega[-1].item() cond = (eig_max / abs(eig_min)) if abs(eig_min) > 1e-30 else float('inf') H_norm = H.norm().item() diag_diff = abs(torch.diag(H).norm().item() - prev_diag_norm) prev_diag_norm = torch.diag(H).norm().item() flag = "" if gpu_ms > 50: flag = " ⚠ SLOW" if gpu_ms > cpu_ms * 5 and cpu_ms > 0.1: flag += f" ⚠ GPU {gpu_ms/cpu_ms:.0f}x SLOWER" print(f"{iteration:4d} {gpu_ms:14.3f} {cpu_ms:14.3f} {cond:14.3e} {H_norm:14.3e} {diag_diff:14.3e}{flag}") # Dump if slow if gpu_ms > 100: dump_dir = "/tmp/eigh_debug_dumps" os.makedirs(dump_dir, exist_ok=True) torch.save(H.cpu(), os.path.join(dump_dir, f"H_prog_size{size}_iter{iteration}.pt")) # Compute step and update (same as bfgs_torch.py) dpos_dir = V @ (forces.t() @ V / torch.abs(omega)).t() step_len = dpos_dir.norm().item() scale = min(1.0, 0.2 / max(step_len, 1e-10)) new_pos = pos + dpos_dir * scale # Simulate force change new_forces = forces * (0.85 + 0.3 * torch.rand(1, device=device, dtype=torch.float64).item()) new_forces += torch.randn_like(forces) * 0.002 # BFGS update dpos = new_pos - pos dforces = new_forces - forces if torch.abs(dpos).max() > 1e-7: dg = H @ dpos a = torch.dot(dforces, dpos) b = torch.dot(dpos, dg) if abs(a.item()) > 1e-15 and abs(b.item()) > 1e-15: H = H - torch.outer(dforces, dforces) / a - torch.outer(dg, dg) / b pos = new_pos forces = new_forces ``` 最新更新:PyTorch 默认选用了有缺陷的 MAGMA 算子库(magma_dsyevd_gpu)。 1. PyTorch 底层的多后端机制: 在 PyTorch 中,torch.linalg.eigh 在 GPU 端有两个候选后端: • cusolver(在海光 DCU 上被宏映射为海光原生 hipSOLVER) • magma(第三方代数库 MAGMA,算子名为 magma_dsyevd_gpu) 2. 故障算子:MAGMA 库的 magma_dsyevd_gpu,在 DCU 上存在 __launch_bounds__ 越界与重根迭代死锁缺陷。 3. 修复手段:通过 torch.backends.cuda.preferred_linalg_library('cusolver') 将后端强制指向海光原生 hipSOLVER,纯 GPU 原生运行,完美解决。
vllm
海光 BW 64GB
qwen
全部评论(9)
只看楼主
Y
yanzy
2楼
试试export ROCSOLVER_BLOCKED_ALGO=0这个参数能不能绕过去。不能绕过去的话,还得麻烦留一下镜像信息,和复现问题的步骤
4/13
N
neandeny
回复 @yanzy
好。我先试一下。另外使用社区提供的torch-2.7.1+das.opt1.dtk2604-cp310-cp310-manylinux_2_28_x86_64.whl 或者2.7.1-ubuntu22.04-dtk26.04-py3.10镜像,加上一个测试脚本就行。我这里可以上传脚本到gitee
4/13
Y
yanzy
1楼
有没有日志信息,确认一下cond数和gpu时间的关系
4/13
N
neandeny
回复 @yanzy
05:41:40 - 386682 - INFO - Step Fmax(eV/A)
05:41:40 - 386682 - INFO - 0 0.253283182148787
05:41:40 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=14.537ms, cond=1.000e+00, eig_min=7.000e+01, eig_max=7.000e+01
05:41:40 - 386682 - INFO - 1 0.222348417211786
05:41:40 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.347ms, cond=2.647e+00, eig_min=4.733e+01, eig_max=1.253e+02
05:41:40 - 386682 - INFO - 2 0.0578248741308243
05:41:40 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.362ms, cond=5.392e+00, eig_min=3.034e+01, eig_max=1.636e+02
05:41:40 - 386682 - INFO - 3 0.070036658788222
05:41:40 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.354ms, cond=1.308e+01, eig_min=1.215e+01, eig_max=1.589e+02
05:41:40 - 386682 - INFO - 4 0.0566683146198651
05:41:40 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.348ms, cond=1.972e+01, eig_min=7.574e+00, eig_max=1.493e+02
05:41:40 - 386682 - INFO - 5 0.0562126521863167
05:41:41 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.478ms, cond=3.963e+01, eig_min=4.023e+00, eig_max=1.595e+02
05:41:41 - 386682 - INFO - 6 0.0657506997907059
05:41:41 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.409ms, cond=6.944e+01, eig_min=2.458e+00, eig_max=1.707e+02
05:41:41 - 386682 - INFO - 7 0.104232219842957
05:41:41 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.407ms, cond=9.184e+01, eig_min=1.817e+00, eig_max=1.669e+02
05:41:41 - 386682 - INFO - 8 0.0690597654671199
05:41:41 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.425ms, cond=9.075e+01, eig_min=1.700e+00, eig_max=1.543e+02
05:41:41 - 386682 - INFO - 9 0.0559879484095137
05:41:41 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.478ms, cond=9.887e+01, eig_min=1.605e+00, eig_max=1.586e+02
05:41:41 - 386682 - INFO - 10 0.0562832976264053
05:41:41 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.410ms, cond=1.278e+02, eig_min=1.351e+00, eig_max=1.727e+02
05:41:41 - 386682 - INFO - 11 0.0803992007032949
05:41:42 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.442ms, cond=1.729e+02, eig_min=1.006e+00, eig_max=1.740e+02
05:41:42 - 386682 - INFO - 12 0.0879353511670851
05:41:42 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.500ms, cond=2.252e+02, eig_min=7.253e-01, eig_max=1.633e+02
05:41:42 - 386682 - INFO - 13 0.0710123804596261
05:41:42 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.477ms, cond=2.907e+02, eig_min=5.452e-01, eig_max=1.585e+02
05:41:42 - 386682 - INFO - 14 0.0623047541753428
05:41:42 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.533ms, cond=3.932e+02, eig_min=4.216e-01, eig_max=1.658e+02
05:41:42 - 386682 - INFO - 15 0.0686281122940318
05:41:42 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.731ms, cond=5.158e+02, eig_min=3.329e-01, eig_max=1.717e+02
05:41:42 - 386682 - INFO - 16 0.101737524399213
05:41:43 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.762ms, cond=6.558e+02, eig_min=2.552e-01, eig_max=1.673e+02
05:41:43 - 386682 - INFO - 17 0.0980871271816612
05:41:43 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=9.722ms, cond=8.273e+02, eig_min=1.934e-01, eig_max=1.600e+02
05:41:43 - 386682 - INFO - 18 0.113307778943982
05:42:32 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=49278.607ms, cond=1.031e+03, eig_min=1.551e-01, eig_max=1.598e+02
05:42:32 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step288_idx0.pt
05:42:32 - 386682 - INFO - 19 0.0862484804161348
05:43:01 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=28643.415ms, cond=1.228e+03, eig_min=1.337e-01, eig_max=1.641e+02
05:43:01 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step289_idx0.pt
05:43:01 - 386682 - INFO - 20 0.0960544722034441
05:43:30 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=28641.558ms, cond=1.360e+03, eig_min=1.208e-01, eig_max=1.643e+02
05:43:30 - 386682 - INFO - 21 0.103083592386865
05:44:12 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=41555.243ms, cond=1.458e+03, eig_min=1.096e-01, eig_max=1.598e+02
05:44:12 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step291_idx0.pt
05:44:12 - 386682 - INFO - 22 0.118760643480967
05:44:41 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=28638.197ms, cond=1.600e+03, eig_min=9.962e-02, eig_max=1.594e+02
05:44:41 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step292_idx0.pt
05:44:41 - 386682 - INFO - 23 0.081203377529422
05:45:09 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=28628.602ms, cond=1.823e+03, eig_min=8.973e-02, eig_max=1.636e+02
05:45:09 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step293_idx0.pt
05:45:09 - 386682 - INFO - 24 0.0749226649329974
05:45:40 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=30111.874ms, cond=1.986e+03, eig_min=8.237e-02, eig_max=1.636e+02
05:45:40 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step294_idx0.pt
05:45:40 - 386682 - INFO - 25 0.0750817447368421
05:46:08 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=28639.783ms, cond=2.064e+03, eig_min=7.711e-02, eig_max=1.591e+02
05:46:08 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step295_idx0.pt
05:46:09 - 386682 - INFO - 26 0.0687659720487184
05:47:01 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=51942.020ms, cond=2.188e+03, eig_min=7.335e-02, eig_max=1.605e+02
05:47:01 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step296_idx0.pt
05:47:01 - 386682 - INFO - 27 0.0912610673425455
05:47:29 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=28639.431ms, cond=2.340e+03, eig_min=7.059e-02, eig_max=1.652e+02
05:47:29 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step297_idx0.pt
05:47:30 - 386682 - INFO - 28 0.0977618751359609
05:47:58 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=28638.356ms, cond=2.392e+03, eig_min=6.881e-02, eig_max=1.646e+02
05:47:58 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step298_idx0.pt
05:47:58 - 386682 - INFO - 29 0.0964950529891688
05:48:27 - 386682 - INFO - [eigh_prof] idx=0, H_size=321, eigh_cost=28640.180ms, cond=2.406e+03, eig_min=6.621e-02, eig_max=1.593e+02
05:48:27 - 386682 - INFO - [eigh_prof] Dumped H matrix to /tmp/eigh_debug_dumps/H_step299_idx0.pt
05:48:27 - 386682 - INFO - 30 0.0797893878811294
05:48:27 - 386682 - INFO - [eigh_timing] device=gpu, threads=1, total_calls=300, total_time=2153148.30ms, avg_per_call=7177.16ms
05:48:27 - 386682 - INFO - Final energies of all structures: [-66961.69019018265]
4/13
N
neandeny
回复 @neandeny
第18次迭代开始出问题。
4/13
N
neandeny
回复 @neandeny
上面的是真实应用中的log。下面的是随机数据的测试,也是第18轮出了问题:

 python scripts/test_eigh_rocsolver.py --mode progressive --device cuda --size 321 --iterations 50
PyTorch version: 2.7.1
CUDA available: True
Device name: BW200, UBB BW1000
Device count: 8
Device: cuda
Dtype: float64
================================================================================
PROGRESSIVE DEGRADATION TEST: 50 BFGS iterations, size=321
================================================================================
Iter eigh_gpu_ms eigh_cpu_ms cond H_norm H_diag_diff
   0 3652.368 138.368 1.000e+00 1.254e+03 0.000e+00 ⚠ SLOW ⚠ GPU 26x SLOWER
   1 13.651 68.719 2.081e+01 1.252e+03 4.112e+00
   2 8.966 68.241 7.061e+01 1.252e+03 1.299e-01
   3 9.629 57.152 8.708e+01 1.252e+03 8.487e-03
   4 8.969 58.275 5.434e+01 1.252e+03 1.178e-01
   5 10.850 42.303 1.378e+02 1.252e+03 1.033e-01
   6 9.661 41.019 6.533e+01 1.252e+03 8.955e-02
   7 9.904 53.873 1.039e+02 1.252e+03 9.932e-02
   8 9.242 40.069 6.964e+01 1.252e+03 9.502e-02
   9 15.277 40.780 5.698e+01 1.252e+03 1.255e-01
  10 9.266 42.185 5.104e+01 1.252e+03 9.103e-03
  11 9.220 43.102 1.462e+02 1.252e+03 4.635e-02
  12 9.976 43.512 8.832e+01 1.252e+03 1.941e-02
  13 9.317 39.286 1.219e+03 1.252e+03 7.454e-02
  14 9.217 49.465 5.840e+01 1.252e+03 7.156e-02
  15 9.186 44.528 3.835e+01 1.252e+03 3.611e-02
  16 9.222 39.804 5.479e+01 1.252e+03 1.751e-01
  17 9.916 40.533 3.316e+02 1.252e+03 5.174e-02
  18 37402.758 45.361 1.028e+02 1.252e+03 2.885e-02 ⚠ SLOW ⚠ GPU 825x SLOWER
  19 28639.540 48.159 5.619e+01 1.252e+03 1.093e-01 ⚠ SLOW ⚠ GPU 595x SLOWER
  20 28639.859 54.947 6.680e+01 1.252e+03 9.243e-03 ⚠ SLOW ⚠ GPU 521x SLOWER
  21 49979.278 53.978 4.989e+01 1.252e+03 2.133e-02 ⚠ SLOW ⚠ GPU 926x SLOWER
  22 28630.158 56.724 4.281e+01 1.252e+03 1.421e-02 ⚠ SLOW ⚠ GPU 505x SLOWER
  23 28646.880 60.085 3.567e+01 1.252e+03 2.023e-01 ⚠ SLOW ⚠ GPU 477x SLOWER
  24 49130.553 59.257 1.181e+02 1.252e+03 1.458e-01 ⚠ SLOW ⚠ GPU 829x SLOWER
  25 28635.494 82.660 4.641e+02 1.252e+03 1.500e-02 ⚠ SLOW ⚠ GPU 346x SLOWER
  26 28644.479 41.904 5.871e+01 1.252e+03 7.660e-02 ⚠ SLOW ⚠ GPU 684x SLOWER
  27 28628.834 41.338 2.753e+01 1.252e+03 7.626e-02 ⚠ SLOW ⚠ GPU 693x SLOWER
  28 36315.845 54.009 4.284e+01 1.252e+03 4.979e-02 ⚠ SLOW ⚠ GPU 672x SLOWER
  29 31945.127 42.129 1.448e+02 1.252e+03 6.026e-02 ⚠ SLOW ⚠ GPU 758x SLOWER
  30 29009.253 54.588 3.780e+01 1.252e+03 7.749e-02 ⚠ SLOW ⚠ GPU 531x SLOWER
4/13
全部6条回复
没有更多内容了
--
楼主
Level.2
0 帖子
楼主热帖
暂无数据