Add files using upload-large-folder tool
Browse files- LTA_openwebtext_dualt/logs/lta_lm1b_dirichlet_len1024_Cv_to_2v_gbs512_8gpu_20k_save1k_gumbelwatch_20260524.log +687 -0
- LTA_openwebtext_dualt/logs/lta_owt_c1024_gpt2_cached_chunks_len1024_fast10k_4gpu_500step.log +168 -0
- LTA_openwebtext_dualt/logs/lta_owt_c1024_len1024_lowt0p2_lowk80_noall_buf1000_gbs128_4gpu_100step.nohup.log +73 -0
- LTA_openwebtext_dualt/logs/lta_owt_launcher_opt_smoke_bspgpu64_gbs512_4gpu_20step_20260513.outer.log +103 -0
- LTA_openwebtext_dualt/logs/owt_classic_fullvocab_len1024_infer_watch/infer_lta_owt_classic_fullvocab_bert_c1024_len1024_gbs512_8gpu_1m_save10k_20260521_162117_step_0010000_t1p45.log +260 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/__init__.pxd +14 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/__init__.py +215 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/__init__.pyi +72 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_common.pxd +106 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_generator.pyi +681 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_pcg64.pyi +42 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_pickle.py +80 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_sfc64.pyi +28 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/c_distributions.pxd +120 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/fsmt/__init__.py +28 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/fsmt/modeling_fsmt.py +1136 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/qwen3_vl_moe/__init__.py +27 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/qwen3_vl_moe/modeling_qwen3_vl_moe.py +1886 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/qwen3_vl_moe/modular_qwen3_vl_moe.py +467 -0
- LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/infer_not5_bottleneck128_170k_decode32_ema_20260611/lr4e3.log +29 -0
LTA_openwebtext_dualt/logs/lta_lm1b_dirichlet_len1024_Cv_to_2v_gbs512_8gpu_20k_save1k_gumbelwatch_20260524.log
ADDED
|
@@ -0,0 +1,687 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
*****************************************
|
| 3 |
+
Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.
|
| 4 |
+
*****************************************
|
| 5 |
+
t-20260524091317-xb65t-worker-0:10324:10324 [0] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 6 |
+
t-20260524091317-xb65t-worker-0:10324:10324 [0] NCCL INFO Bootstrap: Using eth1:10.82.96.52<0>
|
| 7 |
+
t-20260524091317-xb65t-worker-0:10324:10324 [0] NCCL INFO cudaDriverVersion 12080
|
| 8 |
+
t-20260524091317-xb65t-worker-0:10324:10324 [0] NCCL INFO NCCL version 2.25.1+cuda12.8
|
| 9 |
+
t-20260524091317-xb65t-worker-0:10324:10324 [0] NCCL INFO Comm config Blocking set to 1
|
| 10 |
+
t-20260524091317-xb65t-worker-0:10325:10325 [1] NCCL INFO cudaDriverVersion 12080
|
| 11 |
+
t-20260524091317-xb65t-worker-0:10325:10325 [1] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 12 |
+
t-20260524091317-xb65t-worker-0:10325:10325 [1] NCCL INFO Bootstrap: Using eth1:10.82.96.52<0>
|
| 13 |
+
t-20260524091317-xb65t-worker-0:10325:10325 [1] NCCL INFO NCCL version 2.25.1+cuda12.8
|
| 14 |
+
t-20260524091317-xb65t-worker-0:10325:10325 [1] NCCL INFO Comm config Blocking set to 1
|
| 15 |
+
t-20260524091317-xb65t-worker-0:10329:10329 [5] NCCL INFO cudaDriverVersion 12080
|
| 16 |
+
t-20260524091317-xb65t-worker-0:10329:10329 [5] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 17 |
+
t-20260524091317-xb65t-worker-0:10329:10329 [5] NCCL INFO Bootstrap: Using eth1:10.82.96.52<0>
|
| 18 |
+
t-20260524091317-xb65t-worker-0:10329:10329 [5] NCCL INFO NCCL version 2.25.1+cuda12.8
|
| 19 |
+
t-20260524091317-xb65t-worker-0:10329:10329 [5] NCCL INFO Comm config Blocking set to 1
|
| 20 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
|
| 21 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
|
| 22 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
|
| 23 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO P2P plugin v9 IBext_v9
|
| 24 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 25 |
+
t-20260524091317-xb65t-worker-0:10327:10327 [3] NCCL INFO cudaDriverVersion 12080
|
| 26 |
+
t-20260524091317-xb65t-worker-0:10327:10327 [3] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 27 |
+
t-20260524091317-xb65t-worker-0:10327:10327 [3] NCCL INFO Bootstrap: Using eth1:10.82.96.52<0>
|
| 28 |
+
t-20260524091317-xb65t-worker-0:10327:10327 [3] NCCL INFO NCCL version 2.25.1+cuda12.8
|
| 29 |
+
t-20260524091317-xb65t-worker-0:10327:10327 [3] NCCL INFO Comm config Blocking set to 1
|
| 30 |
+
t-20260524091317-xb65t-worker-0:10328:10328 [4] NCCL INFO cudaDriverVersion 12080
|
| 31 |
+
t-20260524091317-xb65t-worker-0:10328:10328 [4] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 32 |
+
t-20260524091317-xb65t-worker-0:10328:10328 [4] NCCL INFO Bootstrap: Using eth1:10.82.96.52<0>
|
| 33 |
+
t-20260524091317-xb65t-worker-0:10328:10328 [4] NCCL INFO NCCL version 2.25.1+cuda12.8
|
| 34 |
+
t-20260524091317-xb65t-worker-0:10328:10328 [4] NCCL INFO Comm config Blocking set to 1
|
| 35 |
+
t-20260524091317-xb65t-worker-0:10330:10330 [6] NCCL INFO cudaDriverVersion 12080
|
| 36 |
+
t-20260524091317-xb65t-worker-0:10330:10330 [6] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 37 |
+
t-20260524091317-xb65t-worker-0:10330:10330 [6] NCCL INFO Bootstrap: Using eth1:10.82.96.52<0>
|
| 38 |
+
t-20260524091317-xb65t-worker-0:10330:10330 [6] NCCL INFO NCCL version 2.25.1+cuda12.8
|
| 39 |
+
t-20260524091317-xb65t-worker-0:10330:10330 [6] NCCL INFO Comm config Blocking set to 1
|
| 40 |
+
t-20260524091317-xb65t-worker-0:10326:10326 [2] NCCL INFO cudaDriverVersion 12080
|
| 41 |
+
t-20260524091317-xb65t-worker-0:10326:10326 [2] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 42 |
+
t-20260524091317-xb65t-worker-0:10326:10326 [2] NCCL INFO Bootstrap: Using eth1:10.82.96.52<0>
|
| 43 |
+
t-20260524091317-xb65t-worker-0:10326:10326 [2] NCCL INFO NCCL version 2.25.1+cuda12.8
|
| 44 |
+
t-20260524091317-xb65t-worker-0:10326:10326 [2] NCCL INFO Comm config Blocking set to 1
|
| 45 |
+
t-20260524091317-xb65t-worker-0:10331:10331 [7] NCCL INFO cudaDriverVersion 12080
|
| 46 |
+
t-20260524091317-xb65t-worker-0:10331:10331 [7] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 47 |
+
t-20260524091317-xb65t-worker-0:10331:10331 [7] NCCL INFO Bootstrap: Using eth1:10.82.96.52<0>
|
| 48 |
+
t-20260524091317-xb65t-worker-0:10331:10331 [7] NCCL INFO NCCL version 2.25.1+cuda12.8
|
| 49 |
+
t-20260524091317-xb65t-worker-0:10331:10331 [7] NCCL INFO Comm config Blocking set to 1
|
| 50 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
|
| 51 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO NET/IB : Using [0]mlx5_1:1/RoCE [1]mlx5_4:1/RoCE [2]mlx5_5:1/RoCE [3]mlx5_6:1/RoCE [4]mlx5_7:1/RoCE [5]mlx5_8:1/RoCE [6]mlx5_9:1/RoCE [7]mlx5_10:1/RoCE [RO]; OOB eth1:10.82.96.52<0>
|
| 52 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
|
| 53 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Using network IBext_v9
|
| 54 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO ncclCommInitRankConfig comm 0xd973700 rank 0 nranks 8 cudaDev 0 nvmlDev 0 busId 65040 commId 0xe94542814597d064 - Init START
|
| 55 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
|
| 56 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
|
| 57 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
|
| 58 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO P2P plugin v9 IBext_v9
|
| 59 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 60 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
|
| 61 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
|
| 62 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
|
| 63 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO P2P plugin v9 IBext_v9
|
| 64 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 65 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
|
| 66 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
|
| 67 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
|
| 68 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO P2P plugin v9 IBext_v9
|
| 69 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 70 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
|
| 71 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
|
| 72 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
|
| 73 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO P2P plugin v9 IBext_v9
|
| 74 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 75 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
|
| 76 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
|
| 77 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
|
| 78 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO P2P plugin v9 IBext_v9
|
| 79 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 80 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
|
| 81 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
|
| 82 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
|
| 83 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO P2P plugin v9 IBext_v9
|
| 84 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 85 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
|
| 86 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
|
| 87 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
|
| 88 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO P2P plugin v9 IBext_v9
|
| 89 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
|
| 90 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
|
| 91 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO NET/IB : Using [0]mlx5_1:1/RoCE [1]mlx5_4:1/RoCE [2]mlx5_5:1/RoCE [3]mlx5_6:1/RoCE [4]mlx5_7:1/RoCE [5]mlx5_8:1/RoCE [6]mlx5_9:1/RoCE [7]mlx5_10:1/RoCE [RO]; OOB eth1:10.82.96.52<0>
|
| 92 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
|
| 93 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO Using network IBext_v9
|
| 94 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
|
| 95 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO NET/IB : Using [0]mlx5_1:1/RoCE [1]mlx5_4:1/RoCE [2]mlx5_5:1/RoCE [3]mlx5_6:1/RoCE [4]mlx5_7:1/RoCE [5]mlx5_8:1/RoCE [6]mlx5_9:1/RoCE [7]mlx5_10:1/RoCE [RO]; OOB eth1:10.82.96.52<0>
|
| 96 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
|
| 97 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO Using network IBext_v9
|
| 98 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
|
| 99 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO NET/IB : Using [0]mlx5_1:1/RoCE [1]mlx5_4:1/RoCE [2]mlx5_5:1/RoCE [3]mlx5_6:1/RoCE [4]mlx5_7:1/RoCE [5]mlx5_8:1/RoCE [6]mlx5_9:1/RoCE [7]mlx5_10:1/RoCE [RO]; OOB eth1:10.82.96.52<0>
|
| 100 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
|
| 101 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO Using network IBext_v9
|
| 102 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
|
| 103 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO NET/IB : Using [0]mlx5_1:1/RoCE [1]mlx5_4:1/RoCE [2]mlx5_5:1/RoCE [3]mlx5_6:1/RoCE [4]mlx5_7:1/RoCE [5]mlx5_8:1/RoCE [6]mlx5_9:1/RoCE [7]mlx5_10:1/RoCE [RO]; OOB eth1:10.82.96.52<0>
|
| 104 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
|
| 105 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO Using network IBext_v9
|
| 106 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
|
| 107 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO NET/IB : Using [0]mlx5_1:1/RoCE [1]mlx5_4:1/RoCE [2]mlx5_5:1/RoCE [3]mlx5_6:1/RoCE [4]mlx5_7:1/RoCE [5]mlx5_8:1/RoCE [6]mlx5_9:1/RoCE [7]mlx5_10:1/RoCE [RO]; OOB eth1:10.82.96.52<0>
|
| 108 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
|
| 109 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO Using network IBext_v9
|
| 110 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
|
| 111 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO NET/IB : Using [0]mlx5_1:1/RoCE [1]mlx5_4:1/RoCE [2]mlx5_5:1/RoCE [3]mlx5_6:1/RoCE [4]mlx5_7:1/RoCE [5]mlx5_8:1/RoCE [6]mlx5_9:1/RoCE [7]mlx5_10:1/RoCE [RO]; OOB eth1:10.82.96.52<0>
|
| 112 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
|
| 113 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO NET/IB : Using [0]mlx5_1:1/RoCE [1]mlx5_4:1/RoCE [2]mlx5_5:1/RoCE [3]mlx5_6:1/RoCE [4]mlx5_7:1/RoCE [5]mlx5_8:1/RoCE [6]mlx5_9:1/RoCE [7]mlx5_10:1/RoCE [RO]; OOB eth1:10.82.96.52<0>
|
| 114 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
|
| 115 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO Using network IBext_v9
|
| 116 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
|
| 117 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO Using network IBext_v9
|
| 118 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO ncclCommInitRankConfig comm 0xb3a9dc0 rank 1 nranks 8 cudaDev 1 nvmlDev 1 busId 67020 commId 0xe94542814597d064 - Init START
|
| 119 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO ncclCommInitRankConfig comm 0xb803a00 rank 3 nranks 8 cudaDev 3 nvmlDev 3 busId 6b020 commId 0xe94542814597d064 - Init START
|
| 120 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO ncclCommInitRankConfig comm 0xa75cfc0 rank 5 nranks 8 cudaDev 5 nvmlDev 5 busId 71020 commId 0xe94542814597d064 - Init START
|
| 121 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO ncclCommInitRankConfig comm 0xa12b740 rank 4 nranks 8 cudaDev 4 nvmlDev 4 busId 6f020 commId 0xe94542814597d064 - Init START
|
| 122 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO RAS client listening socket at ::1<28028>
|
| 123 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO ncclCommInitRankConfig comm 0xb514740 rank 6 nranks 8 cudaDev 6 nvmlDev 6 busId 73020 commId 0xe94542814597d064 - Init START
|
| 124 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO RAS client listening socket at ::1<28028>
|
| 125 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO ncclCommInitRankConfig comm 0xb5394c0 rank 7 nranks 8 cudaDev 7 nvmlDev 7 busId 75020 commId 0xe94542814597d064 - Init START
|
| 126 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO RAS client listening socket at ::1<28028>
|
| 127 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO ncclCommInitRankConfig comm 0x9d7a4c0 rank 2 nranks 8 cudaDev 2 nvmlDev 2 busId 69020 commId 0xe94542814597d064 - Init START
|
| 128 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO RAS client listening socket at ::1<28028>
|
| 129 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO RAS client listening socket at ::1<28028>
|
| 130 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO RAS client listening socket at ::1<28028>
|
| 131 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO RAS client listening socket at ::1<28028>
|
| 132 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO RAS client listening socket at ::1<28028>
|
| 133 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO Bootstrap timings total 0.012864 (create 0.000026, send 0.000075, recv 0.007017, ring 0.005429, delay 0.000001)
|
| 134 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO Bootstrap timings total 0.008913 (create 0.000019, send 0.000061, recv 0.000120, ring 0.008428, delay 0.000001)
|
| 135 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO Bootstrap timings total 0.025766 (create 0.000020, send 0.000067, recv 0.016937, ring 0.001309, delay 0.000001)
|
| 136 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO Bootstrap timings total 0.001775 (create 0.000020, send 0.000069, recv 0.000095, ring 0.000093, delay 0.000001)
|
| 137 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO Bootstrap timings total 0.005908 (create 0.000020, send 0.000063, recv 0.003807, ring 0.001745, delay 0.000001)
|
| 138 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO Bootstrap timings total 0.105052 (create 0.000023, send 0.000062, recv 0.104563, ring 0.000086, delay 0.000001)
|
| 139 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO Bootstrap timings total 0.002241 (create 0.000023, send 0.000068, recv 0.000153, ring 0.001709, delay 0.000001)
|
| 140 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Bootstrap timings total 0.960418 (create 0.000026, send 0.000077, recv 0.855478, ring 0.001623, delay 0.000001)
|
| 141 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO MNNVL busId 0x6f020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
|
| 142 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO MNNVL busId 0x6b020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
|
| 143 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO MNNVL busId 0x71020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
|
| 144 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO MNNVL busId 0x73020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
|
| 145 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO MNNVL busId 0x69020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
|
| 146 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO MNNVL busId 0x67020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
|
| 147 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO MNNVL busId 0x75020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
|
| 148 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO MNNVL busId 0x65040 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
|
| 149 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
|
| 150 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
|
| 151 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
|
| 152 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
|
| 153 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
|
| 154 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
|
| 155 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
|
| 156 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
|
| 157 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO Setting affinity for GPU 2 to 03ffffff,ffffffff,ffffffff
|
| 158 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO NVLS multicast support is available on dev 2
|
| 159 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO Setting affinity for GPU 5 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
|
| 160 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO Setting affinity for GPU 7 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
|
| 161 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO Setting affinity for GPU 4 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
|
| 162 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO NVLS multicast support is available on dev 5
|
| 163 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO Setting affinity for GPU 3 to 03ffffff,ffffffff,ffffffff
|
| 164 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO NVLS multicast support is available on dev 4
|
| 165 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO NVLS multicast support is available on dev 3
|
| 166 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO Setting affinity for GPU 1 to 03ffffff,ffffffff,ffffffff
|
| 167 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Setting affinity for GPU 0 to 03ffffff,ffffffff,ffffffff
|
| 168 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO NVLS multicast support is available on dev 1
|
| 169 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO Setting affinity for GPU 6 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
|
| 170 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO NVLS multicast support is available on dev 0
|
| 171 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO NVLS multicast support is available on dev 6
|
| 172 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO NVLS multicast support is available on dev 7
|
| 173 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO comm 0xb514740 rank 6 nRanks 8 nNodes 1 localRanks 8 localRank 6 MNNVL 0
|
| 174 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO comm 0xa75cfc0 rank 5 nRanks 8 nNodes 1 localRanks 8 localRank 5 MNNVL 0
|
| 175 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO comm 0xa12b740 rank 4 nRanks 8 nNodes 1 localRanks 8 localRank 4 MNNVL 0
|
| 176 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO comm 0xb803a00 rank 3 nRanks 8 nNodes 1 localRanks 8 localRank 3 MNNVL 0
|
| 177 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO comm 0x9d7a4c0 rank 2 nRanks 8 nNodes 1 localRanks 8 localRank 2 MNNVL 0
|
| 178 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO comm 0xb3a9dc0 rank 1 nRanks 8 nNodes 1 localRanks 8 localRank 1 MNNVL 0
|
| 179 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO comm 0xd973700 rank 0 nRanks 8 nNodes 1 localRanks 8 localRank 0 MNNVL 0
|
| 180 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO comm 0xb5394c0 rank 7 nRanks 8 nNodes 1 localRanks 8 localRank 7 MNNVL 0
|
| 181 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO Trees [0] 5/-1/-1->4->3 [1] 5/-1/-1->4->3 [2] 5/-1/-1->4->3 [3] 5/-1/-1->4->3 [4] 5/-1/-1->4->3 [5] 5/-1/-1->4->3 [6] 5/-1/-1->4->3 [7] 5/-1/-1->4->3 [8] 5/-1/-1->4->3 [9] 5/-1/-1->4->3 [10] 5/-1/-1->4->3 [11] 5/-1/-1->4->3 [12] 5/-1/-1->4->3 [13] 5/-1/-1->4->3 [14] 5/-1/-1->4->3 [15] 5/-1/-1->4->3 [16] 5/-1/-1->4->3 [17] 5/-1/-1->4->3 [18] 5/-1/-1->4->3 [19] 5/-1/-1->4->3 [20] 5/-1/-1->4->3 [21] 5/-1/-1->4->3 [22] 5/-1/-1->4->3 [23] 5/-1/-1->4->3
|
| 182 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO P2P Chunksize set to 524288
|
| 183 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO Trees [0] 4/-1/-1->3->2 [1] 4/-1/-1->3->2 [2] 4/-1/-1->3->2 [3] 4/-1/-1->3->2 [4] 4/-1/-1->3->2 [5] 4/-1/-1->3->2 [6] 4/-1/-1->3->2 [7] 4/-1/-1->3->2 [8] 4/-1/-1->3->2 [9] 4/-1/-1->3->2 [10] 4/-1/-1->3->2 [11] 4/-1/-1->3->2 [12] 4/-1/-1->3->2 [13] 4/-1/-1->3->2 [14] 4/-1/-1->3->2 [15] 4/-1/-1->3->2 [16] 4/-1/-1->3->2 [17] 4/-1/-1->3->2 [18] 4/-1/-1->3->2 [19] 4/-1/-1->3->2 [20] 4/-1/-1->3->2 [21] 4/-1/-1->3->2 [22] 4/-1/-1->3->2 [23] 4/-1/-1->3->2
|
| 184 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 00/24 : 0 1 2 3 4 5 6 7
|
| 185 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO Trees [0] 6/-1/-1->5->4 [1] 6/-1/-1->5->4 [2] 6/-1/-1->5->4 [3] 6/-1/-1->5->4 [4] 6/-1/-1->5->4 [5] 6/-1/-1->5->4 [6] 6/-1/-1->5->4 [7] 6/-1/-1->5->4 [8] 6/-1/-1->5->4 [9] 6/-1/-1->5->4 [10] 6/-1/-1->5->4 [11] 6/-1/-1->5->4 [12] 6/-1/-1->5->4 [13] 6/-1/-1->5->4 [14] 6/-1/-1->5->4 [15] 6/-1/-1->5->4 [16] 6/-1/-1->5->4 [17] 6/-1/-1->5->4 [18] 6/-1/-1->5->4 [19] 6/-1/-1->5->4 [20] 6/-1/-1->5->4 [21] 6/-1/-1->5->4 [22] 6/-1/-1->5->4 [23] 6/-1/-1->5->4
|
| 186 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO P2P Chunksize set to 524288
|
| 187 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO Trees [0] 7/-1/-1->6->5 [1] 7/-1/-1->6->5 [2] 7/-1/-1->6->5 [3] 7/-1/-1->6->5 [4] 7/-1/-1->6->5 [5] 7/-1/-1->6->5 [6] 7/-1/-1->6->5 [7] 7/-1/-1->6->5 [8] 7/-1/-1->6->5 [9] 7/-1/-1->6->5 [10] 7/-1/-1->6->5 [11] 7/-1/-1->6->5 [12] 7/-1/-1->6->5 [13] 7/-1/-1->6->5 [14] 7/-1/-1->6->5 [15] 7/-1/-1->6->5 [16] 7/-1/-1->6->5 [17] 7/-1/-1->6->5 [18] 7/-1/-1->6->5 [19] 7/-1/-1->6->5 [20] 7/-1/-1->6->5 [21] 7/-1/-1->6->5 [22] 7/-1/-1->6->5 [23] 7/-1/-1->6->5
|
| 188 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 01/24 : 0 1 2 3 4 5 6 7
|
| 189 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO P2P Chunksize set to 524288
|
| 190 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 02/24 : 0 1 2 3 4 5 6 7
|
| 191 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO P2P Chunksize set to 524288
|
| 192 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 03/24 : 0 1 2 3 4 5 6 7
|
| 193 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 04/24 : 0 1 2 3 4 5 6 7
|
| 194 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 05/24 : 0 1 2 3 4 5 6 7
|
| 195 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 06/24 : 0 1 2 3 4 5 6 7
|
| 196 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 07/24 : 0 1 2 3 4 5 6 7
|
| 197 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO Trees [0] 2/-1/-1->1->0 [1] 2/-1/-1->1->0 [2] 2/-1/-1->1->0 [3] 2/-1/-1->1->0 [4] 2/-1/-1->1->0 [5] 2/-1/-1->1->0 [6] 2/-1/-1->1->0 [7] 2/-1/-1->1->0 [8] 2/-1/-1->1->0 [9] 2/-1/-1->1->0 [10] 2/-1/-1->1->0 [11] 2/-1/-1->1->0 [12] 2/-1/-1->1->0 [13] 2/-1/-1->1->0 [14] 2/-1/-1->1->0 [15] 2/-1/-1->1->0 [16] 2/-1/-1->1->0 [17] 2/-1/-1->1->0 [18] 2/-1/-1->1->0 [19] 2/-1/-1->1->0 [20] 2/-1/-1->1->0 [21] 2/-1/-1->1->0 [22] 2/-1/-1->1->0 [23] 2/-1/-1->1->0
|
| 198 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO Trees [0] 3/-1/-1->2->1 [1] 3/-1/-1->2->1 [2] 3/-1/-1->2->1 [3] 3/-1/-1->2->1 [4] 3/-1/-1->2->1 [5] 3/-1/-1->2->1 [6] 3/-1/-1->2->1 [7] 3/-1/-1->2->1 [8] 3/-1/-1->2->1 [9] 3/-1/-1->2->1 [10] 3/-1/-1->2->1 [11] 3/-1/-1->2->1 [12] 3/-1/-1->2->1 [13] 3/-1/-1->2->1 [14] 3/-1/-1->2->1 [15] 3/-1/-1->2->1 [16] 3/-1/-1->2->1 [17] 3/-1/-1->2->1 [18] 3/-1/-1->2->1 [19] 3/-1/-1->2->1 [20] 3/-1/-1->2->1 [21] 3/-1/-1->2->1 [22] 3/-1/-1->2->1 [23] 3/-1/-1->2->1
|
| 199 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO Trees [0] -1/-1/-1->7->6 [1] -1/-1/-1->7->6 [2] -1/-1/-1->7->6 [3] -1/-1/-1->7->6 [4] -1/-1/-1->7->6 [5] -1/-1/-1->7->6 [6] -1/-1/-1->7->6 [7] -1/-1/-1->7->6 [8] -1/-1/-1->7->6 [9] -1/-1/-1->7->6 [10] -1/-1/-1->7->6 [11] -1/-1/-1->7->6 [12] -1/-1/-1->7->6 [13] -1/-1/-1->7->6 [14] -1/-1/-1->7->6 [15] -1/-1/-1->7->6 [16] -1/-1/-1->7->6 [17] -1/-1/-1->7->6 [18] -1/-1/-1->7->6 [19] -1/-1/-1->7->6 [20] -1/-1/-1->7->6 [21] -1/-1/-1->7->6 [22] -1/-1/-1->7->6 [23] -1/-1/-1->7->6
|
| 200 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 08/24 : 0 1 2 3 4 5 6 7
|
| 201 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO P2P Chunksize set to 524288
|
| 202 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO P2P Chunksize set to 524288
|
| 203 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 09/24 : 0 1 2 3 4 5 6 7
|
| 204 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO P2P Chunksize set to 524288
|
| 205 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 10/24 : 0 1 2 3 4 5 6 7
|
| 206 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 11/24 : 0 1 2 3 4 5 6 7
|
| 207 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 12/24 : 0 1 2 3 4 5 6 7
|
| 208 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 13/24 : 0 1 2 3 4 5 6 7
|
| 209 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 14/24 : 0 1 2 3 4 5 6 7
|
| 210 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 15/24 : 0 1 2 3 4 5 6 7
|
| 211 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 16/24 : 0 1 2 3 4 5 6 7
|
| 212 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 17/24 : 0 1 2 3 4 5 6 7
|
| 213 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 18/24 : 0 1 2 3 4 5 6 7
|
| 214 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 19/24 : 0 1 2 3 4 5 6 7
|
| 215 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 20/24 : 0 1 2 3 4 5 6 7
|
| 216 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 21/24 : 0 1 2 3 4 5 6 7
|
| 217 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 22/24 : 0 1 2 3 4 5 6 7
|
| 218 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Channel 23/24 : 0 1 2 3 4 5 6 7
|
| 219 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Trees [0] 1/-1/-1->0->-1 [1] 1/-1/-1->0->-1 [2] 1/-1/-1->0->-1 [3] 1/-1/-1->0->-1 [4] 1/-1/-1->0->-1 [5] 1/-1/-1->0->-1 [6] 1/-1/-1->0->-1 [7] 1/-1/-1->0->-1 [8] 1/-1/-1->0->-1 [9] 1/-1/-1->0->-1 [10] 1/-1/-1->0->-1 [11] 1/-1/-1->0->-1 [12] 1/-1/-1->0->-1 [13] 1/-1/-1->0->-1 [14] 1/-1/-1->0->-1 [15] 1/-1/-1->0->-1 [16] 1/-1/-1->0->-1 [17] 1/-1/-1->0->-1 [18] 1/-1/-1->0->-1 [19] 1/-1/-1->0->-1 [20] 1/-1/-1->0->-1 [21] 1/-1/-1->0->-1 [22] 1/-1/-1->0->-1 [23] 1/-1/-1->0->-1
|
| 220 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO P2P Chunksize set to 524288
|
| 221 |
+
t-20260524091317-xb65t-worker-0:10329:10476 [5] NCCL INFO [Proxy Service] Device 5 CPU core 94
|
| 222 |
+
t-20260524091317-xb65t-worker-0:10329:10477 [5] NCCL INFO [Proxy Service UDS] Device 5 CPU core 96
|
| 223 |
+
t-20260524091317-xb65t-worker-0:10327:10478 [3] NCCL INFO [Proxy Service] Device 3 CPU core 14
|
| 224 |
+
t-20260524091317-xb65t-worker-0:10327:10479 [3] NCCL INFO [Proxy Service UDS] Device 3 CPU core 18
|
| 225 |
+
t-20260524091317-xb65t-worker-0:10328:10480 [4] NCCL INFO [Proxy Service] Device 4 CPU core 168
|
| 226 |
+
t-20260524091317-xb65t-worker-0:10330:10482 [6] NCCL INFO [Proxy Service] Device 6 CPU core 96
|
| 227 |
+
t-20260524091317-xb65t-worker-0:10328:10481 [4] NCCL INFO [Proxy Service UDS] Device 4 CPU core 172
|
| 228 |
+
t-20260524091317-xb65t-worker-0:10330:10483 [6] NCCL INFO [Proxy Service UDS] Device 6 CPU core 94
|
| 229 |
+
t-20260524091317-xb65t-worker-0:10325:10484 [1] NCCL INFO [Proxy Service] Device 1 CPU core 2
|
| 230 |
+
t-20260524091317-xb65t-worker-0:10325:10485 [1] NCCL INFO [Proxy Service UDS] Device 1 CPU core 4
|
| 231 |
+
t-20260524091317-xb65t-worker-0:10331:10486 [7] NCCL INFO [Proxy Service] Device 7 CPU core 94
|
| 232 |
+
t-20260524091317-xb65t-worker-0:10331:10487 [7] NCCL INFO [Proxy Service UDS] Device 7 CPU core 96
|
| 233 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Check P2P Type intraNodeP2pSupport 1 directMode 0
|
| 234 |
+
t-20260524091317-xb65t-worker-0:10324:10488 [0] NCCL INFO [Proxy Service] Device 0 CPU core 22
|
| 235 |
+
t-20260524091317-xb65t-worker-0:10326:10489 [2] NCCL INFO [Proxy Service] Device 2 CPU core 2
|
| 236 |
+
t-20260524091317-xb65t-worker-0:10324:10490 [0] NCCL INFO [Proxy Service UDS] Device 0 CPU core 18
|
| 237 |
+
t-20260524091317-xb65t-worker-0:10326:10491 [2] NCCL INFO [Proxy Service UDS] Device 2 CPU core 4
|
| 238 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
|
| 239 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
|
| 240 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
|
| 241 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
|
| 242 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
|
| 243 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
|
| 244 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
|
| 245 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
|
| 246 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
|
| 247 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
|
| 248 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
|
| 249 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
|
| 250 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
|
| 251 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
|
| 252 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
|
| 253 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
|
| 254 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO CC Off, workFifoBytes 1048576
|
| 255 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
|
| 256 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
|
| 257 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
|
| 258 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
|
| 259 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
|
| 260 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
|
| 261 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
|
| 262 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
|
| 263 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
|
| 264 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
|
| 265 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
|
| 266 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
|
| 267 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
|
| 268 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
|
| 269 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
|
| 270 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
|
| 271 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
|
| 272 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO ncclCommInitRankConfig comm 0xb803a00 rank 3 nranks 8 cudaDev 3 nvmlDev 3 busId 6b020 commId 0xe94542814597d064 - Init COMPLETE
|
| 273 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
|
| 274 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
|
| 275 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
|
| 276 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
|
| 277 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO ncclCommInitRankConfig comm 0xa12b740 rank 4 nranks 8 cudaDev 4 nvmlDev 4 busId 6f020 commId 0xe94542814597d064 - Init COMPLETE
|
| 278 |
+
t-20260524091317-xb65t-worker-0:10327:10400 [3] NCCL INFO Init timings - ncclCommInitRankConfig: rank 3 nranks 8 total 2.14 (kernels 0.22, alloc 0.90, bootstrap 0.03, allgathers 0.01, topo 0.54, graphs 0.01, connections 0.41, rest 0.02)
|
| 279 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
|
| 280 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
|
| 281 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
|
| 282 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO ncclCommInitRankConfig comm 0xb5394c0 rank 7 nranks 8 cudaDev 7 nvmlDev 7 busId 75020 commId 0xe94542814597d064 - Init COMPLETE
|
| 283 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO ncclCommInitRankConfig comm 0xa75cfc0 rank 5 nranks 8 cudaDev 5 nvmlDev 5 busId 71020 commId 0xe94542814597d064 - Init COMPLETE
|
| 284 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO ncclCommInitRankConfig comm 0x9d7a4c0 rank 2 nranks 8 cudaDev 2 nvmlDev 2 busId 69020 commId 0xe94542814597d064 - Init COMPLETE
|
| 285 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO ncclCommInitRankConfig comm 0xb3a9dc0 rank 1 nranks 8 cudaDev 1 nvmlDev 1 busId 67020 commId 0xe94542814597d064 - Init COMPLETE
|
| 286 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO ncclCommInitRankConfig comm 0xd973700 rank 0 nranks 8 cudaDev 0 nvmlDev 0 busId 65040 commId 0xe94542814597d064 - Init COMPLETE
|
| 287 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO ncclCommInitRankConfig comm 0xb514740 rank 6 nranks 8 cudaDev 6 nvmlDev 6 busId 73020 commId 0xe94542814597d064 - Init COMPLETE
|
| 288 |
+
t-20260524091317-xb65t-worker-0:10328:10401 [4] NCCL INFO Init timings - ncclCommInitRankConfig: rank 4 nranks 8 total 2.13 (kernels 0.22, alloc 0.91, bootstrap 0.01, allgathers 0.01, topo 0.54, graphs 0.01, connections 0.41, rest 0.03)
|
| 289 |
+
t-20260524091317-xb65t-worker-0:10331:10408 [7] NCCL INFO Init timings - ncclCommInitRankConfig: rank 7 nranks 8 total 2.11 (kernels 0.22, alloc 0.90, bootstrap 0.00, allgathers 0.00, topo 0.54, graphs 0.01, connections 0.41, rest 0.03)
|
| 290 |
+
t-20260524091317-xb65t-worker-0:10329:10398 [5] NCCL INFO Init timings - ncclCommInitRankConfig: rank 5 nranks 8 total 2.15 (kernels 0.23, alloc 0.91, bootstrap 0.01, allgathers 0.00, topo 0.54, graphs 0.01, connections 0.42, rest 0.02)
|
| 291 |
+
t-20260524091317-xb65t-worker-0:10324:10396 [0] NCCL INFO Init timings - ncclCommInitRankConfig: rank 0 nranks 8 total 2.36 (kernels 0.21, alloc 0.20, bootstrap 0.96, allgathers 0.01, topo 0.54, graphs 0.01, connections 0.41, rest 0.03)
|
| 292 |
+
t-20260524091317-xb65t-worker-0:10325:10397 [1] NCCL INFO Init timings - ncclCommInitRankConfig: rank 1 nranks 8 total 2.20 (kernels 0.27, alloc 0.84, bootstrap 0.11, allgathers 0.00, topo 0.54, graphs 0.01, connections 0.41, rest 0.03)
|
| 293 |
+
t-20260524091317-xb65t-worker-0:10326:10406 [2] NCCL INFO Init timings - ncclCommInitRankConfig: rank 2 nranks 8 total 2.12 (kernels 0.22, alloc 0.91, bootstrap 0.00, allgathers 0.00, topo 0.54, graphs 0.01, connections 0.41, rest 0.03)
|
| 294 |
+
t-20260524091317-xb65t-worker-0:10330:10404 [6] NCCL INFO Init timings - ncclCommInitRankConfig: rank 6 nranks 8 total 2.13 (kernels 0.22, alloc 0.91, bootstrap 0.01, allgathers 0.00, topo 0.54, graphs 0.01, connections 0.41, rest 0.03)
|
| 295 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 00/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 296 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 00/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 297 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 00/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 298 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 01/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 299 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 00/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 300 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 01/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 301 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 01/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 302 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 02/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 303 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 01/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 304 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 02/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 305 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 02/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 306 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 03/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 307 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 02/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 308 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 03/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 309 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 04/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 310 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 05/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 311 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 00/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 312 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 06/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 313 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 01/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 314 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 07/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 315 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 02/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 316 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 08/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 317 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 03/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 318 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 09/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 319 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 04/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 320 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 10/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 321 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 05/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 322 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 11/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 323 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 06/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 324 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 12/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 325 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 07/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 326 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 03/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 327 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 13/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 328 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 03/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 329 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 04/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 330 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 00/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 331 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 08/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 332 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 04/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 333 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 14/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 334 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 04/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 335 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 05/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 336 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 01/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 337 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 09/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 338 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 05/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 339 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 15/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 340 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 05/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 341 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 06/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 342 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 02/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 343 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 10/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 344 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 06/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 345 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 16/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 346 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 06/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 347 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 07/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 348 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 03/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 349 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 00/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 350 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 04/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 351 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 11/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 352 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 00/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 353 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 01/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 354 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 05/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 355 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 12/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 356 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 01/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 357 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 02/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 358 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 06/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 359 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 13/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 360 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 02/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 361 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 07/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 362 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 03/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 363 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 07/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 364 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 14/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 365 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 03/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 366 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 08/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 367 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 04/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 368 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 08/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 369 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 15/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 370 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 04/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 371 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 09/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 372 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 05/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 373 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 09/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 374 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 16/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 375 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 05/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 376 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 10/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 377 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 06/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 378 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 10/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 379 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 17/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 380 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 17/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 381 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 07/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 382 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 06/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 383 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 08/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 384 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 11/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 385 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 07/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 386 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 11/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 387 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 18/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 388 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 18/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 389 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 08/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 390 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 07/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 391 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 09/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 392 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 12/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 393 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 08/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 394 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 12/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 395 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 19/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 396 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 19/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 397 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 09/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 398 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 08/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 399 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 10/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 400 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 13/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 401 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 09/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 402 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 13/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 403 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 20/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 404 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 20/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 405 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 10/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 406 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 09/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 407 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 11/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 408 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 14/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 409 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 10/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 410 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 14/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 411 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 21/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 412 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 21/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 413 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 11/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 414 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 10/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 415 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 12/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 416 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 15/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 417 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 11/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 418 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 15/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 419 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 22/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 420 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 22/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 421 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 12/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 422 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 11/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 423 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 13/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 424 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 16/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 425 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 12/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 426 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 16/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 427 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Channel 23/0 : 4[4] -> 5[5] via P2P/CUMEM
|
| 428 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Channel 23/0 : 2[2] -> 3[3] via P2P/CUMEM
|
| 429 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 13/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 430 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 12/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 431 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 14/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 432 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 17/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 433 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 13/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 434 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 17/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 435 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 14/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 436 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 13/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 437 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 15/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 438 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 18/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 439 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 14/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 440 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 18/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 441 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 15/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 442 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 19/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 443 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 14/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 444 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 16/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 445 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 15/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 446 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 19/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 447 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 16/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 448 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 20/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 449 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 15/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 450 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 17/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 451 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 16/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 452 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 20/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 453 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 17/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 454 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 21/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 455 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 16/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 456 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 18/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 457 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 17/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 458 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 21/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 459 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 18/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 460 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 22/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 461 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 17/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 462 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 19/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 463 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 18/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 464 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 22/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 465 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 19/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 466 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Channel 23/0 : 3[3] -> 4[4] via P2P/CUMEM
|
| 467 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 18/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 468 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 20/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 469 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 19/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 470 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Channel 23/0 : 7[7] -> 0[0] via P2P/CUMEM
|
| 471 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 19/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 472 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 20/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 473 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 21/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 474 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 20/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 475 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 21/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 476 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 22/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 477 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 20/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 478 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 22/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 479 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 21/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 480 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Channel 23/0 : 5[5] -> 6[6] via P2P/CUMEM
|
| 481 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 21/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 482 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Channel 23/0 : 6[6] -> 7[7] via P2P/CUMEM
|
| 483 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 22/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 484 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 22/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 485 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Channel 23/0 : 0[0] -> 1[1] via P2P/CUMEM
|
| 486 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Channel 23/0 : 1[1] -> 2[2] via P2P/CUMEM
|
| 487 |
+
t-20260524091317-xb65t-worker-0:10330:10497 [6] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
|
| 488 |
+
t-20260524091317-xb65t-worker-0:10331:10499 [7] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
|
| 489 |
+
t-20260524091317-xb65t-worker-0:10329:10492 [5] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
|
| 490 |
+
t-20260524091317-xb65t-worker-0:10325:10498 [1] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
|
| 491 |
+
t-20260524091317-xb65t-worker-0:10326:10495 [2] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
|
| 492 |
+
t-20260524091317-xb65t-worker-0:10327:10493 [3] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
|
| 493 |
+
t-20260524091317-xb65t-worker-0:10324:10494 [0] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
|
| 494 |
+
t-20260524091317-xb65t-worker-0:10328:10496 [4] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
|
| 495 |
+
{
|
| 496 |
+
"device": "cuda:0",
|
| 497 |
+
"rank": 0,
|
| 498 |
+
"world_size": 8,
|
| 499 |
+
"samples": "wrapped_stream",
|
| 500 |
+
"vocab_size": 30522,
|
| 501 |
+
"tokenizer_vocab_size": 30522,
|
| 502 |
+
"save_dir": "runs/lta_lm1b_dirichlet_len1024_Cv_to_2v_gbs512_8gpu_20k_save1k_gumbelwatch_20260524",
|
| 503 |
+
"max_len": 1024,
|
| 504 |
+
"effective_model_max_len": 1024,
|
| 505 |
+
"batch_size": 2,
|
| 506 |
+
"grad_accum": 32,
|
| 507 |
+
"effective_batch_size": 512,
|
| 508 |
+
"global_batch_size": 512,
|
| 509 |
+
"lr_schedule": "constant_warmup",
|
| 510 |
+
"optimizer": "adamw",
|
| 511 |
+
"epochs": 0.0,
|
| 512 |
+
"steps_per_epoch": 0,
|
| 513 |
+
"total_steps": 20000,
|
| 514 |
+
"warmup_steps": 2500,
|
| 515 |
+
"warmup_epochs": -1.0,
|
| 516 |
+
"min_lr": 6e-05,
|
| 517 |
+
"weight_decay": 0.0,
|
| 518 |
+
"output_weight_decay": -1.0,
|
| 519 |
+
"adamw_param_groups": "nanogpt",
|
| 520 |
+
"adam_beta1": 0.9,
|
| 521 |
+
"adam_beta2": 0.999,
|
| 522 |
+
"adam_eps": 1e-08,
|
| 523 |
+
"muon_impl": "legacy",
|
| 524 |
+
"muon_momentum": 0.95,
|
| 525 |
+
"muon_ns_steps": 5,
|
| 526 |
+
"muon_update_scale": 1.0,
|
| 527 |
+
"muon_nesterov": false,
|
| 528 |
+
"muon_width_scale": false,
|
| 529 |
+
"muon_grouping": "",
|
| 530 |
+
"muon_param_count": 0,
|
| 531 |
+
"muon_adam_param_count": 0,
|
| 532 |
+
"muon_param_names": [],
|
| 533 |
+
"muon_adam_param_names": [],
|
| 534 |
+
"muon_effective_nesterov": false,
|
| 535 |
+
"muon_effective_width_scale": false,
|
| 536 |
+
"muon_effective_weight_decay": 0.0,
|
| 537 |
+
"muon_adam_fallback_nesterov": false,
|
| 538 |
+
"muon_adam_fallback_weight_decay": 0.0,
|
| 539 |
+
"ema_decay": 0.0,
|
| 540 |
+
"ema_start_step": 0,
|
| 541 |
+
"model_type": "ddit",
|
| 542 |
+
"ddit_mlp_type": "gelu",
|
| 543 |
+
"block_anchor_every": 0,
|
| 544 |
+
"block_anchor_init_std": 0.02,
|
| 545 |
+
"bos_anchor_every": 0,
|
| 546 |
+
"bos_anchor_token_id": -1,
|
| 547 |
+
"bos_anchor_extra_len": 0,
|
| 548 |
+
"abs_pos_embed": false,
|
| 549 |
+
"abs_pos_init_std": 0.02,
|
| 550 |
+
"elf_num_time_tokens": 4,
|
| 551 |
+
"elf_num_model_mode_tokens": 0,
|
| 552 |
+
"qk_norm": true,
|
| 553 |
+
"output_bias": false,
|
| 554 |
+
"output_init_std": -1.0,
|
| 555 |
+
"norm_type": "rmsnorm",
|
| 556 |
+
"target_loss": "hard_ce",
|
| 557 |
+
"linear_soft_target_power": 1.0,
|
| 558 |
+
"linear_soft_target_min_conf": 0.0,
|
| 559 |
+
"linear_soft_target_max_conf": 1.0,
|
| 560 |
+
"t_sampling_mode": "uniform",
|
| 561 |
+
"t_sampling_power": 1.0,
|
| 562 |
+
"t_sampling_eps": 0.0001,
|
| 563 |
+
"t_sampling_logit_mean": -1.5,
|
| 564 |
+
"t_sampling_logit_std": 0.8,
|
| 565 |
+
"t_sampling_gumbel_loc": 2.2,
|
| 566 |
+
"t_sampling_gumbel_scale": 0.8,
|
| 567 |
+
"dual_t": true,
|
| 568 |
+
"corrupt_t_mode": "independent",
|
| 569 |
+
"corrupt_min_t": 0.0,
|
| 570 |
+
"corrupt_max_t": 1.0,
|
| 571 |
+
"prefix_block_prob": 0.0,
|
| 572 |
+
"prefix_block_len": 128,
|
| 573 |
+
"block_ar_two_stream": false,
|
| 574 |
+
"block_ar_block_len": 128,
|
| 575 |
+
"mask_ratio_floor_schedule": "none",
|
| 576 |
+
"dirichlet_endpoint_mode": "categorical_dual_t",
|
| 577 |
+
"dirichlet_semantic_t_mode": "same",
|
| 578 |
+
"dirichlet_semantic_t_value": 0.0,
|
| 579 |
+
"dirichlet_semantic_t_curve": "linear",
|
| 580 |
+
"dirichlet_semantic_t_power": 1.0,
|
| 581 |
+
"dirichlet_support_t_curve": "linear",
|
| 582 |
+
"dirichlet_support_t_power": 1.0,
|
| 583 |
+
"endpoint_sequence_random_prob_alpha": 0.0,
|
| 584 |
+
"categorical_wrong_from_full_vocab": true,
|
| 585 |
+
"categorical_wrong_from_batch_valid_tokens": false,
|
| 586 |
+
"categorical_wrong_basin_token_ids": "",
|
| 587 |
+
"categorical_wrong_basin_prob": 0.0,
|
| 588 |
+
"categorical_wrong_unigram_prob": 0.0,
|
| 589 |
+
"categorical_wrong_uniform_prob": 0.0,
|
| 590 |
+
"categorical_wrong_prob_floor": 0.0,
|
| 591 |
+
"categorical_gold_prob_floor": 0.0,
|
| 592 |
+
"categorical_gold_prob_ceil": 1.0,
|
| 593 |
+
"categorical_wrong_corpus_unigram_path": "",
|
| 594 |
+
"categorical_wrong_corpus_unigram_alpha": 1.0,
|
| 595 |
+
"categorical_wrong_basin_shared_prob": 0.0,
|
| 596 |
+
"categorical_wrong_unigram_shared_prob": 0.0,
|
| 597 |
+
"mask_mixture_original_prob": 0.0,
|
| 598 |
+
"mask_mixture_lowk_prob": 0.0,
|
| 599 |
+
"mask_mixture_lowcorrupt_prob": 0.0,
|
| 600 |
+
"mask_mixture_block_prob": 0.0,
|
| 601 |
+
"mask_mixture_all_prob": 0.0,
|
| 602 |
+
"mask_mixture_lowk_clean_tokens": "1,2,4,8,16,32,64",
|
| 603 |
+
"mask_mixture_lowcorrupt_tokens": "1,2,4,8,16,32,64",
|
| 604 |
+
"mask_mixture_block_tokens": "64,128",
|
| 605 |
+
"simplex_bridge_sampler": "dirichlet",
|
| 606 |
+
"logistic_normal_sigma_min": 0.18,
|
| 607 |
+
"logistic_normal_sigma_max": 2.2,
|
| 608 |
+
"logistic_normal_tau_min": 0.65,
|
| 609 |
+
"logistic_normal_tau_max": 1.15,
|
| 610 |
+
"torch_compile": false,
|
| 611 |
+
"compile_mode": "max-autotune",
|
| 612 |
+
"state_format": "prob",
|
| 613 |
+
"meanflow_weight": 0.0,
|
| 614 |
+
"rollout_train_prob": 0.0,
|
| 615 |
+
"rollout_train_steps": 1,
|
| 616 |
+
"rollout_train_steps_min": -1,
|
| 617 |
+
"rollout_train_infer_steps": 64,
|
| 618 |
+
"rollout_train_time_mode": "fixed_steps",
|
| 619 |
+
"rollout_train_s_dist": "uniform",
|
| 620 |
+
"rollout_train_s_min_frac": 0.0,
|
| 621 |
+
"rollout_train_s_max_frac": 0.125,
|
| 622 |
+
"rollout_train_s_beta_alpha": 2.0,
|
| 623 |
+
"rollout_train_s_beta_beta": 6.0,
|
| 624 |
+
"rollout_train_temp": 1.0,
|
| 625 |
+
"rollout_train_max_gamma": 1.0,
|
| 626 |
+
"rollout_train_rule": "flowmap",
|
| 627 |
+
"rollout_train_corrupt_only": true,
|
| 628 |
+
"rollout_train_samplewise": false,
|
| 629 |
+
"rollout_train_compute_always": false,
|
| 630 |
+
"rollout_train_keep_grad": false,
|
| 631 |
+
"rollout_train_sync_t": false,
|
| 632 |
+
"rollout_train_state_mix_mode": "final",
|
| 633 |
+
"rollout_train_state_mix_alpha": 0.5,
|
| 634 |
+
"bridge_noise_init": "logistic_normal",
|
| 635 |
+
"noise_sigma": -1.0,
|
| 636 |
+
"allow_tf32": true,
|
| 637 |
+
"activation_checkpointing": false,
|
| 638 |
+
"activation_checkpoint_interval": 1,
|
| 639 |
+
"activation_checkpoint_scope": "block",
|
| 640 |
+
"ddp_static_graph": false,
|
| 641 |
+
"ddp_gradient_as_bucket_view": true,
|
| 642 |
+
"blocking_data_transfer": false,
|
| 643 |
+
"dataloader_prefetch_factor": 2,
|
| 644 |
+
"full_train_stats": false,
|
| 645 |
+
"tokenized_hf": false,
|
| 646 |
+
"tokenized_pad_token": "pad",
|
| 647 |
+
"elf_conditional_hf": false,
|
| 648 |
+
"record_pad_truncate": false,
|
| 649 |
+
"record_add_eos": false,
|
| 650 |
+
"record_add_special_tokens": false,
|
| 651 |
+
"record_pad_token": "pad",
|
| 652 |
+
"record_shuffle_buffer": 10000,
|
| 653 |
+
"wrap": true,
|
| 654 |
+
"wrap_mode": "stream",
|
| 655 |
+
"wrap_record_buffer_size": 200,
|
| 656 |
+
"owt_cached_chunks": false,
|
| 657 |
+
"owt_chunk_cache_dir": "",
|
| 658 |
+
"owt_chunk_cache_rebuild": false,
|
| 659 |
+
"owt_chunk_cache_write_batch": 4096,
|
| 660 |
+
"owt_exact_repeat_per_chunk": 0,
|
| 661 |
+
"online_chunk_shuffle": false,
|
| 662 |
+
"online_chunk_shuffle_buffer": 10000,
|
| 663 |
+
"openwebtext_split": "all",
|
| 664 |
+
"detokenizer": "auto",
|
| 665 |
+
"resolved_detokenizer": "lm1b",
|
| 666 |
+
"num_workers": 0,
|
| 667 |
+
"latest_every": 1000,
|
| 668 |
+
"resume_path": ""
|
| 669 |
+
}
|
| 670 |
+
t-20260524091317-xb65t-worker-0:10324:10604 [0] NCCL INFO NVLS comm 0xd973700 headRank 0 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
|
| 671 |
+
t-20260524091317-xb65t-worker-0:10325:10605 [1] NCCL INFO NVLS comm 0xb3a9dc0 headRank 1 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
|
| 672 |
+
t-20260524091317-xb65t-worker-0:10326:10606 [2] NCCL INFO NVLS comm 0x9d7a4c0 headRank 2 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
|
| 673 |
+
t-20260524091317-xb65t-worker-0:10328:10607 [4] NCCL INFO NVLS comm 0xa12b740 headRank 4 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
|
| 674 |
+
t-20260524091317-xb65t-worker-0:10327:10608 [3] NCCL INFO NVLS comm 0xb803a00 headRank 3 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
|
| 675 |
+
t-20260524091317-xb65t-worker-0:10329:10609 [5] NCCL INFO NVLS comm 0xa75cfc0 headRank 5 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
|
| 676 |
+
t-20260524091317-xb65t-worker-0:10330:10610 [6] NCCL INFO NVLS comm 0xb514740 headRank 6 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
|
| 677 |
+
t-20260524091317-xb65t-worker-0:10331:10611 [7] NCCL INFO NVLS comm 0xb5394c0 headRank 7 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
|
| 678 |
+
step=100 micro_steps=3200 elapsed=170.6s lr=1.212000e-05 loss=10.1456 loss_recon=10.1456 loss_meanflow=0.0000 mean_model_t=0.4981 mean_corrupt_t=0.4994 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.5713 corrupt_frac=0.5504 acc_corrupt=0.3807 loss_corrupt=10.1456 wrong_frac=0.5012 init_acc_corrupt=0.4988 acc_corrupt_t_0p0_0p2=0.0791 corrupt_frac_t_0p0_0p2=0.5561 acc_corrupt_t_0p6_0p8=0.5293 corrupt_frac_t_0p6_0p8=0.5521 out_w_norm=1.0058 out_g_norm=1.0429 acc_corrupt_t_0p2_0p4=0.2091 corrupt_frac_t_0p2_0p4=0.5638 acc_corrupt_t_0p8_1p0=0.7259 corrupt_frac_t_0p8_1p0=0.5535 acc_corrupt_t_0p4_0p6=0.3628 corrupt_frac_t_0p4_0p6=0.5436 loss_all=9.6693 init_gold_top10=0.5832 init_gold_top100=0.5832
|
| 679 |
+
step=200 micro_steps=6400 elapsed=165.6s lr=2.412000e-05 loss=8.8510 loss_recon=8.8510 loss_meanflow=0.0000 mean_model_t=0.5027 mean_corrupt_t=0.4912 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.1270 corrupt_frac=0.5485 acc_corrupt=0.0923 loss_corrupt=8.8510 wrong_frac=0.5090 init_acc_corrupt=0.4910 acc_corrupt_t_0p6_0p8=0.1149 corrupt_frac_t_0p6_0p8=0.5704 acc_corrupt_t_0p8_1p0=0.1501 corrupt_frac_t_0p8_1p0=0.5525 out_w_norm=6.9327 out_g_norm=1.5119 acc_corrupt_t_0p0_0p2=0.0460 corrupt_frac_t_0p0_0p2=0.5588 acc_corrupt_t_0p4_0p6=0.0890 corrupt_frac_t_0p4_0p6=0.5557 acc_corrupt_t_0p2_0p4=0.0667 corrupt_frac_t_0p2_0p4=0.5525 loss_all=7.9347 init_gold_top10=0.3662 init_gold_top100=0.3662
|
| 680 |
+
step=300 micro_steps=9600 elapsed=169.5s lr=3.612000e-05 loss=6.9617 loss_recon=6.9617 loss_meanflow=0.0000 mean_model_t=0.5020 mean_corrupt_t=0.4988 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.1500 corrupt_frac=0.5494 acc_corrupt=0.1156 loss_corrupt=6.9617 wrong_frac=0.5005 init_acc_corrupt=0.4996 acc_corrupt_t_0p6_0p8=0.1446 corrupt_frac_t_0p6_0p8=0.5593 out_w_norm=13.3103 out_g_norm=1.1168 acc_corrupt_t_0p2_0p4=0.0853 corrupt_frac_t_0p2_0p4=0.5636 acc_corrupt_t_0p8_1p0=0.1791 corrupt_frac_t_0p8_1p0=0.5610 acc_corrupt_t_0p4_0p6=0.1135 corrupt_frac_t_0p4_0p6=0.5426 acc_corrupt_t_0p0_0p2=0.0557 corrupt_frac_t_0p0_0p2=0.5508 loss_all=5.0093 init_gold_top10=0.5300 init_gold_top100=0.5309
|
| 681 |
+
step=400 micro_steps=12800 elapsed=173.6s lr=4.812000e-05 loss=4.3888 loss_recon=4.3888 loss_meanflow=0.0000 mean_model_t=0.4947 mean_corrupt_t=0.4990 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.6375 corrupt_frac=0.5480 acc_corrupt=0.4451 loss_corrupt=4.3888 wrong_frac=0.5022 init_acc_corrupt=0.4978 acc_corrupt_t_0p0_0p2=0.1092 corrupt_frac_t_0p0_0p2=0.5475 out_w_norm=18.9742 out_g_norm=0.4668 acc_corrupt_t_0p6_0p8=0.6186 corrupt_frac_t_0p6_0p8=0.5556 acc_corrupt_t_0p8_1p0=0.7924 corrupt_frac_t_0p8_1p0=0.5553 acc_corrupt_t_0p4_0p6=0.4457 corrupt_frac_t_0p4_0p6=0.5529 acc_corrupt_t_0p2_0p4=0.2734 corrupt_frac_t_0p2_0p4=0.5768 loss_all=3.0366 init_gold_top10=0.2575 init_gold_top100=0.2605
|
| 682 |
+
step=500 micro_steps=16000 elapsed=172.9s lr=6.012000e-05 loss=3.8340 loss_recon=3.8340 loss_meanflow=0.0000 mean_model_t=0.4983 mean_corrupt_t=0.5041 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.7222 corrupt_frac=0.5470 acc_corrupt=0.5047 loss_corrupt=3.8340 wrong_frac=0.4975 init_acc_corrupt=0.5025 acc_corrupt_t_0p4_0p6=0.4986 corrupt_frac_t_0p4_0p6=0.5556 acc_corrupt_t_0p8_1p0=0.8904 corrupt_frac_t_0p8_1p0=0.5599 out_w_norm=22.4888 out_g_norm=0.3746 acc_corrupt_t_0p2_0p4=0.3076 corrupt_frac_t_0p2_0p4=0.5515 acc_corrupt_t_0p6_0p8=0.6927 corrupt_frac_t_0p6_0p8=0.5543 acc_corrupt_t_0p0_0p2=0.1224 corrupt_frac_t_0p0_0p2=0.5550 loss_all=2.7828 init_gold_top10=0.2262 init_gold_top100=0.2303
|
| 683 |
+
step=600 micro_steps=19200 elapsed=167.3s lr=7.212000e-05 loss=3.7715 loss_recon=3.7715 loss_meanflow=0.0000 mean_model_t=0.5091 mean_corrupt_t=0.5016 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.7281 corrupt_frac=0.5560 acc_corrupt=0.5141 loss_corrupt=3.7715 wrong_frac=0.4967 init_acc_corrupt=0.5033 acc_corrupt_t_0p2_0p4=0.3151 corrupt_frac_t_0p2_0p4=0.5598 acc_corrupt_t_0p8_1p0=0.8966 corrupt_frac_t_0p8_1p0=0.5597 out_w_norm=24.2086 out_g_norm=0.4152 acc_corrupt_t_0p0_0p2=0.1330 corrupt_frac_t_0p0_0p2=0.5436 acc_corrupt_t_0p6_0p8=0.7071 corrupt_frac_t_0p6_0p8=0.5590 acc_corrupt_t_0p4_0p6=0.5077 corrupt_frac_t_0p4_0p6=0.5540 loss_all=2.5931 init_gold_top10=0.3047 init_gold_top100=0.3067
|
| 684 |
+
step=700 micro_steps=22400 elapsed=171.0s lr=8.412000e-05 loss=3.6355 loss_recon=3.6355 loss_meanflow=0.0000 mean_model_t=0.4975 mean_corrupt_t=0.5052 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.7413 corrupt_frac=0.5475 acc_corrupt=0.5296 loss_corrupt=3.6355 wrong_frac=0.4965 init_acc_corrupt=0.5035 acc_corrupt_t_0p8_1p0=0.9016 corrupt_frac_t_0p8_1p0=0.5505 out_w_norm=25.3922 out_g_norm=0.4602 acc_corrupt_t_0p2_0p4=0.3379 corrupt_frac_t_0p2_0p4=0.5590 acc_corrupt_t_0p4_0p6=0.5255 corrupt_frac_t_0p4_0p6=0.5618 acc_corrupt_t_0p0_0p2=0.1564 corrupt_frac_t_0p0_0p2=0.5508 acc_corrupt_t_0p6_0p8=0.7125 corrupt_frac_t_0p6_0p8=0.5485 loss_all=0.9812 init_gold_top10=0.7266 init_gold_top100=0.7276
|
| 685 |
+
step=800 micro_steps=25600 elapsed=173.0s lr=9.612000e-05 loss=3.4932 loss_recon=3.4932 loss_meanflow=0.0000 mean_model_t=0.4942 mean_corrupt_t=0.4965 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.7437 corrupt_frac=0.5486 acc_corrupt=0.5348 loss_corrupt=3.4932 wrong_frac=0.5036 init_acc_corrupt=0.4964 acc_corrupt_t_0p0_0p2=0.1709 corrupt_frac_t_0p0_0p2=0.5720 acc_corrupt_t_0p8_1p0=0.9047 corrupt_frac_t_0p8_1p0=0.5536 out_w_norm=26.5098 out_g_norm=0.5269 acc_corrupt_t_0p4_0p6=0.5399 corrupt_frac_t_0p4_0p6=0.5477 acc_corrupt_t_0p2_0p4=0.3559 corrupt_frac_t_0p2_0p4=0.5440 acc_corrupt_t_0p6_0p8=0.7240 corrupt_frac_t_0p6_0p8=0.5552 loss_all=0.2252 init_gold_top10=0.9130 init_gold_top100=0.9130
|
| 686 |
+
step=900 micro_steps=28800 elapsed=170.7s lr=1.081200e-04 loss=3.3160 loss_recon=3.3160 loss_meanflow=0.0000 mean_model_t=0.5031 mean_corrupt_t=0.5038 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.7492 corrupt_frac=0.5523 acc_corrupt=0.5479 loss_corrupt=3.3160 wrong_frac=0.4972 init_acc_corrupt=0.5028 acc_corrupt_t_0p4_0p6=0.5454 corrupt_frac_t_0p4_0p6=0.5577 out_w_norm=27.5695 out_g_norm=0.5297 acc_corrupt_t_0p2_0p4=0.3649 corrupt_frac_t_0p2_0p4=0.5480 acc_corrupt_t_0p6_0p8=0.7308 corrupt_frac_t_0p6_0p8=0.5478 acc_corrupt_t_0p8_1p0=0.9107 corrupt_frac_t_0p8_1p0=0.5578 acc_corrupt_t_0p0_0p2=0.1776 corrupt_frac_t_0p0_0p2=0.5622 loss_all=2.2426 init_gold_top10=0.6347 init_gold_top100=0.6358
|
| 687 |
+
step=1000 micro_steps=32000 elapsed=168.6s lr=1.201200e-04 loss=3.2368 loss_recon=3.2368 loss_meanflow=0.0000 mean_model_t=0.5029 mean_corrupt_t=0.4996 mean_loss_t_weight=1.0000 linear_soft_target_mean_conf=0.0000 prior_center_loss_beta=0.0000 rollout_train_applied=0.0000 grad_enabled_before_rollout=1.0000 grad_enabled_after_rollout=1.0000 logits_requires_grad=1.0000 raw_loss_requires_grad=1.0000 acc_all=0.7512 corrupt_frac=0.5516 acc_corrupt=0.5509 loss_corrupt=3.2368 wrong_frac=0.5002 init_acc_corrupt=0.4999 acc_corrupt_t_0p6_0p8=0.7338 corrupt_frac_t_0p6_0p8=0.5574 out_w_norm=28.6215 out_g_norm=0.5405 acc_corrupt_t_0p0_0p2=0.1863 corrupt_frac_t_0p0_0p2=0.5474 acc_corrupt_t_0p8_1p0=0.9104 corrupt_frac_t_0p8_1p0=0.5585 acc_corrupt_t_0p2_0p4=0.3670 corrupt_frac_t_0p2_0p4=0.5583 acc_corrupt_t_0p4_0p6=0.5536 corrupt_frac_t_0p4_0p6=0.5594 loss_all=0.7114 init_gold_top10=0.7198 init_gold_top100=0.7198
|
LTA_openwebtext_dualt/logs/lta_owt_c1024_gpt2_cached_chunks_len1024_fast10k_4gpu_500step.log
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
*****************************************
|
| 3 |
+
Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.
|
| 4 |
+
*****************************************
|
| 5 |
+
[rank0]:[W512 16:35:00.260053068 ProcessGroupNCCL.cpp:4571] [PG ID 0 PG GUID 0 Rank 0] using GPU 0 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect. Specify device_ids in barrier() to force use of a particular device, or call init_process_group() with a device_id.
|
| 6 |
+
NCCL version 2.25.1+cuda12.8
|
| 7 |
+
[rank1]:[W512 16:35:00.299852507 ProcessGroupNCCL.cpp:4571] [PG ID 0 PG GUID 0 Rank 1] using GPU 1 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect. Specify device_ids in barrier() to force use of a particular device, or call init_process_group() with a device_id.
|
| 8 |
+
[rank2]:[W512 16:35:00.301136581 ProcessGroupNCCL.cpp:4571] [PG ID 0 PG GUID 0 Rank 2] using GPU 2 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect. Specify device_ids in barrier() to force use of a particular device, or call init_process_group() with a device_id.
|
| 9 |
+
[rank3]:[W512 16:35:00.304399895 ProcessGroupNCCL.cpp:4571] [PG ID 0 PG GUID 0 Rank 3] using GPU 3 to perform barrier as devices used by this process are currently unknown. This can potentially cause a hang if this rank to GPU mapping is incorrect. Specify device_ids in barrier() to force use of a particular device, or call init_process_group() with a device_id.
|
| 10 |
+
{
|
| 11 |
+
"device": "cuda:0",
|
| 12 |
+
"rank": 0,
|
| 13 |
+
"world_size": 4,
|
| 14 |
+
"samples": "owt_cached_chunks:10904",
|
| 15 |
+
"vocab_size": 50257,
|
| 16 |
+
"save_dir": "runs/lta_owt_c1024_gpt2_cached_chunks_len1024_fast10k_4gpu_500step",
|
| 17 |
+
"batch_size": 32,
|
| 18 |
+
"grad_accum": 4,
|
| 19 |
+
"effective_batch_size": 512,
|
| 20 |
+
"global_batch_size": 512,
|
| 21 |
+
"lr_schedule": "constant_warmup",
|
| 22 |
+
"warmup_steps": 50,
|
| 23 |
+
"adam_beta1": 0.9,
|
| 24 |
+
"adam_beta2": 0.999,
|
| 25 |
+
"adam_eps": 1e-08,
|
| 26 |
+
"model_type": "ddit",
|
| 27 |
+
"dual_t": true,
|
| 28 |
+
"corrupt_t_mode": "same",
|
| 29 |
+
"corrupt_min_t": 0.0,
|
| 30 |
+
"corrupt_max_t": 1.0,
|
| 31 |
+
"dirichlet_endpoint_mode": "categorical_dual_t",
|
| 32 |
+
"dirichlet_semantic_t_mode": "same",
|
| 33 |
+
"dirichlet_semantic_t_value": 0.0,
|
| 34 |
+
"categorical_wrong_from_full_vocab": true,
|
| 35 |
+
"simplex_bridge_sampler": "dirichlet",
|
| 36 |
+
"logistic_normal_sigma_min": 0.18,
|
| 37 |
+
"logistic_normal_sigma_max": 2.2,
|
| 38 |
+
"logistic_normal_tau_min": 0.65,
|
| 39 |
+
"logistic_normal_tau_max": 1.15,
|
| 40 |
+
"torch_compile": false,
|
| 41 |
+
"compile_mode": "max-autotune",
|
| 42 |
+
"state_format": "prob",
|
| 43 |
+
"target_loss": "hard_ce",
|
| 44 |
+
"meanflow_weight": 0.0,
|
| 45 |
+
"bridge_noise_init": "logistic_normal",
|
| 46 |
+
"noise_sigma": -1.0,
|
| 47 |
+
"wrap": true,
|
| 48 |
+
"wrap_mode": "stream",
|
| 49 |
+
"wrap_record_buffer_size": 200,
|
| 50 |
+
"owt_cached_chunks": true,
|
| 51 |
+
"owt_chunk_cache_dir": "/e2e-data/evad-tech-vla/wanghan58/data/small_benchmarks/langflow_2604_11748/openwebtext_lta_cached_chunks/gpt2_len1024_train_minus_100k_fast10k",
|
| 52 |
+
"owt_chunk_cache_rebuild": false,
|
| 53 |
+
"owt_chunk_cache_write_batch": 4096,
|
| 54 |
+
"online_chunk_shuffle": false,
|
| 55 |
+
"online_chunk_shuffle_buffer": 10000,
|
| 56 |
+
"openwebtext_split": "train_minus_100k",
|
| 57 |
+
"detokenizer": "auto",
|
| 58 |
+
"resolved_detokenizer": null,
|
| 59 |
+
"num_workers": 2,
|
| 60 |
+
"latest_every": 50,
|
| 61 |
+
"resume_path": ""
|
| 62 |
+
}
|
| 63 |
+
step=10 micro_steps=40 elapsed=67.7s lr=6.600000e-05 loss_all=10.7775 acc_all=0.6098 loss_corrupt=10.7889 acc_corrupt=0.4141 corrupt_frac=0.5619 loss=10.7889 loss_recon=10.7889 loss_meanflow=0.0000 mean_model_t=0.4986 mean_corrupt_t=0.4986 mean_loss_t_weight=1.0000 prior_center_loss_beta=0.0000 wrong_frac=0.4990 init_acc_corrupt=0.4668 init_gold_top10=0.4955 init_gold_top100=0.5245
|
| 64 |
+
step=20 micro_steps=80 elapsed=57.9s lr=1.260000e-04 loss_all=10.3772 acc_all=0.3528 loss_corrupt=10.4082 acc_corrupt=0.2188 corrupt_frac=0.5554 loss=10.4082 loss_recon=10.4082 loss_meanflow=0.0000 mean_model_t=0.4975 mean_corrupt_t=0.4975 mean_loss_t_weight=1.0000 prior_center_loss_beta=0.0000 wrong_frac=0.4996 init_acc_corrupt=0.4680 init_gold_top10=0.4957 init_gold_top100=0.5226
|
| 65 |
+
step=30 micro_steps=120 elapsed=59.3s lr=1.860000e-04 loss_all=9.3684 acc_all=0.2037 loss_corrupt=9.4072 acc_corrupt=0.1250 corrupt_frac=0.5514 loss=9.4072 loss_recon=9.4072 loss_meanflow=0.0000 mean_model_t=0.4946 mean_corrupt_t=0.4946 mean_loss_t_weight=1.0000 prior_center_loss_beta=0.0000 wrong_frac=0.5065 init_acc_corrupt=0.4578 init_gold_top10=0.4874 init_gold_top100=0.5184
|
| 66 |
+
step=40 micro_steps=160 elapsed=62.9s lr=2.460000e-04 loss_all=8.1540 acc_all=0.2264 loss_corrupt=8.2181 acc_corrupt=0.1478 corrupt_frac=0.5382 loss=8.2181 loss_recon=8.2181 loss_meanflow=0.0000 mean_model_t=0.4880 mean_corrupt_t=0.4880 mean_loss_t_weight=1.0000 prior_center_loss_beta=0.0000 wrong_frac=0.5150 init_acc_corrupt=0.4486 init_gold_top10=0.4790 init_gold_top100=0.5111
|
| 67 |
+
[rank0]: Traceback (most recent call last):
|
| 68 |
+
[rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 797, in <module>
|
| 69 |
+
[rank0]: main()
|
| 70 |
+
[rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 693, in main
|
| 71 |
+
[rank0]: bridge = make_bridge(
|
| 72 |
+
[rank0]: ^^^^^^^^^^^^
|
| 73 |
+
[rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 313, in make_bridge
|
| 74 |
+
[rank0]: return make_dirichlet_bridge_batch(
|
| 75 |
+
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 76 |
+
[rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 529, in make_dirichlet_bridge_batch
|
| 77 |
+
[rank0]: state_probs = sample_dirichlet_bridge_simplex(
|
| 78 |
+
[rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 79 |
+
[rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 263, in sample_dirichlet_bridge_simplex
|
| 80 |
+
[rank0]: sample = sample.clamp_min(eps)
|
| 81 |
+
[rank0]: ^^^^^^^^^^^^^^^^^^^^^
|
| 82 |
+
[rank0]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 6.14 GiB. GPU 0 has a total capacity of 95.22 GiB of which 573.56 MiB is free. Process 971246 has 94.66 GiB memory in use. Of the allocated memory 61.51 GiB is allocated by PyTorch, and 31.86 GiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
|
| 83 |
+
[rank1]: Traceback (most recent call last):
|
| 84 |
+
[rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 797, in <module>
|
| 85 |
+
[rank1]: main()
|
| 86 |
+
[rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 693, in main
|
| 87 |
+
[rank1]: bridge = make_bridge(
|
| 88 |
+
[rank1]: ^^^^^^^^^^^^
|
| 89 |
+
[rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 313, in make_bridge
|
| 90 |
+
[rank1]: return make_dirichlet_bridge_batch(
|
| 91 |
+
[rank1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 92 |
+
[rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 529, in make_dirichlet_bridge_batch
|
| 93 |
+
[rank1]: state_probs = sample_dirichlet_bridge_simplex(
|
| 94 |
+
[rank1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 95 |
+
[rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 263, in sample_dirichlet_bridge_simplex
|
| 96 |
+
[rank1]: sample = sample.clamp_min(eps)
|
| 97 |
+
[rank1]: ^^^^^^^^^^^^^^^^^^^^^
|
| 98 |
+
[rank1]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 6.14 GiB. GPU 1 has a total capacity of 95.22 GiB of which 573.56 MiB is free. Process 971247 has 94.66 GiB memory in use. Of the allocated memory 61.51 GiB is allocated by PyTorch, and 31.86 GiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
|
| 99 |
+
[rank3]: Traceback (most recent call last):
|
| 100 |
+
[rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 797, in <module>
|
| 101 |
+
[rank3]: main()
|
| 102 |
+
[rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 693, in main
|
| 103 |
+
[rank3]: bridge = make_bridge(
|
| 104 |
+
[rank3]: ^^^^^^^^^^^^
|
| 105 |
+
[rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 313, in make_bridge
|
| 106 |
+
[rank3]: return make_dirichlet_bridge_batch(
|
| 107 |
+
[rank3]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 108 |
+
[rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 529, in make_dirichlet_bridge_batch
|
| 109 |
+
[rank3]: state_probs = sample_dirichlet_bridge_simplex(
|
| 110 |
+
[rank3]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 111 |
+
[rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 263, in sample_dirichlet_bridge_simplex
|
| 112 |
+
[rank3]: sample = sample.clamp_min(eps)
|
| 113 |
+
[rank3]: ^^^^^^^^^^^^^^^^^^^^^
|
| 114 |
+
[rank3]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 6.14 GiB. GPU 3 has a total capacity of 95.22 GiB of which 573.56 MiB is free. Process 971249 has 94.66 GiB memory in use. Of the allocated memory 61.51 GiB is allocated by PyTorch, and 31.86 GiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
|
| 115 |
+
[rank2]: Traceback (most recent call last):
|
| 116 |
+
[rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 797, in <module>
|
| 117 |
+
[rank2]: main()
|
| 118 |
+
[rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 693, in main
|
| 119 |
+
[rank2]: bridge = make_bridge(
|
| 120 |
+
[rank2]: ^^^^^^^^^^^^
|
| 121 |
+
[rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 313, in make_bridge
|
| 122 |
+
[rank2]: return make_dirichlet_bridge_batch(
|
| 123 |
+
[rank2]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 124 |
+
[rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 529, in make_dirichlet_bridge_batch
|
| 125 |
+
[rank2]: state_probs = sample_dirichlet_bridge_simplex(
|
| 126 |
+
[rank2]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 127 |
+
[rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 263, in sample_dirichlet_bridge_simplex
|
| 128 |
+
[rank2]: sample = sample.clamp_min(eps)
|
| 129 |
+
[rank2]: ^^^^^^^^^^^^^^^^^^^^^
|
| 130 |
+
[rank2]: torch.OutOfMemoryError: CUDA out of memory. Tried to allocate 6.14 GiB. GPU 2 has a total capacity of 95.22 GiB of which 573.56 MiB is free. Process 971248 has 94.66 GiB memory in use. Of the allocated memory 61.51 GiB is allocated by PyTorch, and 31.86 GiB is reserved by PyTorch but unallocated. If reserved but unallocated memory is large try setting PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True to avoid fragmentation. See documentation for Memory Management (https://pytorch.org/docs/stable/notes/cuda.html#environment-variables)
|
| 131 |
+
[rank0]:[W512 16:40:20.480386792 ProcessGroupNCCL.cpp:1487] Warning: WARNING: destroy_process_group() was not called before program exit, which can leak resources. For more info, please see https://pytorch.org/docs/stable/distributed.html#shutdown (function operator())
|
| 132 |
+
W0512 16:40:21.089000 208015 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 208083 closing signal SIGTERM
|
| 133 |
+
W0512 16:40:21.090000 208015 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 208084 closing signal SIGTERM
|
| 134 |
+
W0512 16:40:21.090000 208015 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 208085 closing signal SIGTERM
|
| 135 |
+
E0512 16:40:21.469000 208015 torch/distributed/elastic/multiprocessing/api.py:870] failed (exitcode: 1) local_rank: 0 (pid: 208082) of binary: /usr/bin/python
|
| 136 |
+
Traceback (most recent call last):
|
| 137 |
+
File "<frozen runpy>", line 198, in _run_module_as_main
|
| 138 |
+
File "<frozen runpy>", line 88, in _run_code
|
| 139 |
+
File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 922, in <module>
|
| 140 |
+
main()
|
| 141 |
+
File "/usr/local/lib/python3.12/dist-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 355, in wrapper
|
| 142 |
+
return f(*args, **kwargs)
|
| 143 |
+
^^^^^^^^^^^^^^^^^^
|
| 144 |
+
File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 918, in main
|
| 145 |
+
run(args)
|
| 146 |
+
File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 909, in run
|
| 147 |
+
elastic_launch(
|
| 148 |
+
File "/usr/local/lib/python3.12/dist-packages/torch/distributed/launcher/api.py", line 139, in __call__
|
| 149 |
+
return launch_agent(self._config, self._entrypoint, list(args))
|
| 150 |
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
| 151 |
+
File "/usr/local/lib/python3.12/dist-packages/torch/distributed/launcher/api.py", line 270, in launch_agent
|
| 152 |
+
raise ChildFailedError(
|
| 153 |
+
torch.distributed.elastic.multiprocessing.errors.ChildFailedError:
|
| 154 |
+
============================================================
|
| 155 |
+
train.py FAILED
|
| 156 |
+
------------------------------------------------------------
|
| 157 |
+
Failures:
|
| 158 |
+
<NO_OTHER_FAILURES>
|
| 159 |
+
------------------------------------------------------------
|
| 160 |
+
Root Cause (first observed failure):
|
| 161 |
+
[0]:
|
| 162 |
+
time : 2026-05-12_16:40:21
|
| 163 |
+
host : localhost
|
| 164 |
+
rank : 0 (local_rank: 0)
|
| 165 |
+
exitcode : 1 (pid: 208082)
|
| 166 |
+
error_file: <N/A>
|
| 167 |
+
traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
|
| 168 |
+
============================================================
|
LTA_openwebtext_dualt/logs/lta_owt_c1024_len1024_lowt0p2_lowk80_noall_buf1000_gbs128_4gpu_100step.nohup.log
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[launch] owt low-t-cut low-k 100-step pilot
|
| 2 |
+
[launch] run_name=lta_owt_c1024_len1024_lowt0p2_lowk80_noall_buf1000_gbs128_4gpu_100step
|
| 3 |
+
[launch] save_dir=runs/lta_owt_c1024_len1024_lowt0p2_lowk80_noall_buf1000_gbs128_4gpu_100step
|
| 4 |
+
[launch] t=0.20..1.0 mask=0.01..1.0
|
| 5 |
+
[launch] mixture original=0.20 lowk=0.80 all=0.0
|
| 6 |
+
|
| 7 |
+
*****************************************
|
| 8 |
+
Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.
|
| 9 |
+
*****************************************
|
| 10 |
+
NCCL version 2.25.1+cuda12.8
|
| 11 |
+
{
|
| 12 |
+
"device": "cuda:0",
|
| 13 |
+
"rank": 0,
|
| 14 |
+
"world_size": 4,
|
| 15 |
+
"samples": "wrapped_stream_online_shuffle:1000",
|
| 16 |
+
"vocab_size": 50257,
|
| 17 |
+
"save_dir": "runs/lta_owt_c1024_len1024_lowt0p2_lowk80_noall_buf1000_gbs128_4gpu_100step",
|
| 18 |
+
"batch_size": 16,
|
| 19 |
+
"grad_accum": 2,
|
| 20 |
+
"effective_batch_size": 128,
|
| 21 |
+
"global_batch_size": 128,
|
| 22 |
+
"lr_schedule": "constant_warmup",
|
| 23 |
+
"warmup_steps": 10,
|
| 24 |
+
"adam_beta1": 0.9,
|
| 25 |
+
"adam_beta2": 0.999,
|
| 26 |
+
"adam_eps": 1e-08,
|
| 27 |
+
"model_type": "ddit",
|
| 28 |
+
"dual_t": true,
|
| 29 |
+
"corrupt_t_mode": "same",
|
| 30 |
+
"corrupt_min_t": 0.2,
|
| 31 |
+
"corrupt_max_t": 1.0,
|
| 32 |
+
"dirichlet_endpoint_mode": "categorical_dual_t",
|
| 33 |
+
"dirichlet_semantic_t_mode": "same",
|
| 34 |
+
"dirichlet_semantic_t_value": 0.0,
|
| 35 |
+
"categorical_wrong_from_full_vocab": true,
|
| 36 |
+
"simplex_bridge_sampler": "dirichlet",
|
| 37 |
+
"logistic_normal_sigma_min": 0.18,
|
| 38 |
+
"logistic_normal_sigma_max": 2.2,
|
| 39 |
+
"logistic_normal_tau_min": 0.65,
|
| 40 |
+
"logistic_normal_tau_max": 1.15,
|
| 41 |
+
"torch_compile": false,
|
| 42 |
+
"compile_mode": "max-autotune",
|
| 43 |
+
"state_format": "prob",
|
| 44 |
+
"target_loss": "hard_ce",
|
| 45 |
+
"meanflow_weight": 0.0,
|
| 46 |
+
"bridge_noise_init": "logistic_normal",
|
| 47 |
+
"noise_sigma": -1.0,
|
| 48 |
+
"wrap": true,
|
| 49 |
+
"wrap_mode": "stream",
|
| 50 |
+
"wrap_record_buffer_size": 200,
|
| 51 |
+
"owt_cached_chunks": false,
|
| 52 |
+
"owt_chunk_cache_dir": "",
|
| 53 |
+
"owt_chunk_cache_rebuild": false,
|
| 54 |
+
"owt_chunk_cache_write_batch": 4096,
|
| 55 |
+
"online_chunk_shuffle": true,
|
| 56 |
+
"online_chunk_shuffle_buffer": 1000,
|
| 57 |
+
"openwebtext_split": "train_minus_100k",
|
| 58 |
+
"detokenizer": "auto",
|
| 59 |
+
"resolved_detokenizer": null,
|
| 60 |
+
"num_workers": 0,
|
| 61 |
+
"latest_every": 50,
|
| 62 |
+
"resume_path": ""
|
| 63 |
+
}
|
| 64 |
+
step=10 micro_steps=20 elapsed=19.3s lr=3.000000e-04 loss_all=10.5503 acc_all=0.3705 loss_corrupt=10.5549 acc_corrupt=0.3380 corrupt_frac=0.8823 loss=10.5549 loss_recon=10.5549 loss_meanflow=0.0000 mean_model_t=0.5957 mean_corrupt_t=0.5957 wrong_frac=0.4038 init_acc_corrupt=0.5758 init_gold_top10=0.5953 init_gold_top100=0.6043
|
| 65 |
+
step=20 micro_steps=40 elapsed=15.6s lr=3.000000e-04 loss_all=8.8827 acc_all=0.2839 loss_corrupt=8.9025 acc_corrupt=0.2544 corrupt_frac=0.8798 loss=8.9025 loss_recon=8.9025 loss_meanflow=0.0000 mean_model_t=0.6119 mean_corrupt_t=0.6119 wrong_frac=0.3848 init_acc_corrupt=0.5963 init_gold_top10=0.6144 init_gold_top100=0.6220
|
| 66 |
+
step=30 micro_steps=60 elapsed=15.7s lr=3.000000e-04 loss_all=7.2594 acc_all=0.3284 loss_corrupt=7.3171 acc_corrupt=0.3054 corrupt_frac=0.8904 loss=7.3171 loss_recon=7.3171 loss_meanflow=0.0000 mean_model_t=0.6081 mean_corrupt_t=0.6081 wrong_frac=0.3883 init_acc_corrupt=0.5898 init_gold_top10=0.6111 init_gold_top100=0.6188
|
| 67 |
+
step=40 micro_steps=80 elapsed=15.6s lr=3.000000e-04 loss_all=6.2331 acc_all=0.3068 loss_corrupt=6.4002 acc_corrupt=0.2793 corrupt_frac=0.8658 loss=6.4002 loss_recon=6.4002 loss_meanflow=0.0000 mean_model_t=0.5845 mean_corrupt_t=0.5845 wrong_frac=0.4127 init_acc_corrupt=0.5643 init_gold_top10=0.5865 init_gold_top100=0.5953
|
| 68 |
+
step=50 micro_steps=100 elapsed=15.6s lr=3.000000e-04 loss_all=5.3938 acc_all=0.3656 loss_corrupt=5.6086 acc_corrupt=0.3343 corrupt_frac=0.8822 loss=5.6086 loss_recon=5.6086 loss_meanflow=0.0000 mean_model_t=0.6005 mean_corrupt_t=0.6005 wrong_frac=0.4020 init_acc_corrupt=0.5757 init_gold_top10=0.5974 init_gold_top100=0.6055
|
| 69 |
+
step=60 micro_steps=120 elapsed=17.4s lr=3.000000e-04 loss_all=4.2746 acc_all=0.5067 loss_corrupt=4.5425 acc_corrupt=0.4699 corrupt_frac=0.8836 loss=4.5425 loss_recon=4.5425 loss_meanflow=0.0000 mean_model_t=0.6039 mean_corrupt_t=0.6039 wrong_frac=0.3956 init_acc_corrupt=0.5818 init_gold_top10=0.6036 init_gold_top100=0.6116
|
| 70 |
+
step=70 micro_steps=140 elapsed=15.6s lr=3.000000e-04 loss_all=3.9509 acc_all=0.5396 loss_corrupt=4.2780 acc_corrupt=0.4999 corrupt_frac=0.8873 loss=4.2780 loss_recon=4.2780 loss_meanflow=0.0000 mean_model_t=0.5874 mean_corrupt_t=0.5874 wrong_frac=0.4177 init_acc_corrupt=0.5603 init_gold_top10=0.5815 init_gold_top100=0.5896
|
| 71 |
+
step=80 micro_steps=160 elapsed=15.7s lr=3.000000e-04 loss_all=3.5467 acc_all=0.5825 loss_corrupt=3.9334 acc_corrupt=0.5363 corrupt_frac=0.8776 loss=3.9334 loss_recon=3.9334 loss_meanflow=0.0000 mean_model_t=0.5958 mean_corrupt_t=0.5958 wrong_frac=0.4048 init_acc_corrupt=0.5710 init_gold_top10=0.5943 init_gold_top100=0.6029
|
| 72 |
+
step=90 micro_steps=180 elapsed=15.7s lr=3.000000e-04 loss_all=3.3378 acc_all=0.5975 loss_corrupt=3.7512 acc_corrupt=0.5472 corrupt_frac=0.8661 loss=3.7512 loss_recon=3.7512 loss_meanflow=0.0000 mean_model_t=0.5929 mean_corrupt_t=0.5929 wrong_frac=0.4062 init_acc_corrupt=0.5668 init_gold_top10=0.5927 init_gold_top100=0.6037
|
| 73 |
+
step=100 micro_steps=200 elapsed=15.6s lr=3.000000e-04 loss_all=3.0738 acc_all=0.6320 loss_corrupt=3.4991 acc_corrupt=0.5806 corrupt_frac=0.8580 loss=3.4991 loss_recon=3.4991 loss_meanflow=0.0000 mean_model_t=0.6140 mean_corrupt_t=0.6140 wrong_frac=0.3817 init_acc_corrupt=0.5964 init_gold_top10=0.6177 init_gold_top100=0.6244
|
LTA_openwebtext_dualt/logs/lta_owt_launcher_opt_smoke_bspgpu64_gbs512_4gpu_20step_20260513.outer.log
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[launch] method=owt_categorical_fullvocab_c1024_fullycoupled host=di-20260411014000-djqhq time=2026-05-13T03:03:02+00:00
|
| 2 |
+
[launch] cwd=/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt
|
| 3 |
+
[launch] run_name=lta_owt_launcher_opt_smoke_bspgpu64_gbs512_4gpu_20step_20260513
|
| 4 |
+
[launch] save_dir=runs/lta_owt_launcher_opt_smoke_bspgpu64_gbs512_4gpu_20step_20260513
|
| 5 |
+
[launch] log_file=logs/lta_owt_launcher_opt_smoke_bspgpu64_gbs512_4gpu_20step_20260513.log
|
| 6 |
+
[launch] data_path=/e2e-data/evad-tech-vla/wanghan58/data/small_benchmarks/langflow_2604_11748/openwebtext
|
| 7 |
+
[launch] tokenizer=/e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-standard/tokenizer.json
|
| 8 |
+
[launch] split=train_minus_100k text_column=text
|
| 9 |
+
[launch] nproc_per_node=4 global_batch_size=512 per_gpu_batch_size=64
|
| 10 |
+
[launch] model d_model=768 n_layers=12 n_heads=12 dim_ff=3072 dropout=0.0
|
| 11 |
+
[launch] optimizer=adamw lr=6e-4 wd=0.1 ema=0.0
|
| 12 |
+
[launch] perf allow_tf32=1 activation_checkpointing=1 prefetch=4
|
| 13 |
+
|
| 14 |
+
*****************************************
|
| 15 |
+
Setting OMP_NUM_THREADS environment variable for each process to be 1 in default, to avoid your system being overloaded, please further tune the variable for optimal performance in your application as needed.
|
| 16 |
+
*****************************************
|
| 17 |
+
NCCL version 2.25.1+cuda12.8
|
| 18 |
+
{
|
| 19 |
+
"device": "cuda:0",
|
| 20 |
+
"rank": 0,
|
| 21 |
+
"world_size": 4,
|
| 22 |
+
"samples": "wrapped_stream",
|
| 23 |
+
"vocab_size": 50257,
|
| 24 |
+
"tokenizer_vocab_size": 50257,
|
| 25 |
+
"save_dir": "runs/lta_owt_launcher_opt_smoke_bspgpu64_gbs512_4gpu_20step_20260513",
|
| 26 |
+
"batch_size": 64,
|
| 27 |
+
"grad_accum": 2,
|
| 28 |
+
"effective_batch_size": 512,
|
| 29 |
+
"global_batch_size": 512,
|
| 30 |
+
"lr_schedule": "cosine",
|
| 31 |
+
"optimizer": "adamw",
|
| 32 |
+
"warmup_steps": 20,
|
| 33 |
+
"min_lr": 6e-05,
|
| 34 |
+
"weight_decay": 0.1,
|
| 35 |
+
"adamw_param_groups": "nanogpt",
|
| 36 |
+
"adam_beta1": 0.9,
|
| 37 |
+
"adam_beta2": 0.95,
|
| 38 |
+
"adam_eps": 1e-08,
|
| 39 |
+
"muon_momentum": 0.95,
|
| 40 |
+
"muon_ns_steps": 5,
|
| 41 |
+
"muon_update_scale": 1.0,
|
| 42 |
+
"ema_decay": 0.0,
|
| 43 |
+
"ema_start_step": 0,
|
| 44 |
+
"model_type": "ddit",
|
| 45 |
+
"dual_t": true,
|
| 46 |
+
"corrupt_t_mode": "same",
|
| 47 |
+
"corrupt_min_t": 0.0,
|
| 48 |
+
"corrupt_max_t": 1.0,
|
| 49 |
+
"prefix_block_prob": 0.0,
|
| 50 |
+
"prefix_block_len": 128,
|
| 51 |
+
"dirichlet_endpoint_mode": "categorical_dual_t",
|
| 52 |
+
"dirichlet_semantic_t_mode": "same",
|
| 53 |
+
"dirichlet_semantic_t_value": 0.0,
|
| 54 |
+
"categorical_wrong_from_full_vocab": true,
|
| 55 |
+
"categorical_wrong_from_batch_valid_tokens": false,
|
| 56 |
+
"mask_mixture_original_prob": 0.0,
|
| 57 |
+
"mask_mixture_lowk_prob": 0.0,
|
| 58 |
+
"mask_mixture_lowcorrupt_prob": 0.0,
|
| 59 |
+
"mask_mixture_block_prob": 0.0,
|
| 60 |
+
"mask_mixture_all_prob": 0.0,
|
| 61 |
+
"mask_mixture_lowk_clean_tokens": "1,2,4,8,16,32,64",
|
| 62 |
+
"mask_mixture_lowcorrupt_tokens": "1,2,4,8,16,32,64",
|
| 63 |
+
"mask_mixture_block_tokens": "64,128",
|
| 64 |
+
"simplex_bridge_sampler": "dirichlet",
|
| 65 |
+
"logistic_normal_sigma_min": 0.18,
|
| 66 |
+
"logistic_normal_sigma_max": 2.2,
|
| 67 |
+
"logistic_normal_tau_min": 0.65,
|
| 68 |
+
"logistic_normal_tau_max": 1.15,
|
| 69 |
+
"torch_compile": false,
|
| 70 |
+
"compile_mode": "max-autotune",
|
| 71 |
+
"state_format": "prob",
|
| 72 |
+
"target_loss": "hard_ce",
|
| 73 |
+
"meanflow_weight": 0.0,
|
| 74 |
+
"bridge_noise_init": "logistic_normal",
|
| 75 |
+
"noise_sigma": -1.0,
|
| 76 |
+
"allow_tf32": true,
|
| 77 |
+
"activation_checkpointing": true,
|
| 78 |
+
"ddp_static_graph": false,
|
| 79 |
+
"ddp_gradient_as_bucket_view": true,
|
| 80 |
+
"blocking_data_transfer": false,
|
| 81 |
+
"dataloader_prefetch_factor": 4,
|
| 82 |
+
"full_train_stats": false,
|
| 83 |
+
"wrap": true,
|
| 84 |
+
"wrap_mode": "stream",
|
| 85 |
+
"wrap_record_buffer_size": 200,
|
| 86 |
+
"owt_cached_chunks": false,
|
| 87 |
+
"owt_chunk_cache_dir": "",
|
| 88 |
+
"owt_chunk_cache_rebuild": false,
|
| 89 |
+
"owt_chunk_cache_write_batch": 4096,
|
| 90 |
+
"owt_exact_repeat_per_chunk": 0,
|
| 91 |
+
"online_chunk_shuffle": false,
|
| 92 |
+
"online_chunk_shuffle_buffer": 10000,
|
| 93 |
+
"openwebtext_split": "train_minus_100k",
|
| 94 |
+
"detokenizer": "auto",
|
| 95 |
+
"resolved_detokenizer": null,
|
| 96 |
+
"num_workers": 4,
|
| 97 |
+
"latest_every": 0,
|
| 98 |
+
"resume_path": ""
|
| 99 |
+
}
|
| 100 |
+
step=5 micro_steps=10 elapsed=16.8s lr=1.800000e-04 loss_all=10.6893 acc_all=0.6116 loss_corrupt=10.7312 acc_corrupt=0.3232 corrupt_frac=0.5314 loss=10.7312 loss_recon=10.7312 loss_meanflow=0.0000 mean_model_t=0.5283 mean_corrupt_t=0.5283 mean_loss_t_weight=1.0000 prior_center_loss_beta=0.0000 wrong_frac=0.4484 init_acc_corrupt=0.3224 init_gold_top10=0.3393 init_gold_top100=0.3990
|
| 101 |
+
step=10 micro_steps=20 elapsed=15.5s lr=3.300000e-04 loss_all=9.9390 acc_all=0.0729 loss_corrupt=9.9570 acc_corrupt=0.0432 corrupt_frac=0.5474 loss=9.9570 loss_recon=9.9570 loss_meanflow=0.0000 mean_model_t=0.5045 mean_corrupt_t=0.5045 mean_loss_t_weight=1.0000 prior_center_loss_beta=0.0000 wrong_frac=0.4738 init_acc_corrupt=0.3317 init_gold_top10=0.3498 init_gold_top100=0.3963
|
| 102 |
+
step=15 micro_steps=30 elapsed=17.9s lr=4.800000e-04 loss_all=8.7640 acc_all=0.0341 loss_corrupt=8.7541 acc_corrupt=0.0343 corrupt_frac=0.6156 loss=8.7541 loss_recon=8.7541 loss_meanflow=0.0000 mean_model_t=0.5740 mean_corrupt_t=0.5740 mean_loss_t_weight=1.0000 prior_center_loss_beta=0.0000 wrong_frac=0.4372 init_acc_corrupt=0.3838 init_gold_top10=0.4053 init_gold_top100=0.4513
|
| 103 |
+
Terminated
|
LTA_openwebtext_dualt/logs/owt_classic_fullvocab_len1024_infer_watch/infer_lta_owt_classic_fullvocab_bert_c1024_len1024_gbs512_8gpu_1m_save10k_20260521_162117_step_0010000_t1p45.log
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[watch-owt-classic] 2026-05-21_18:30:25 infer runs/lta_owt_classic_fullvocab_bert_c1024_len1024_gbs512_8gpu_1m_save10k_20260521_162117/step_0010000.pt -> docs/lta_samples/metrics_20260521/owt_classic_fullvocab_len1024_every10k_normal_steps_state_t1p45_c1024_n1024/lta_owt_classic_fullvocab_bert_c1024_len1024_gbs512_8gpu_1m_save10k_20260521_162117/step_0010000
|
| 2 |
+
[ckpt] runs/lta_owt_classic_fullvocab_bert_c1024_len1024_gbs512_8gpu_1m_save10k_20260521_162117/step_0010000.pt step=10000
|
| 3 |
+
[decode] steps128_c1024_t1p45 generated 4/1024
|
| 4 |
+
[decode] steps128_c1024_t1p45 generated 8/1024
|
| 5 |
+
[decode] steps128_c1024_t1p45 generated 12/1024
|
| 6 |
+
[decode] steps128_c1024_t1p45 generated 16/1024
|
| 7 |
+
[decode] steps128_c1024_t1p45 generated 20/1024
|
| 8 |
+
[decode] steps128_c1024_t1p45 generated 24/1024
|
| 9 |
+
[decode] steps128_c1024_t1p45 generated 28/1024
|
| 10 |
+
[decode] steps128_c1024_t1p45 generated 32/1024
|
| 11 |
+
[decode] steps128_c1024_t1p45 generated 36/1024
|
| 12 |
+
[decode] steps128_c1024_t1p45 generated 40/1024
|
| 13 |
+
[decode] steps128_c1024_t1p45 generated 44/1024
|
| 14 |
+
[decode] steps128_c1024_t1p45 generated 48/1024
|
| 15 |
+
[decode] steps128_c1024_t1p45 generated 52/1024
|
| 16 |
+
[decode] steps128_c1024_t1p45 generated 56/1024
|
| 17 |
+
[decode] steps128_c1024_t1p45 generated 60/1024
|
| 18 |
+
[decode] steps128_c1024_t1p45 generated 64/1024
|
| 19 |
+
[decode] steps128_c1024_t1p45 generated 68/1024
|
| 20 |
+
[decode] steps128_c1024_t1p45 generated 72/1024
|
| 21 |
+
[decode] steps128_c1024_t1p45 generated 76/1024
|
| 22 |
+
[decode] steps128_c1024_t1p45 generated 80/1024
|
| 23 |
+
[decode] steps128_c1024_t1p45 generated 84/1024
|
| 24 |
+
[decode] steps128_c1024_t1p45 generated 88/1024
|
| 25 |
+
[decode] steps128_c1024_t1p45 generated 92/1024
|
| 26 |
+
[decode] steps128_c1024_t1p45 generated 96/1024
|
| 27 |
+
[decode] steps128_c1024_t1p45 generated 100/1024
|
| 28 |
+
[decode] steps128_c1024_t1p45 generated 104/1024
|
| 29 |
+
[decode] steps128_c1024_t1p45 generated 108/1024
|
| 30 |
+
[decode] steps128_c1024_t1p45 generated 112/1024
|
| 31 |
+
[decode] steps128_c1024_t1p45 generated 116/1024
|
| 32 |
+
[decode] steps128_c1024_t1p45 generated 120/1024
|
| 33 |
+
[decode] steps128_c1024_t1p45 generated 124/1024
|
| 34 |
+
[decode] steps128_c1024_t1p45 generated 128/1024
|
| 35 |
+
[decode] steps128_c1024_t1p45 generated 132/1024
|
| 36 |
+
[decode] steps128_c1024_t1p45 generated 136/1024
|
| 37 |
+
[decode] steps128_c1024_t1p45 generated 140/1024
|
| 38 |
+
[decode] steps128_c1024_t1p45 generated 144/1024
|
| 39 |
+
[decode] steps128_c1024_t1p45 generated 148/1024
|
| 40 |
+
[decode] steps128_c1024_t1p45 generated 152/1024
|
| 41 |
+
[decode] steps128_c1024_t1p45 generated 156/1024
|
| 42 |
+
[decode] steps128_c1024_t1p45 generated 160/1024
|
| 43 |
+
[decode] steps128_c1024_t1p45 generated 164/1024
|
| 44 |
+
[decode] steps128_c1024_t1p45 generated 168/1024
|
| 45 |
+
[decode] steps128_c1024_t1p45 generated 172/1024
|
| 46 |
+
[decode] steps128_c1024_t1p45 generated 176/1024
|
| 47 |
+
[decode] steps128_c1024_t1p45 generated 180/1024
|
| 48 |
+
[decode] steps128_c1024_t1p45 generated 184/1024
|
| 49 |
+
[decode] steps128_c1024_t1p45 generated 188/1024
|
| 50 |
+
[decode] steps128_c1024_t1p45 generated 192/1024
|
| 51 |
+
[decode] steps128_c1024_t1p45 generated 196/1024
|
| 52 |
+
[decode] steps128_c1024_t1p45 generated 200/1024
|
| 53 |
+
[decode] steps128_c1024_t1p45 generated 204/1024
|
| 54 |
+
[decode] steps128_c1024_t1p45 generated 208/1024
|
| 55 |
+
[decode] steps128_c1024_t1p45 generated 212/1024
|
| 56 |
+
[decode] steps128_c1024_t1p45 generated 216/1024
|
| 57 |
+
[decode] steps128_c1024_t1p45 generated 220/1024
|
| 58 |
+
[decode] steps128_c1024_t1p45 generated 224/1024
|
| 59 |
+
[decode] steps128_c1024_t1p45 generated 228/1024
|
| 60 |
+
[decode] steps128_c1024_t1p45 generated 232/1024
|
| 61 |
+
[decode] steps128_c1024_t1p45 generated 236/1024
|
| 62 |
+
[decode] steps128_c1024_t1p45 generated 240/1024
|
| 63 |
+
[decode] steps128_c1024_t1p45 generated 244/1024
|
| 64 |
+
[decode] steps128_c1024_t1p45 generated 248/1024
|
| 65 |
+
[decode] steps128_c1024_t1p45 generated 252/1024
|
| 66 |
+
[decode] steps128_c1024_t1p45 generated 256/1024
|
| 67 |
+
[decode] steps128_c1024_t1p45 generated 260/1024
|
| 68 |
+
[decode] steps128_c1024_t1p45 generated 264/1024
|
| 69 |
+
[decode] steps128_c1024_t1p45 generated 268/1024
|
| 70 |
+
[decode] steps128_c1024_t1p45 generated 272/1024
|
| 71 |
+
[decode] steps128_c1024_t1p45 generated 276/1024
|
| 72 |
+
[decode] steps128_c1024_t1p45 generated 280/1024
|
| 73 |
+
[decode] steps128_c1024_t1p45 generated 284/1024
|
| 74 |
+
[decode] steps128_c1024_t1p45 generated 288/1024
|
| 75 |
+
[decode] steps128_c1024_t1p45 generated 292/1024
|
| 76 |
+
[decode] steps128_c1024_t1p45 generated 296/1024
|
| 77 |
+
[decode] steps128_c1024_t1p45 generated 300/1024
|
| 78 |
+
[decode] steps128_c1024_t1p45 generated 304/1024
|
| 79 |
+
[decode] steps128_c1024_t1p45 generated 308/1024
|
| 80 |
+
[decode] steps128_c1024_t1p45 generated 312/1024
|
| 81 |
+
[decode] steps128_c1024_t1p45 generated 316/1024
|
| 82 |
+
[decode] steps128_c1024_t1p45 generated 320/1024
|
| 83 |
+
[decode] steps128_c1024_t1p45 generated 324/1024
|
| 84 |
+
[decode] steps128_c1024_t1p45 generated 328/1024
|
| 85 |
+
[decode] steps128_c1024_t1p45 generated 332/1024
|
| 86 |
+
[decode] steps128_c1024_t1p45 generated 336/1024
|
| 87 |
+
[decode] steps128_c1024_t1p45 generated 340/1024
|
| 88 |
+
[decode] steps128_c1024_t1p45 generated 344/1024
|
| 89 |
+
[decode] steps128_c1024_t1p45 generated 348/1024
|
| 90 |
+
[decode] steps128_c1024_t1p45 generated 352/1024
|
| 91 |
+
[decode] steps128_c1024_t1p45 generated 356/1024
|
| 92 |
+
[decode] steps128_c1024_t1p45 generated 360/1024
|
| 93 |
+
[decode] steps128_c1024_t1p45 generated 364/1024
|
| 94 |
+
[decode] steps128_c1024_t1p45 generated 368/1024
|
| 95 |
+
[decode] steps128_c1024_t1p45 generated 372/1024
|
| 96 |
+
[decode] steps128_c1024_t1p45 generated 376/1024
|
| 97 |
+
[decode] steps128_c1024_t1p45 generated 380/1024
|
| 98 |
+
[decode] steps128_c1024_t1p45 generated 384/1024
|
| 99 |
+
[decode] steps128_c1024_t1p45 generated 388/1024
|
| 100 |
+
[decode] steps128_c1024_t1p45 generated 392/1024
|
| 101 |
+
[decode] steps128_c1024_t1p45 generated 396/1024
|
| 102 |
+
[decode] steps128_c1024_t1p45 generated 400/1024
|
| 103 |
+
[decode] steps128_c1024_t1p45 generated 404/1024
|
| 104 |
+
[decode] steps128_c1024_t1p45 generated 408/1024
|
| 105 |
+
[decode] steps128_c1024_t1p45 generated 412/1024
|
| 106 |
+
[decode] steps128_c1024_t1p45 generated 416/1024
|
| 107 |
+
[decode] steps128_c1024_t1p45 generated 420/1024
|
| 108 |
+
[decode] steps128_c1024_t1p45 generated 424/1024
|
| 109 |
+
[decode] steps128_c1024_t1p45 generated 428/1024
|
| 110 |
+
[decode] steps128_c1024_t1p45 generated 432/1024
|
| 111 |
+
[decode] steps128_c1024_t1p45 generated 436/1024
|
| 112 |
+
[decode] steps128_c1024_t1p45 generated 440/1024
|
| 113 |
+
[decode] steps128_c1024_t1p45 generated 444/1024
|
| 114 |
+
[decode] steps128_c1024_t1p45 generated 448/1024
|
| 115 |
+
[decode] steps128_c1024_t1p45 generated 452/1024
|
| 116 |
+
[decode] steps128_c1024_t1p45 generated 456/1024
|
| 117 |
+
[decode] steps128_c1024_t1p45 generated 460/1024
|
| 118 |
+
[decode] steps128_c1024_t1p45 generated 464/1024
|
| 119 |
+
[decode] steps128_c1024_t1p45 generated 468/1024
|
| 120 |
+
[decode] steps128_c1024_t1p45 generated 472/1024
|
| 121 |
+
[decode] steps128_c1024_t1p45 generated 476/1024
|
| 122 |
+
[decode] steps128_c1024_t1p45 generated 480/1024
|
| 123 |
+
[decode] steps128_c1024_t1p45 generated 484/1024
|
| 124 |
+
[decode] steps128_c1024_t1p45 generated 488/1024
|
| 125 |
+
[decode] steps128_c1024_t1p45 generated 492/1024
|
| 126 |
+
[decode] steps128_c1024_t1p45 generated 496/1024
|
| 127 |
+
[decode] steps128_c1024_t1p45 generated 500/1024
|
| 128 |
+
[decode] steps128_c1024_t1p45 generated 504/1024
|
| 129 |
+
[decode] steps128_c1024_t1p45 generated 508/1024
|
| 130 |
+
[decode] steps128_c1024_t1p45 generated 512/1024
|
| 131 |
+
[decode] steps128_c1024_t1p45 generated 516/1024
|
| 132 |
+
[decode] steps128_c1024_t1p45 generated 520/1024
|
| 133 |
+
[decode] steps128_c1024_t1p45 generated 524/1024
|
| 134 |
+
[decode] steps128_c1024_t1p45 generated 528/1024
|
| 135 |
+
[decode] steps128_c1024_t1p45 generated 532/1024
|
| 136 |
+
[decode] steps128_c1024_t1p45 generated 536/1024
|
| 137 |
+
[decode] steps128_c1024_t1p45 generated 540/1024
|
| 138 |
+
[decode] steps128_c1024_t1p45 generated 544/1024
|
| 139 |
+
[decode] steps128_c1024_t1p45 generated 548/1024
|
| 140 |
+
[decode] steps128_c1024_t1p45 generated 552/1024
|
| 141 |
+
[decode] steps128_c1024_t1p45 generated 556/1024
|
| 142 |
+
[decode] steps128_c1024_t1p45 generated 560/1024
|
| 143 |
+
[decode] steps128_c1024_t1p45 generated 564/1024
|
| 144 |
+
[decode] steps128_c1024_t1p45 generated 568/1024
|
| 145 |
+
[decode] steps128_c1024_t1p45 generated 572/1024
|
| 146 |
+
[decode] steps128_c1024_t1p45 generated 576/1024
|
| 147 |
+
[decode] steps128_c1024_t1p45 generated 580/1024
|
| 148 |
+
[decode] steps128_c1024_t1p45 generated 584/1024
|
| 149 |
+
[decode] steps128_c1024_t1p45 generated 588/1024
|
| 150 |
+
[decode] steps128_c1024_t1p45 generated 592/1024
|
| 151 |
+
[decode] steps128_c1024_t1p45 generated 596/1024
|
| 152 |
+
[decode] steps128_c1024_t1p45 generated 600/1024
|
| 153 |
+
[decode] steps128_c1024_t1p45 generated 604/1024
|
| 154 |
+
[decode] steps128_c1024_t1p45 generated 608/1024
|
| 155 |
+
[decode] steps128_c1024_t1p45 generated 612/1024
|
| 156 |
+
[decode] steps128_c1024_t1p45 generated 616/1024
|
| 157 |
+
[decode] steps128_c1024_t1p45 generated 620/1024
|
| 158 |
+
[decode] steps128_c1024_t1p45 generated 624/1024
|
| 159 |
+
[decode] steps128_c1024_t1p45 generated 628/1024
|
| 160 |
+
[decode] steps128_c1024_t1p45 generated 632/1024
|
| 161 |
+
[decode] steps128_c1024_t1p45 generated 636/1024
|
| 162 |
+
[decode] steps128_c1024_t1p45 generated 640/1024
|
| 163 |
+
[decode] steps128_c1024_t1p45 generated 644/1024
|
| 164 |
+
[decode] steps128_c1024_t1p45 generated 648/1024
|
| 165 |
+
[decode] steps128_c1024_t1p45 generated 652/1024
|
| 166 |
+
[decode] steps128_c1024_t1p45 generated 656/1024
|
| 167 |
+
[decode] steps128_c1024_t1p45 generated 660/1024
|
| 168 |
+
[decode] steps128_c1024_t1p45 generated 664/1024
|
| 169 |
+
[decode] steps128_c1024_t1p45 generated 668/1024
|
| 170 |
+
[decode] steps128_c1024_t1p45 generated 672/1024
|
| 171 |
+
[decode] steps128_c1024_t1p45 generated 676/1024
|
| 172 |
+
[decode] steps128_c1024_t1p45 generated 680/1024
|
| 173 |
+
[decode] steps128_c1024_t1p45 generated 684/1024
|
| 174 |
+
[decode] steps128_c1024_t1p45 generated 688/1024
|
| 175 |
+
[decode] steps128_c1024_t1p45 generated 692/1024
|
| 176 |
+
[decode] steps128_c1024_t1p45 generated 696/1024
|
| 177 |
+
[decode] steps128_c1024_t1p45 generated 700/1024
|
| 178 |
+
[decode] steps128_c1024_t1p45 generated 704/1024
|
| 179 |
+
[decode] steps128_c1024_t1p45 generated 708/1024
|
| 180 |
+
[decode] steps128_c1024_t1p45 generated 712/1024
|
| 181 |
+
[decode] steps128_c1024_t1p45 generated 716/1024
|
| 182 |
+
[decode] steps128_c1024_t1p45 generated 720/1024
|
| 183 |
+
[decode] steps128_c1024_t1p45 generated 724/1024
|
| 184 |
+
[decode] steps128_c1024_t1p45 generated 728/1024
|
| 185 |
+
[decode] steps128_c1024_t1p45 generated 732/1024
|
| 186 |
+
[decode] steps128_c1024_t1p45 generated 736/1024
|
| 187 |
+
[decode] steps128_c1024_t1p45 generated 740/1024
|
| 188 |
+
[decode] steps128_c1024_t1p45 generated 744/1024
|
| 189 |
+
[decode] steps128_c1024_t1p45 generated 748/1024
|
| 190 |
+
[decode] steps128_c1024_t1p45 generated 752/1024
|
| 191 |
+
[decode] steps128_c1024_t1p45 generated 756/1024
|
| 192 |
+
[decode] steps128_c1024_t1p45 generated 760/1024
|
| 193 |
+
[decode] steps128_c1024_t1p45 generated 764/1024
|
| 194 |
+
[decode] steps128_c1024_t1p45 generated 768/1024
|
| 195 |
+
[decode] steps128_c1024_t1p45 generated 772/1024
|
| 196 |
+
[decode] steps128_c1024_t1p45 generated 776/1024
|
| 197 |
+
[decode] steps128_c1024_t1p45 generated 780/1024
|
| 198 |
+
[decode] steps128_c1024_t1p45 generated 784/1024
|
| 199 |
+
[decode] steps128_c1024_t1p45 generated 788/1024
|
| 200 |
+
[decode] steps128_c1024_t1p45 generated 792/1024
|
| 201 |
+
[decode] steps128_c1024_t1p45 generated 796/1024
|
| 202 |
+
[decode] steps128_c1024_t1p45 generated 800/1024
|
| 203 |
+
[decode] steps128_c1024_t1p45 generated 804/1024
|
| 204 |
+
[decode] steps128_c1024_t1p45 generated 808/1024
|
| 205 |
+
[decode] steps128_c1024_t1p45 generated 812/1024
|
| 206 |
+
[decode] steps128_c1024_t1p45 generated 816/1024
|
| 207 |
+
[decode] steps128_c1024_t1p45 generated 820/1024
|
| 208 |
+
[decode] steps128_c1024_t1p45 generated 824/1024
|
| 209 |
+
[decode] steps128_c1024_t1p45 generated 828/1024
|
| 210 |
+
[decode] steps128_c1024_t1p45 generated 832/1024
|
| 211 |
+
[decode] steps128_c1024_t1p45 generated 836/1024
|
| 212 |
+
[decode] steps128_c1024_t1p45 generated 840/1024
|
| 213 |
+
[decode] steps128_c1024_t1p45 generated 844/1024
|
| 214 |
+
[decode] steps128_c1024_t1p45 generated 848/1024
|
| 215 |
+
[decode] steps128_c1024_t1p45 generated 852/1024
|
| 216 |
+
[decode] steps128_c1024_t1p45 generated 856/1024
|
| 217 |
+
[decode] steps128_c1024_t1p45 generated 860/1024
|
| 218 |
+
[decode] steps128_c1024_t1p45 generated 864/1024
|
| 219 |
+
[decode] steps128_c1024_t1p45 generated 868/1024
|
| 220 |
+
[decode] steps128_c1024_t1p45 generated 872/1024
|
| 221 |
+
[decode] steps128_c1024_t1p45 generated 876/1024
|
| 222 |
+
[decode] steps128_c1024_t1p45 generated 880/1024
|
| 223 |
+
[decode] steps128_c1024_t1p45 generated 884/1024
|
| 224 |
+
[decode] steps128_c1024_t1p45 generated 888/1024
|
| 225 |
+
[decode] steps128_c1024_t1p45 generated 892/1024
|
| 226 |
+
[decode] steps128_c1024_t1p45 generated 896/1024
|
| 227 |
+
[decode] steps128_c1024_t1p45 generated 900/1024
|
| 228 |
+
[decode] steps128_c1024_t1p45 generated 904/1024
|
| 229 |
+
[decode] steps128_c1024_t1p45 generated 908/1024
|
| 230 |
+
[decode] steps128_c1024_t1p45 generated 912/1024
|
| 231 |
+
[decode] steps128_c1024_t1p45 generated 916/1024
|
| 232 |
+
[decode] steps128_c1024_t1p45 generated 920/1024
|
| 233 |
+
[decode] steps128_c1024_t1p45 generated 924/1024
|
| 234 |
+
[decode] steps128_c1024_t1p45 generated 928/1024
|
| 235 |
+
[decode] steps128_c1024_t1p45 generated 932/1024
|
| 236 |
+
[decode] steps128_c1024_t1p45 generated 936/1024
|
| 237 |
+
[decode] steps128_c1024_t1p45 generated 940/1024
|
| 238 |
+
[decode] steps128_c1024_t1p45 generated 944/1024
|
| 239 |
+
[decode] steps128_c1024_t1p45 generated 948/1024
|
| 240 |
+
[decode] steps128_c1024_t1p45 generated 952/1024
|
| 241 |
+
[decode] steps128_c1024_t1p45 generated 956/1024
|
| 242 |
+
[decode] steps128_c1024_t1p45 generated 960/1024
|
| 243 |
+
[decode] steps128_c1024_t1p45 generated 964/1024
|
| 244 |
+
[decode] steps128_c1024_t1p45 generated 968/1024
|
| 245 |
+
[decode] steps128_c1024_t1p45 generated 972/1024
|
| 246 |
+
[decode] steps128_c1024_t1p45 generated 976/1024
|
| 247 |
+
[decode] steps128_c1024_t1p45 generated 980/1024
|
| 248 |
+
[decode] steps128_c1024_t1p45 generated 984/1024
|
| 249 |
+
[decode] steps128_c1024_t1p45 generated 988/1024
|
| 250 |
+
[decode] steps128_c1024_t1p45 generated 992/1024
|
| 251 |
+
[decode] steps128_c1024_t1p45 generated 996/1024
|
| 252 |
+
[decode] steps128_c1024_t1p45 generated 1000/1024
|
| 253 |
+
[decode] steps128_c1024_t1p45 generated 1004/1024
|
| 254 |
+
[decode] steps128_c1024_t1p45 generated 1008/1024
|
| 255 |
+
[decode] steps128_c1024_t1p45 generated 1012/1024
|
| 256 |
+
[decode] steps128_c1024_t1p45 generated 1016/1024
|
| 257 |
+
[decode] steps128_c1024_t1p45 generated 1020/1024
|
| 258 |
+
[decode] steps128_c1024_t1p45 generated 1024/1024
|
| 259 |
+
[summary] {"name": "steps128_c1024_t1p45", "step": 10000, "decode_steps": 128, "concentration_max": 1024.0, "raw_genppl": 3.7899707881267246, "stripped_genppl": 3.7899707881267246, "sample_entropy": 0.9235058106966801, "distinct_1": 0.0008497238159179688, "distinct_2": 0.002539253421309873, "top_token_mass": 0.5727787017822266, "raw_kept": 1024, "stripped_kept": 1024}
|
| 260 |
+
[watch-owt-classic] 2026-05-21_19:13:52 done step_0010000
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/__init__.pxd
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
cimport numpy as np
|
| 2 |
+
from libc.stdint cimport uint32_t, uint64_t
|
| 3 |
+
|
| 4 |
+
cdef extern from "numpy/random/bitgen.h":
|
| 5 |
+
struct bitgen:
|
| 6 |
+
void *state
|
| 7 |
+
uint64_t (*next_uint64)(void *st) nogil
|
| 8 |
+
uint32_t (*next_uint32)(void *st) nogil
|
| 9 |
+
double (*next_double)(void *st) nogil
|
| 10 |
+
uint64_t (*next_raw)(void *st) nogil
|
| 11 |
+
|
| 12 |
+
ctypedef bitgen bitgen_t
|
| 13 |
+
|
| 14 |
+
from numpy.random.bit_generator cimport BitGenerator, SeedSequence
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/__init__.py
ADDED
|
@@ -0,0 +1,215 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
========================
|
| 3 |
+
Random Number Generation
|
| 4 |
+
========================
|
| 5 |
+
|
| 6 |
+
Use ``default_rng()`` to create a `Generator` and call its methods.
|
| 7 |
+
|
| 8 |
+
=============== =========================================================
|
| 9 |
+
Generator
|
| 10 |
+
--------------- ---------------------------------------------------------
|
| 11 |
+
Generator Class implementing all of the random number distributions
|
| 12 |
+
default_rng Default constructor for ``Generator``
|
| 13 |
+
=============== =========================================================
|
| 14 |
+
|
| 15 |
+
============================================= ===
|
| 16 |
+
BitGenerator Streams that work with Generator
|
| 17 |
+
--------------------------------------------- ---
|
| 18 |
+
MT19937
|
| 19 |
+
PCG64
|
| 20 |
+
PCG64DXSM
|
| 21 |
+
Philox
|
| 22 |
+
SFC64
|
| 23 |
+
============================================= ===
|
| 24 |
+
|
| 25 |
+
============================================= ===
|
| 26 |
+
Getting entropy to initialize a BitGenerator
|
| 27 |
+
--------------------------------------------- ---
|
| 28 |
+
SeedSequence
|
| 29 |
+
============================================= ===
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
Legacy
|
| 33 |
+
------
|
| 34 |
+
|
| 35 |
+
For backwards compatibility with previous versions of numpy before 1.17, the
|
| 36 |
+
various aliases to the global `RandomState` methods are left alone and do not
|
| 37 |
+
use the new `Generator` API.
|
| 38 |
+
|
| 39 |
+
==================== =========================================================
|
| 40 |
+
Utility functions
|
| 41 |
+
-------------------- ---------------------------------------------------------
|
| 42 |
+
random Uniformly distributed floats over ``[0, 1)``
|
| 43 |
+
bytes Uniformly distributed random bytes.
|
| 44 |
+
permutation Randomly permute a sequence / generate a random sequence.
|
| 45 |
+
shuffle Randomly permute a sequence in place.
|
| 46 |
+
choice Random sample from 1-D array.
|
| 47 |
+
==================== =========================================================
|
| 48 |
+
|
| 49 |
+
==================== =========================================================
|
| 50 |
+
Compatibility
|
| 51 |
+
functions - removed
|
| 52 |
+
in the new API
|
| 53 |
+
-------------------- ---------------------------------------------------------
|
| 54 |
+
rand Uniformly distributed values.
|
| 55 |
+
randn Normally distributed values.
|
| 56 |
+
ranf Uniformly distributed floating point numbers.
|
| 57 |
+
random_integers Uniformly distributed integers in a given range.
|
| 58 |
+
(deprecated, use ``integers(..., closed=True)`` instead)
|
| 59 |
+
random_sample Alias for `random_sample`
|
| 60 |
+
randint Uniformly distributed integers in a given range
|
| 61 |
+
seed Seed the legacy random number generator.
|
| 62 |
+
==================== =========================================================
|
| 63 |
+
|
| 64 |
+
==================== =========================================================
|
| 65 |
+
Univariate
|
| 66 |
+
distributions
|
| 67 |
+
-------------------- ---------------------------------------------------------
|
| 68 |
+
beta Beta distribution over ``[0, 1]``.
|
| 69 |
+
binomial Binomial distribution.
|
| 70 |
+
chisquare :math:`\\chi^2` distribution.
|
| 71 |
+
exponential Exponential distribution.
|
| 72 |
+
f F (Fisher-Snedecor) distribution.
|
| 73 |
+
gamma Gamma distribution.
|
| 74 |
+
geometric Geometric distribution.
|
| 75 |
+
gumbel Gumbel distribution.
|
| 76 |
+
hypergeometric Hypergeometric distribution.
|
| 77 |
+
laplace Laplace distribution.
|
| 78 |
+
logistic Logistic distribution.
|
| 79 |
+
lognormal Log-normal distribution.
|
| 80 |
+
logseries Logarithmic series distribution.
|
| 81 |
+
negative_binomial Negative binomial distribution.
|
| 82 |
+
noncentral_chisquare Non-central chi-square distribution.
|
| 83 |
+
noncentral_f Non-central F distribution.
|
| 84 |
+
normal Normal / Gaussian distribution.
|
| 85 |
+
pareto Pareto distribution.
|
| 86 |
+
poisson Poisson distribution.
|
| 87 |
+
power Power distribution.
|
| 88 |
+
rayleigh Rayleigh distribution.
|
| 89 |
+
triangular Triangular distribution.
|
| 90 |
+
uniform Uniform distribution.
|
| 91 |
+
vonmises Von Mises circular distribution.
|
| 92 |
+
wald Wald (inverse Gaussian) distribution.
|
| 93 |
+
weibull Weibull distribution.
|
| 94 |
+
zipf Zipf's distribution over ranked data.
|
| 95 |
+
==================== =========================================================
|
| 96 |
+
|
| 97 |
+
==================== ==========================================================
|
| 98 |
+
Multivariate
|
| 99 |
+
distributions
|
| 100 |
+
-------------------- ----------------------------------------------------------
|
| 101 |
+
dirichlet Multivariate generalization of Beta distribution.
|
| 102 |
+
multinomial Multivariate generalization of the binomial distribution.
|
| 103 |
+
multivariate_normal Multivariate generalization of the normal distribution.
|
| 104 |
+
==================== ==========================================================
|
| 105 |
+
|
| 106 |
+
==================== =========================================================
|
| 107 |
+
Standard
|
| 108 |
+
distributions
|
| 109 |
+
-------------------- ---------------------------------------------------------
|
| 110 |
+
standard_cauchy Standard Cauchy-Lorentz distribution.
|
| 111 |
+
standard_exponential Standard exponential distribution.
|
| 112 |
+
standard_gamma Standard Gamma distribution.
|
| 113 |
+
standard_normal Standard normal distribution.
|
| 114 |
+
standard_t Standard Student's t-distribution.
|
| 115 |
+
==================== =========================================================
|
| 116 |
+
|
| 117 |
+
==================== =========================================================
|
| 118 |
+
Internal functions
|
| 119 |
+
-------------------- ---------------------------------------------------------
|
| 120 |
+
get_state Get tuple representing internal state of generator.
|
| 121 |
+
set_state Set state of generator.
|
| 122 |
+
==================== =========================================================
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
"""
|
| 126 |
+
__all__ = [
|
| 127 |
+
'beta',
|
| 128 |
+
'binomial',
|
| 129 |
+
'bytes',
|
| 130 |
+
'chisquare',
|
| 131 |
+
'choice',
|
| 132 |
+
'dirichlet',
|
| 133 |
+
'exponential',
|
| 134 |
+
'f',
|
| 135 |
+
'gamma',
|
| 136 |
+
'geometric',
|
| 137 |
+
'get_state',
|
| 138 |
+
'gumbel',
|
| 139 |
+
'hypergeometric',
|
| 140 |
+
'laplace',
|
| 141 |
+
'logistic',
|
| 142 |
+
'lognormal',
|
| 143 |
+
'logseries',
|
| 144 |
+
'multinomial',
|
| 145 |
+
'multivariate_normal',
|
| 146 |
+
'negative_binomial',
|
| 147 |
+
'noncentral_chisquare',
|
| 148 |
+
'noncentral_f',
|
| 149 |
+
'normal',
|
| 150 |
+
'pareto',
|
| 151 |
+
'permutation',
|
| 152 |
+
'poisson',
|
| 153 |
+
'power',
|
| 154 |
+
'rand',
|
| 155 |
+
'randint',
|
| 156 |
+
'randn',
|
| 157 |
+
'random',
|
| 158 |
+
'random_integers',
|
| 159 |
+
'random_sample',
|
| 160 |
+
'ranf',
|
| 161 |
+
'rayleigh',
|
| 162 |
+
'sample',
|
| 163 |
+
'seed',
|
| 164 |
+
'set_state',
|
| 165 |
+
'shuffle',
|
| 166 |
+
'standard_cauchy',
|
| 167 |
+
'standard_exponential',
|
| 168 |
+
'standard_gamma',
|
| 169 |
+
'standard_normal',
|
| 170 |
+
'standard_t',
|
| 171 |
+
'triangular',
|
| 172 |
+
'uniform',
|
| 173 |
+
'vonmises',
|
| 174 |
+
'wald',
|
| 175 |
+
'weibull',
|
| 176 |
+
'zipf',
|
| 177 |
+
]
|
| 178 |
+
|
| 179 |
+
# add these for module-freeze analysis (like PyInstaller)
|
| 180 |
+
from . import _pickle
|
| 181 |
+
from . import _common
|
| 182 |
+
from . import _bounded_integers
|
| 183 |
+
|
| 184 |
+
from ._generator import Generator, default_rng
|
| 185 |
+
from .bit_generator import SeedSequence, BitGenerator
|
| 186 |
+
from ._mt19937 import MT19937
|
| 187 |
+
from ._pcg64 import PCG64, PCG64DXSM
|
| 188 |
+
from ._philox import Philox
|
| 189 |
+
from ._sfc64 import SFC64
|
| 190 |
+
from .mtrand import *
|
| 191 |
+
|
| 192 |
+
__all__ += ['Generator', 'RandomState', 'SeedSequence', 'MT19937',
|
| 193 |
+
'Philox', 'PCG64', 'PCG64DXSM', 'SFC64', 'default_rng',
|
| 194 |
+
'BitGenerator']
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def __RandomState_ctor():
|
| 198 |
+
"""Return a RandomState instance.
|
| 199 |
+
|
| 200 |
+
This function exists solely to assist (un)pickling.
|
| 201 |
+
|
| 202 |
+
Note that the state of the RandomState returned here is irrelevant, as this
|
| 203 |
+
function's entire purpose is to return a newly allocated RandomState whose
|
| 204 |
+
state pickle can set. Consequently the RandomState returned by this function
|
| 205 |
+
is a freshly allocated copy with a seed=0.
|
| 206 |
+
|
| 207 |
+
See https://github.com/numpy/numpy/issues/4763 for a detailed discussion
|
| 208 |
+
|
| 209 |
+
"""
|
| 210 |
+
return RandomState(seed=0)
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
from numpy._pytesttester import PytestTester
|
| 214 |
+
test = PytestTester(__name__)
|
| 215 |
+
del PytestTester
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/__init__.pyi
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from numpy._pytesttester import PytestTester
|
| 2 |
+
|
| 3 |
+
from numpy.random._generator import Generator as Generator
|
| 4 |
+
from numpy.random._generator import default_rng as default_rng
|
| 5 |
+
from numpy.random._mt19937 import MT19937 as MT19937
|
| 6 |
+
from numpy.random._pcg64 import (
|
| 7 |
+
PCG64 as PCG64,
|
| 8 |
+
PCG64DXSM as PCG64DXSM,
|
| 9 |
+
)
|
| 10 |
+
from numpy.random._philox import Philox as Philox
|
| 11 |
+
from numpy.random._sfc64 import SFC64 as SFC64
|
| 12 |
+
from numpy.random.bit_generator import BitGenerator as BitGenerator
|
| 13 |
+
from numpy.random.bit_generator import SeedSequence as SeedSequence
|
| 14 |
+
from numpy.random.mtrand import (
|
| 15 |
+
RandomState as RandomState,
|
| 16 |
+
beta as beta,
|
| 17 |
+
binomial as binomial,
|
| 18 |
+
bytes as bytes,
|
| 19 |
+
chisquare as chisquare,
|
| 20 |
+
choice as choice,
|
| 21 |
+
dirichlet as dirichlet,
|
| 22 |
+
exponential as exponential,
|
| 23 |
+
f as f,
|
| 24 |
+
gamma as gamma,
|
| 25 |
+
geometric as geometric,
|
| 26 |
+
get_bit_generator as get_bit_generator,
|
| 27 |
+
get_state as get_state,
|
| 28 |
+
gumbel as gumbel,
|
| 29 |
+
hypergeometric as hypergeometric,
|
| 30 |
+
laplace as laplace,
|
| 31 |
+
logistic as logistic,
|
| 32 |
+
lognormal as lognormal,
|
| 33 |
+
logseries as logseries,
|
| 34 |
+
multinomial as multinomial,
|
| 35 |
+
multivariate_normal as multivariate_normal,
|
| 36 |
+
negative_binomial as negative_binomial,
|
| 37 |
+
noncentral_chisquare as noncentral_chisquare,
|
| 38 |
+
noncentral_f as noncentral_f,
|
| 39 |
+
normal as normal,
|
| 40 |
+
pareto as pareto,
|
| 41 |
+
permutation as permutation,
|
| 42 |
+
poisson as poisson,
|
| 43 |
+
power as power,
|
| 44 |
+
rand as rand,
|
| 45 |
+
randint as randint,
|
| 46 |
+
randn as randn,
|
| 47 |
+
random as random,
|
| 48 |
+
random_integers as random_integers,
|
| 49 |
+
random_sample as random_sample,
|
| 50 |
+
ranf as ranf,
|
| 51 |
+
rayleigh as rayleigh,
|
| 52 |
+
sample as sample,
|
| 53 |
+
seed as seed,
|
| 54 |
+
set_bit_generator as set_bit_generator,
|
| 55 |
+
set_state as set_state,
|
| 56 |
+
shuffle as shuffle,
|
| 57 |
+
standard_cauchy as standard_cauchy,
|
| 58 |
+
standard_exponential as standard_exponential,
|
| 59 |
+
standard_gamma as standard_gamma,
|
| 60 |
+
standard_normal as standard_normal,
|
| 61 |
+
standard_t as standard_t,
|
| 62 |
+
triangular as triangular,
|
| 63 |
+
uniform as uniform,
|
| 64 |
+
vonmises as vonmises,
|
| 65 |
+
wald as wald,
|
| 66 |
+
weibull as weibull,
|
| 67 |
+
zipf as zipf,
|
| 68 |
+
)
|
| 69 |
+
|
| 70 |
+
__all__: list[str]
|
| 71 |
+
__path__: list[str]
|
| 72 |
+
test: PytestTester
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_common.pxd
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#cython: language_level=3
|
| 2 |
+
|
| 3 |
+
from libc.stdint cimport uint32_t, uint64_t, int32_t, int64_t
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
cimport numpy as np
|
| 7 |
+
|
| 8 |
+
from numpy.random cimport bitgen_t
|
| 9 |
+
|
| 10 |
+
cdef double POISSON_LAM_MAX
|
| 11 |
+
cdef double LEGACY_POISSON_LAM_MAX
|
| 12 |
+
cdef uint64_t MAXSIZE
|
| 13 |
+
|
| 14 |
+
cdef enum ConstraintType:
|
| 15 |
+
CONS_NONE
|
| 16 |
+
CONS_NON_NEGATIVE
|
| 17 |
+
CONS_POSITIVE
|
| 18 |
+
CONS_POSITIVE_NOT_NAN
|
| 19 |
+
CONS_BOUNDED_0_1
|
| 20 |
+
CONS_BOUNDED_GT_0_1
|
| 21 |
+
CONS_BOUNDED_LT_0_1
|
| 22 |
+
CONS_GT_1
|
| 23 |
+
CONS_GTE_1
|
| 24 |
+
CONS_POISSON
|
| 25 |
+
LEGACY_CONS_POISSON
|
| 26 |
+
|
| 27 |
+
ctypedef ConstraintType constraint_type
|
| 28 |
+
|
| 29 |
+
cdef object benchmark(bitgen_t *bitgen, object lock, Py_ssize_t cnt, object method)
|
| 30 |
+
cdef object random_raw(bitgen_t *bitgen, object lock, object size, object output)
|
| 31 |
+
cdef object prepare_cffi(bitgen_t *bitgen)
|
| 32 |
+
cdef object prepare_ctypes(bitgen_t *bitgen)
|
| 33 |
+
cdef int check_constraint(double val, object name, constraint_type cons) except -1
|
| 34 |
+
cdef int check_array_constraint(np.ndarray val, object name, constraint_type cons) except -1
|
| 35 |
+
|
| 36 |
+
cdef extern from "include/aligned_malloc.h":
|
| 37 |
+
cdef void *PyArray_realloc_aligned(void *p, size_t n)
|
| 38 |
+
cdef void *PyArray_malloc_aligned(size_t n)
|
| 39 |
+
cdef void *PyArray_calloc_aligned(size_t n, size_t s)
|
| 40 |
+
cdef void PyArray_free_aligned(void *p)
|
| 41 |
+
|
| 42 |
+
ctypedef void (*random_double_fill)(bitgen_t *state, np.npy_intp count, double* out) noexcept nogil
|
| 43 |
+
ctypedef double (*random_double_0)(void *state) noexcept nogil
|
| 44 |
+
ctypedef double (*random_double_1)(void *state, double a) noexcept nogil
|
| 45 |
+
ctypedef double (*random_double_2)(void *state, double a, double b) noexcept nogil
|
| 46 |
+
ctypedef double (*random_double_3)(void *state, double a, double b, double c) noexcept nogil
|
| 47 |
+
|
| 48 |
+
ctypedef void (*random_float_fill)(bitgen_t *state, np.npy_intp count, float* out) noexcept nogil
|
| 49 |
+
ctypedef float (*random_float_0)(bitgen_t *state) noexcept nogil
|
| 50 |
+
ctypedef float (*random_float_1)(bitgen_t *state, float a) noexcept nogil
|
| 51 |
+
|
| 52 |
+
ctypedef int64_t (*random_uint_0)(void *state) noexcept nogil
|
| 53 |
+
ctypedef int64_t (*random_uint_d)(void *state, double a) noexcept nogil
|
| 54 |
+
ctypedef int64_t (*random_uint_dd)(void *state, double a, double b) noexcept nogil
|
| 55 |
+
ctypedef int64_t (*random_uint_di)(void *state, double a, uint64_t b) noexcept nogil
|
| 56 |
+
ctypedef int64_t (*random_uint_i)(void *state, int64_t a) noexcept nogil
|
| 57 |
+
ctypedef int64_t (*random_uint_iii)(void *state, int64_t a, int64_t b, int64_t c) noexcept nogil
|
| 58 |
+
|
| 59 |
+
ctypedef uint32_t (*random_uint_0_32)(bitgen_t *state) noexcept nogil
|
| 60 |
+
ctypedef uint32_t (*random_uint_1_i_32)(bitgen_t *state, uint32_t a) noexcept nogil
|
| 61 |
+
|
| 62 |
+
ctypedef int32_t (*random_int_2_i_32)(bitgen_t *state, int32_t a, int32_t b) noexcept nogil
|
| 63 |
+
ctypedef int64_t (*random_int_2_i)(bitgen_t *state, int64_t a, int64_t b) noexcept nogil
|
| 64 |
+
|
| 65 |
+
cdef double kahan_sum(double *darr, np.npy_intp n) noexcept
|
| 66 |
+
|
| 67 |
+
cdef inline double uint64_to_double(uint64_t rnd) noexcept nogil:
|
| 68 |
+
return (rnd >> 11) * (1.0 / 9007199254740992.0)
|
| 69 |
+
|
| 70 |
+
cdef object double_fill(void *func, bitgen_t *state, object size, object lock, object out)
|
| 71 |
+
|
| 72 |
+
cdef object float_fill(void *func, bitgen_t *state, object size, object lock, object out)
|
| 73 |
+
|
| 74 |
+
cdef object float_fill_from_double(void *func, bitgen_t *state, object size, object lock, object out)
|
| 75 |
+
|
| 76 |
+
cdef object wrap_int(object val, object bits)
|
| 77 |
+
|
| 78 |
+
cdef np.ndarray int_to_array(object value, object name, object bits, object uint_size)
|
| 79 |
+
|
| 80 |
+
cdef validate_output_shape(iter_shape, np.ndarray output)
|
| 81 |
+
|
| 82 |
+
cdef object cont(void *func, void *state, object size, object lock, int narg,
|
| 83 |
+
object a, object a_name, constraint_type a_constraint,
|
| 84 |
+
object b, object b_name, constraint_type b_constraint,
|
| 85 |
+
object c, object c_name, constraint_type c_constraint,
|
| 86 |
+
object out)
|
| 87 |
+
|
| 88 |
+
cdef object disc(void *func, void *state, object size, object lock,
|
| 89 |
+
int narg_double, int narg_int64,
|
| 90 |
+
object a, object a_name, constraint_type a_constraint,
|
| 91 |
+
object b, object b_name, constraint_type b_constraint,
|
| 92 |
+
object c, object c_name, constraint_type c_constraint)
|
| 93 |
+
|
| 94 |
+
cdef object cont_f(void *func, bitgen_t *state, object size, object lock,
|
| 95 |
+
object a, object a_name, constraint_type a_constraint,
|
| 96 |
+
object out)
|
| 97 |
+
|
| 98 |
+
cdef object cont_broadcast_3(void *func, void *state, object size, object lock,
|
| 99 |
+
np.ndarray a_arr, object a_name, constraint_type a_constraint,
|
| 100 |
+
np.ndarray b_arr, object b_name, constraint_type b_constraint,
|
| 101 |
+
np.ndarray c_arr, object c_name, constraint_type c_constraint)
|
| 102 |
+
|
| 103 |
+
cdef object discrete_broadcast_iii(void *func, void *state, object size, object lock,
|
| 104 |
+
np.ndarray a_arr, object a_name, constraint_type a_constraint,
|
| 105 |
+
np.ndarray b_arr, object b_name, constraint_type b_constraint,
|
| 106 |
+
np.ndarray c_arr, object c_name, constraint_type c_constraint)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_generator.pyi
ADDED
|
@@ -0,0 +1,681 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections.abc import Callable
|
| 2 |
+
from typing import Any, Union, overload, TypeVar, Literal
|
| 3 |
+
|
| 4 |
+
from numpy import (
|
| 5 |
+
bool_,
|
| 6 |
+
dtype,
|
| 7 |
+
float32,
|
| 8 |
+
float64,
|
| 9 |
+
int8,
|
| 10 |
+
int16,
|
| 11 |
+
int32,
|
| 12 |
+
int64,
|
| 13 |
+
int_,
|
| 14 |
+
ndarray,
|
| 15 |
+
uint,
|
| 16 |
+
uint8,
|
| 17 |
+
uint16,
|
| 18 |
+
uint32,
|
| 19 |
+
uint64,
|
| 20 |
+
)
|
| 21 |
+
from numpy.random import BitGenerator, SeedSequence
|
| 22 |
+
from numpy._typing import (
|
| 23 |
+
ArrayLike,
|
| 24 |
+
_ArrayLikeFloat_co,
|
| 25 |
+
_ArrayLikeInt_co,
|
| 26 |
+
_DoubleCodes,
|
| 27 |
+
_DTypeLikeBool,
|
| 28 |
+
_DTypeLikeInt,
|
| 29 |
+
_DTypeLikeUInt,
|
| 30 |
+
_Float32Codes,
|
| 31 |
+
_Float64Codes,
|
| 32 |
+
_FloatLike_co,
|
| 33 |
+
_Int8Codes,
|
| 34 |
+
_Int16Codes,
|
| 35 |
+
_Int32Codes,
|
| 36 |
+
_Int64Codes,
|
| 37 |
+
_IntCodes,
|
| 38 |
+
_ShapeLike,
|
| 39 |
+
_SingleCodes,
|
| 40 |
+
_SupportsDType,
|
| 41 |
+
_UInt8Codes,
|
| 42 |
+
_UInt16Codes,
|
| 43 |
+
_UInt32Codes,
|
| 44 |
+
_UInt64Codes,
|
| 45 |
+
_UIntCodes,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
_ArrayType = TypeVar("_ArrayType", bound=ndarray[Any, Any])
|
| 49 |
+
|
| 50 |
+
_DTypeLikeFloat32 = Union[
|
| 51 |
+
dtype[float32],
|
| 52 |
+
_SupportsDType[dtype[float32]],
|
| 53 |
+
type[float32],
|
| 54 |
+
_Float32Codes,
|
| 55 |
+
_SingleCodes,
|
| 56 |
+
]
|
| 57 |
+
|
| 58 |
+
_DTypeLikeFloat64 = Union[
|
| 59 |
+
dtype[float64],
|
| 60 |
+
_SupportsDType[dtype[float64]],
|
| 61 |
+
type[float],
|
| 62 |
+
type[float64],
|
| 63 |
+
_Float64Codes,
|
| 64 |
+
_DoubleCodes,
|
| 65 |
+
]
|
| 66 |
+
|
| 67 |
+
class Generator:
|
| 68 |
+
def __init__(self, bit_generator: BitGenerator) -> None: ...
|
| 69 |
+
def __repr__(self) -> str: ...
|
| 70 |
+
def __str__(self) -> str: ...
|
| 71 |
+
def __getstate__(self) -> dict[str, Any]: ...
|
| 72 |
+
def __setstate__(self, state: dict[str, Any]) -> None: ...
|
| 73 |
+
def __reduce__(self) -> tuple[Callable[[str], Generator], tuple[str], dict[str, Any]]: ...
|
| 74 |
+
@property
|
| 75 |
+
def bit_generator(self) -> BitGenerator: ...
|
| 76 |
+
def spawn(self, n_children: int) -> list[Generator]: ...
|
| 77 |
+
def bytes(self, length: int) -> bytes: ...
|
| 78 |
+
@overload
|
| 79 |
+
def standard_normal( # type: ignore[misc]
|
| 80 |
+
self,
|
| 81 |
+
size: None = ...,
|
| 82 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 83 |
+
out: None = ...,
|
| 84 |
+
) -> float: ...
|
| 85 |
+
@overload
|
| 86 |
+
def standard_normal( # type: ignore[misc]
|
| 87 |
+
self,
|
| 88 |
+
size: _ShapeLike = ...,
|
| 89 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 90 |
+
@overload
|
| 91 |
+
def standard_normal( # type: ignore[misc]
|
| 92 |
+
self,
|
| 93 |
+
*,
|
| 94 |
+
out: ndarray[Any, dtype[float64]] = ...,
|
| 95 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 96 |
+
@overload
|
| 97 |
+
def standard_normal( # type: ignore[misc]
|
| 98 |
+
self,
|
| 99 |
+
size: _ShapeLike = ...,
|
| 100 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 101 |
+
out: None | ndarray[Any, dtype[float32]] = ...,
|
| 102 |
+
) -> ndarray[Any, dtype[float32]]: ...
|
| 103 |
+
@overload
|
| 104 |
+
def standard_normal( # type: ignore[misc]
|
| 105 |
+
self,
|
| 106 |
+
size: _ShapeLike = ...,
|
| 107 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 108 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 109 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 110 |
+
@overload
|
| 111 |
+
def permutation(self, x: int, axis: int = ...) -> ndarray[Any, dtype[int64]]: ...
|
| 112 |
+
@overload
|
| 113 |
+
def permutation(self, x: ArrayLike, axis: int = ...) -> ndarray[Any, Any]: ...
|
| 114 |
+
@overload
|
| 115 |
+
def standard_exponential( # type: ignore[misc]
|
| 116 |
+
self,
|
| 117 |
+
size: None = ...,
|
| 118 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 119 |
+
method: Literal["zig", "inv"] = ...,
|
| 120 |
+
out: None = ...,
|
| 121 |
+
) -> float: ...
|
| 122 |
+
@overload
|
| 123 |
+
def standard_exponential(
|
| 124 |
+
self,
|
| 125 |
+
size: _ShapeLike = ...,
|
| 126 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 127 |
+
@overload
|
| 128 |
+
def standard_exponential(
|
| 129 |
+
self,
|
| 130 |
+
*,
|
| 131 |
+
out: ndarray[Any, dtype[float64]] = ...,
|
| 132 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 133 |
+
@overload
|
| 134 |
+
def standard_exponential(
|
| 135 |
+
self,
|
| 136 |
+
size: _ShapeLike = ...,
|
| 137 |
+
*,
|
| 138 |
+
method: Literal["zig", "inv"] = ...,
|
| 139 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 140 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 141 |
+
@overload
|
| 142 |
+
def standard_exponential(
|
| 143 |
+
self,
|
| 144 |
+
size: _ShapeLike = ...,
|
| 145 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 146 |
+
method: Literal["zig", "inv"] = ...,
|
| 147 |
+
out: None | ndarray[Any, dtype[float32]] = ...,
|
| 148 |
+
) -> ndarray[Any, dtype[float32]]: ...
|
| 149 |
+
@overload
|
| 150 |
+
def standard_exponential(
|
| 151 |
+
self,
|
| 152 |
+
size: _ShapeLike = ...,
|
| 153 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 154 |
+
method: Literal["zig", "inv"] = ...,
|
| 155 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 156 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 157 |
+
@overload
|
| 158 |
+
def random( # type: ignore[misc]
|
| 159 |
+
self,
|
| 160 |
+
size: None = ...,
|
| 161 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 162 |
+
out: None = ...,
|
| 163 |
+
) -> float: ...
|
| 164 |
+
@overload
|
| 165 |
+
def random(
|
| 166 |
+
self,
|
| 167 |
+
*,
|
| 168 |
+
out: ndarray[Any, dtype[float64]] = ...,
|
| 169 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 170 |
+
@overload
|
| 171 |
+
def random(
|
| 172 |
+
self,
|
| 173 |
+
size: _ShapeLike = ...,
|
| 174 |
+
*,
|
| 175 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 176 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 177 |
+
@overload
|
| 178 |
+
def random(
|
| 179 |
+
self,
|
| 180 |
+
size: _ShapeLike = ...,
|
| 181 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 182 |
+
out: None | ndarray[Any, dtype[float32]] = ...,
|
| 183 |
+
) -> ndarray[Any, dtype[float32]]: ...
|
| 184 |
+
@overload
|
| 185 |
+
def random(
|
| 186 |
+
self,
|
| 187 |
+
size: _ShapeLike = ...,
|
| 188 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 189 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 190 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 191 |
+
@overload
|
| 192 |
+
def beta(
|
| 193 |
+
self,
|
| 194 |
+
a: _FloatLike_co,
|
| 195 |
+
b: _FloatLike_co,
|
| 196 |
+
size: None = ...,
|
| 197 |
+
) -> float: ... # type: ignore[misc]
|
| 198 |
+
@overload
|
| 199 |
+
def beta(
|
| 200 |
+
self, a: _ArrayLikeFloat_co, b: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 201 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 202 |
+
@overload
|
| 203 |
+
def exponential(self, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 204 |
+
@overload
|
| 205 |
+
def exponential(
|
| 206 |
+
self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 207 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 208 |
+
@overload
|
| 209 |
+
def integers( # type: ignore[misc]
|
| 210 |
+
self,
|
| 211 |
+
low: int,
|
| 212 |
+
high: None | int = ...,
|
| 213 |
+
) -> int: ...
|
| 214 |
+
@overload
|
| 215 |
+
def integers( # type: ignore[misc]
|
| 216 |
+
self,
|
| 217 |
+
low: int,
|
| 218 |
+
high: None | int = ...,
|
| 219 |
+
size: None = ...,
|
| 220 |
+
dtype: _DTypeLikeBool = ...,
|
| 221 |
+
endpoint: bool = ...,
|
| 222 |
+
) -> bool: ...
|
| 223 |
+
@overload
|
| 224 |
+
def integers( # type: ignore[misc]
|
| 225 |
+
self,
|
| 226 |
+
low: int,
|
| 227 |
+
high: None | int = ...,
|
| 228 |
+
size: None = ...,
|
| 229 |
+
dtype: _DTypeLikeInt | _DTypeLikeUInt = ...,
|
| 230 |
+
endpoint: bool = ...,
|
| 231 |
+
) -> int: ...
|
| 232 |
+
@overload
|
| 233 |
+
def integers( # type: ignore[misc]
|
| 234 |
+
self,
|
| 235 |
+
low: _ArrayLikeInt_co,
|
| 236 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 237 |
+
size: None | _ShapeLike = ...,
|
| 238 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 239 |
+
@overload
|
| 240 |
+
def integers( # type: ignore[misc]
|
| 241 |
+
self,
|
| 242 |
+
low: _ArrayLikeInt_co,
|
| 243 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 244 |
+
size: None | _ShapeLike = ...,
|
| 245 |
+
dtype: _DTypeLikeBool = ...,
|
| 246 |
+
endpoint: bool = ...,
|
| 247 |
+
) -> ndarray[Any, dtype[bool_]]: ...
|
| 248 |
+
@overload
|
| 249 |
+
def integers( # type: ignore[misc]
|
| 250 |
+
self,
|
| 251 |
+
low: _ArrayLikeInt_co,
|
| 252 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 253 |
+
size: None | _ShapeLike = ...,
|
| 254 |
+
dtype: dtype[int8] | type[int8] | _Int8Codes | _SupportsDType[dtype[int8]] = ...,
|
| 255 |
+
endpoint: bool = ...,
|
| 256 |
+
) -> ndarray[Any, dtype[int8]]: ...
|
| 257 |
+
@overload
|
| 258 |
+
def integers( # type: ignore[misc]
|
| 259 |
+
self,
|
| 260 |
+
low: _ArrayLikeInt_co,
|
| 261 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 262 |
+
size: None | _ShapeLike = ...,
|
| 263 |
+
dtype: dtype[int16] | type[int16] | _Int16Codes | _SupportsDType[dtype[int16]] = ...,
|
| 264 |
+
endpoint: bool = ...,
|
| 265 |
+
) -> ndarray[Any, dtype[int16]]: ...
|
| 266 |
+
@overload
|
| 267 |
+
def integers( # type: ignore[misc]
|
| 268 |
+
self,
|
| 269 |
+
low: _ArrayLikeInt_co,
|
| 270 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 271 |
+
size: None | _ShapeLike = ...,
|
| 272 |
+
dtype: dtype[int32] | type[int32] | _Int32Codes | _SupportsDType[dtype[int32]] = ...,
|
| 273 |
+
endpoint: bool = ...,
|
| 274 |
+
) -> ndarray[Any, dtype[int32]]: ...
|
| 275 |
+
@overload
|
| 276 |
+
def integers( # type: ignore[misc]
|
| 277 |
+
self,
|
| 278 |
+
low: _ArrayLikeInt_co,
|
| 279 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 280 |
+
size: None | _ShapeLike = ...,
|
| 281 |
+
dtype: None | dtype[int64] | type[int64] | _Int64Codes | _SupportsDType[dtype[int64]] = ...,
|
| 282 |
+
endpoint: bool = ...,
|
| 283 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 284 |
+
@overload
|
| 285 |
+
def integers( # type: ignore[misc]
|
| 286 |
+
self,
|
| 287 |
+
low: _ArrayLikeInt_co,
|
| 288 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 289 |
+
size: None | _ShapeLike = ...,
|
| 290 |
+
dtype: dtype[uint8] | type[uint8] | _UInt8Codes | _SupportsDType[dtype[uint8]] = ...,
|
| 291 |
+
endpoint: bool = ...,
|
| 292 |
+
) -> ndarray[Any, dtype[uint8]]: ...
|
| 293 |
+
@overload
|
| 294 |
+
def integers( # type: ignore[misc]
|
| 295 |
+
self,
|
| 296 |
+
low: _ArrayLikeInt_co,
|
| 297 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 298 |
+
size: None | _ShapeLike = ...,
|
| 299 |
+
dtype: dtype[uint16] | type[uint16] | _UInt16Codes | _SupportsDType[dtype[uint16]] = ...,
|
| 300 |
+
endpoint: bool = ...,
|
| 301 |
+
) -> ndarray[Any, dtype[uint16]]: ...
|
| 302 |
+
@overload
|
| 303 |
+
def integers( # type: ignore[misc]
|
| 304 |
+
self,
|
| 305 |
+
low: _ArrayLikeInt_co,
|
| 306 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 307 |
+
size: None | _ShapeLike = ...,
|
| 308 |
+
dtype: dtype[uint32] | type[uint32] | _UInt32Codes | _SupportsDType[dtype[uint32]] = ...,
|
| 309 |
+
endpoint: bool = ...,
|
| 310 |
+
) -> ndarray[Any, dtype[uint32]]: ...
|
| 311 |
+
@overload
|
| 312 |
+
def integers( # type: ignore[misc]
|
| 313 |
+
self,
|
| 314 |
+
low: _ArrayLikeInt_co,
|
| 315 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 316 |
+
size: None | _ShapeLike = ...,
|
| 317 |
+
dtype: dtype[uint64] | type[uint64] | _UInt64Codes | _SupportsDType[dtype[uint64]] = ...,
|
| 318 |
+
endpoint: bool = ...,
|
| 319 |
+
) -> ndarray[Any, dtype[uint64]]: ...
|
| 320 |
+
@overload
|
| 321 |
+
def integers( # type: ignore[misc]
|
| 322 |
+
self,
|
| 323 |
+
low: _ArrayLikeInt_co,
|
| 324 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 325 |
+
size: None | _ShapeLike = ...,
|
| 326 |
+
dtype: dtype[int_] | type[int] | type[int_] | _IntCodes | _SupportsDType[dtype[int_]] = ...,
|
| 327 |
+
endpoint: bool = ...,
|
| 328 |
+
) -> ndarray[Any, dtype[int_]]: ...
|
| 329 |
+
@overload
|
| 330 |
+
def integers( # type: ignore[misc]
|
| 331 |
+
self,
|
| 332 |
+
low: _ArrayLikeInt_co,
|
| 333 |
+
high: None | _ArrayLikeInt_co = ...,
|
| 334 |
+
size: None | _ShapeLike = ...,
|
| 335 |
+
dtype: dtype[uint] | type[uint] | _UIntCodes | _SupportsDType[dtype[uint]] = ...,
|
| 336 |
+
endpoint: bool = ...,
|
| 337 |
+
) -> ndarray[Any, dtype[uint]]: ...
|
| 338 |
+
# TODO: Use a TypeVar _T here to get away from Any output? Should be int->ndarray[Any,dtype[int64]], ArrayLike[_T] -> _T | ndarray[Any,Any]
|
| 339 |
+
@overload
|
| 340 |
+
def choice(
|
| 341 |
+
self,
|
| 342 |
+
a: int,
|
| 343 |
+
size: None = ...,
|
| 344 |
+
replace: bool = ...,
|
| 345 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 346 |
+
axis: int = ...,
|
| 347 |
+
shuffle: bool = ...,
|
| 348 |
+
) -> int: ...
|
| 349 |
+
@overload
|
| 350 |
+
def choice(
|
| 351 |
+
self,
|
| 352 |
+
a: int,
|
| 353 |
+
size: _ShapeLike = ...,
|
| 354 |
+
replace: bool = ...,
|
| 355 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 356 |
+
axis: int = ...,
|
| 357 |
+
shuffle: bool = ...,
|
| 358 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 359 |
+
@overload
|
| 360 |
+
def choice(
|
| 361 |
+
self,
|
| 362 |
+
a: ArrayLike,
|
| 363 |
+
size: None = ...,
|
| 364 |
+
replace: bool = ...,
|
| 365 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 366 |
+
axis: int = ...,
|
| 367 |
+
shuffle: bool = ...,
|
| 368 |
+
) -> Any: ...
|
| 369 |
+
@overload
|
| 370 |
+
def choice(
|
| 371 |
+
self,
|
| 372 |
+
a: ArrayLike,
|
| 373 |
+
size: _ShapeLike = ...,
|
| 374 |
+
replace: bool = ...,
|
| 375 |
+
p: None | _ArrayLikeFloat_co = ...,
|
| 376 |
+
axis: int = ...,
|
| 377 |
+
shuffle: bool = ...,
|
| 378 |
+
) -> ndarray[Any, Any]: ...
|
| 379 |
+
@overload
|
| 380 |
+
def uniform(
|
| 381 |
+
self,
|
| 382 |
+
low: _FloatLike_co = ...,
|
| 383 |
+
high: _FloatLike_co = ...,
|
| 384 |
+
size: None = ...,
|
| 385 |
+
) -> float: ... # type: ignore[misc]
|
| 386 |
+
@overload
|
| 387 |
+
def uniform(
|
| 388 |
+
self,
|
| 389 |
+
low: _ArrayLikeFloat_co = ...,
|
| 390 |
+
high: _ArrayLikeFloat_co = ...,
|
| 391 |
+
size: None | _ShapeLike = ...,
|
| 392 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 393 |
+
@overload
|
| 394 |
+
def normal(
|
| 395 |
+
self,
|
| 396 |
+
loc: _FloatLike_co = ...,
|
| 397 |
+
scale: _FloatLike_co = ...,
|
| 398 |
+
size: None = ...,
|
| 399 |
+
) -> float: ... # type: ignore[misc]
|
| 400 |
+
@overload
|
| 401 |
+
def normal(
|
| 402 |
+
self,
|
| 403 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 404 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 405 |
+
size: None | _ShapeLike = ...,
|
| 406 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 407 |
+
@overload
|
| 408 |
+
def standard_gamma( # type: ignore[misc]
|
| 409 |
+
self,
|
| 410 |
+
shape: _FloatLike_co,
|
| 411 |
+
size: None = ...,
|
| 412 |
+
dtype: _DTypeLikeFloat32 | _DTypeLikeFloat64 = ...,
|
| 413 |
+
out: None = ...,
|
| 414 |
+
) -> float: ...
|
| 415 |
+
@overload
|
| 416 |
+
def standard_gamma(
|
| 417 |
+
self,
|
| 418 |
+
shape: _ArrayLikeFloat_co,
|
| 419 |
+
size: None | _ShapeLike = ...,
|
| 420 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 421 |
+
@overload
|
| 422 |
+
def standard_gamma(
|
| 423 |
+
self,
|
| 424 |
+
shape: _ArrayLikeFloat_co,
|
| 425 |
+
*,
|
| 426 |
+
out: ndarray[Any, dtype[float64]] = ...,
|
| 427 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 428 |
+
@overload
|
| 429 |
+
def standard_gamma(
|
| 430 |
+
self,
|
| 431 |
+
shape: _ArrayLikeFloat_co,
|
| 432 |
+
size: None | _ShapeLike = ...,
|
| 433 |
+
dtype: _DTypeLikeFloat32 = ...,
|
| 434 |
+
out: None | ndarray[Any, dtype[float32]] = ...,
|
| 435 |
+
) -> ndarray[Any, dtype[float32]]: ...
|
| 436 |
+
@overload
|
| 437 |
+
def standard_gamma(
|
| 438 |
+
self,
|
| 439 |
+
shape: _ArrayLikeFloat_co,
|
| 440 |
+
size: None | _ShapeLike = ...,
|
| 441 |
+
dtype: _DTypeLikeFloat64 = ...,
|
| 442 |
+
out: None | ndarray[Any, dtype[float64]] = ...,
|
| 443 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 444 |
+
@overload
|
| 445 |
+
def gamma(self, shape: _FloatLike_co, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 446 |
+
@overload
|
| 447 |
+
def gamma(
|
| 448 |
+
self,
|
| 449 |
+
shape: _ArrayLikeFloat_co,
|
| 450 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 451 |
+
size: None | _ShapeLike = ...,
|
| 452 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 453 |
+
@overload
|
| 454 |
+
def f(self, dfnum: _FloatLike_co, dfden: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 455 |
+
@overload
|
| 456 |
+
def f(
|
| 457 |
+
self, dfnum: _ArrayLikeFloat_co, dfden: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 458 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 459 |
+
@overload
|
| 460 |
+
def noncentral_f(self, dfnum: _FloatLike_co, dfden: _FloatLike_co, nonc: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 461 |
+
@overload
|
| 462 |
+
def noncentral_f(
|
| 463 |
+
self,
|
| 464 |
+
dfnum: _ArrayLikeFloat_co,
|
| 465 |
+
dfden: _ArrayLikeFloat_co,
|
| 466 |
+
nonc: _ArrayLikeFloat_co,
|
| 467 |
+
size: None | _ShapeLike = ...,
|
| 468 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 469 |
+
@overload
|
| 470 |
+
def chisquare(self, df: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 471 |
+
@overload
|
| 472 |
+
def chisquare(
|
| 473 |
+
self, df: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 474 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 475 |
+
@overload
|
| 476 |
+
def noncentral_chisquare(self, df: _FloatLike_co, nonc: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 477 |
+
@overload
|
| 478 |
+
def noncentral_chisquare(
|
| 479 |
+
self, df: _ArrayLikeFloat_co, nonc: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 480 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 481 |
+
@overload
|
| 482 |
+
def standard_t(self, df: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 483 |
+
@overload
|
| 484 |
+
def standard_t(
|
| 485 |
+
self, df: _ArrayLikeFloat_co, size: None = ...
|
| 486 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 487 |
+
@overload
|
| 488 |
+
def standard_t(
|
| 489 |
+
self, df: _ArrayLikeFloat_co, size: _ShapeLike = ...
|
| 490 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 491 |
+
@overload
|
| 492 |
+
def vonmises(self, mu: _FloatLike_co, kappa: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 493 |
+
@overload
|
| 494 |
+
def vonmises(
|
| 495 |
+
self, mu: _ArrayLikeFloat_co, kappa: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 496 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 497 |
+
@overload
|
| 498 |
+
def pareto(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 499 |
+
@overload
|
| 500 |
+
def pareto(
|
| 501 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 502 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 503 |
+
@overload
|
| 504 |
+
def weibull(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 505 |
+
@overload
|
| 506 |
+
def weibull(
|
| 507 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 508 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 509 |
+
@overload
|
| 510 |
+
def power(self, a: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 511 |
+
@overload
|
| 512 |
+
def power(
|
| 513 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 514 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 515 |
+
@overload
|
| 516 |
+
def standard_cauchy(self, size: None = ...) -> float: ... # type: ignore[misc]
|
| 517 |
+
@overload
|
| 518 |
+
def standard_cauchy(self, size: _ShapeLike = ...) -> ndarray[Any, dtype[float64]]: ...
|
| 519 |
+
@overload
|
| 520 |
+
def laplace(
|
| 521 |
+
self,
|
| 522 |
+
loc: _FloatLike_co = ...,
|
| 523 |
+
scale: _FloatLike_co = ...,
|
| 524 |
+
size: None = ...,
|
| 525 |
+
) -> float: ... # type: ignore[misc]
|
| 526 |
+
@overload
|
| 527 |
+
def laplace(
|
| 528 |
+
self,
|
| 529 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 530 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 531 |
+
size: None | _ShapeLike = ...,
|
| 532 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 533 |
+
@overload
|
| 534 |
+
def gumbel(
|
| 535 |
+
self,
|
| 536 |
+
loc: _FloatLike_co = ...,
|
| 537 |
+
scale: _FloatLike_co = ...,
|
| 538 |
+
size: None = ...,
|
| 539 |
+
) -> float: ... # type: ignore[misc]
|
| 540 |
+
@overload
|
| 541 |
+
def gumbel(
|
| 542 |
+
self,
|
| 543 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 544 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 545 |
+
size: None | _ShapeLike = ...,
|
| 546 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 547 |
+
@overload
|
| 548 |
+
def logistic(
|
| 549 |
+
self,
|
| 550 |
+
loc: _FloatLike_co = ...,
|
| 551 |
+
scale: _FloatLike_co = ...,
|
| 552 |
+
size: None = ...,
|
| 553 |
+
) -> float: ... # type: ignore[misc]
|
| 554 |
+
@overload
|
| 555 |
+
def logistic(
|
| 556 |
+
self,
|
| 557 |
+
loc: _ArrayLikeFloat_co = ...,
|
| 558 |
+
scale: _ArrayLikeFloat_co = ...,
|
| 559 |
+
size: None | _ShapeLike = ...,
|
| 560 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 561 |
+
@overload
|
| 562 |
+
def lognormal(
|
| 563 |
+
self,
|
| 564 |
+
mean: _FloatLike_co = ...,
|
| 565 |
+
sigma: _FloatLike_co = ...,
|
| 566 |
+
size: None = ...,
|
| 567 |
+
) -> float: ... # type: ignore[misc]
|
| 568 |
+
@overload
|
| 569 |
+
def lognormal(
|
| 570 |
+
self,
|
| 571 |
+
mean: _ArrayLikeFloat_co = ...,
|
| 572 |
+
sigma: _ArrayLikeFloat_co = ...,
|
| 573 |
+
size: None | _ShapeLike = ...,
|
| 574 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 575 |
+
@overload
|
| 576 |
+
def rayleigh(self, scale: _FloatLike_co = ..., size: None = ...) -> float: ... # type: ignore[misc]
|
| 577 |
+
@overload
|
| 578 |
+
def rayleigh(
|
| 579 |
+
self, scale: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 580 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 581 |
+
@overload
|
| 582 |
+
def wald(self, mean: _FloatLike_co, scale: _FloatLike_co, size: None = ...) -> float: ... # type: ignore[misc]
|
| 583 |
+
@overload
|
| 584 |
+
def wald(
|
| 585 |
+
self, mean: _ArrayLikeFloat_co, scale: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 586 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 587 |
+
@overload
|
| 588 |
+
def triangular(
|
| 589 |
+
self,
|
| 590 |
+
left: _FloatLike_co,
|
| 591 |
+
mode: _FloatLike_co,
|
| 592 |
+
right: _FloatLike_co,
|
| 593 |
+
size: None = ...,
|
| 594 |
+
) -> float: ... # type: ignore[misc]
|
| 595 |
+
@overload
|
| 596 |
+
def triangular(
|
| 597 |
+
self,
|
| 598 |
+
left: _ArrayLikeFloat_co,
|
| 599 |
+
mode: _ArrayLikeFloat_co,
|
| 600 |
+
right: _ArrayLikeFloat_co,
|
| 601 |
+
size: None | _ShapeLike = ...,
|
| 602 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 603 |
+
@overload
|
| 604 |
+
def binomial(self, n: int, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 605 |
+
@overload
|
| 606 |
+
def binomial(
|
| 607 |
+
self, n: _ArrayLikeInt_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 608 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 609 |
+
@overload
|
| 610 |
+
def negative_binomial(self, n: _FloatLike_co, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 611 |
+
@overload
|
| 612 |
+
def negative_binomial(
|
| 613 |
+
self, n: _ArrayLikeFloat_co, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 614 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 615 |
+
@overload
|
| 616 |
+
def poisson(self, lam: _FloatLike_co = ..., size: None = ...) -> int: ... # type: ignore[misc]
|
| 617 |
+
@overload
|
| 618 |
+
def poisson(
|
| 619 |
+
self, lam: _ArrayLikeFloat_co = ..., size: None | _ShapeLike = ...
|
| 620 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 621 |
+
@overload
|
| 622 |
+
def zipf(self, a: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 623 |
+
@overload
|
| 624 |
+
def zipf(
|
| 625 |
+
self, a: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 626 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 627 |
+
@overload
|
| 628 |
+
def geometric(self, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 629 |
+
@overload
|
| 630 |
+
def geometric(
|
| 631 |
+
self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 632 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 633 |
+
@overload
|
| 634 |
+
def hypergeometric(self, ngood: int, nbad: int, nsample: int, size: None = ...) -> int: ... # type: ignore[misc]
|
| 635 |
+
@overload
|
| 636 |
+
def hypergeometric(
|
| 637 |
+
self,
|
| 638 |
+
ngood: _ArrayLikeInt_co,
|
| 639 |
+
nbad: _ArrayLikeInt_co,
|
| 640 |
+
nsample: _ArrayLikeInt_co,
|
| 641 |
+
size: None | _ShapeLike = ...,
|
| 642 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 643 |
+
@overload
|
| 644 |
+
def logseries(self, p: _FloatLike_co, size: None = ...) -> int: ... # type: ignore[misc]
|
| 645 |
+
@overload
|
| 646 |
+
def logseries(
|
| 647 |
+
self, p: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 648 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 649 |
+
def multivariate_normal(
|
| 650 |
+
self,
|
| 651 |
+
mean: _ArrayLikeFloat_co,
|
| 652 |
+
cov: _ArrayLikeFloat_co,
|
| 653 |
+
size: None | _ShapeLike = ...,
|
| 654 |
+
check_valid: Literal["warn", "raise", "ignore"] = ...,
|
| 655 |
+
tol: float = ...,
|
| 656 |
+
*,
|
| 657 |
+
method: Literal["svd", "eigh", "cholesky"] = ...,
|
| 658 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 659 |
+
def multinomial(
|
| 660 |
+
self, n: _ArrayLikeInt_co,
|
| 661 |
+
pvals: _ArrayLikeFloat_co,
|
| 662 |
+
size: None | _ShapeLike = ...
|
| 663 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 664 |
+
def multivariate_hypergeometric(
|
| 665 |
+
self,
|
| 666 |
+
colors: _ArrayLikeInt_co,
|
| 667 |
+
nsample: int,
|
| 668 |
+
size: None | _ShapeLike = ...,
|
| 669 |
+
method: Literal["marginals", "count"] = ...,
|
| 670 |
+
) -> ndarray[Any, dtype[int64]]: ...
|
| 671 |
+
def dirichlet(
|
| 672 |
+
self, alpha: _ArrayLikeFloat_co, size: None | _ShapeLike = ...
|
| 673 |
+
) -> ndarray[Any, dtype[float64]]: ...
|
| 674 |
+
def permuted(
|
| 675 |
+
self, x: ArrayLike, *, axis: None | int = ..., out: None | ndarray[Any, Any] = ...
|
| 676 |
+
) -> ndarray[Any, Any]: ...
|
| 677 |
+
def shuffle(self, x: ArrayLike, axis: int = ...) -> None: ...
|
| 678 |
+
|
| 679 |
+
def default_rng(
|
| 680 |
+
seed: None | _ArrayLikeInt_co | SeedSequence | BitGenerator | Generator = ...
|
| 681 |
+
) -> Generator: ...
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_pcg64.pyi
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import TypedDict
|
| 2 |
+
|
| 3 |
+
from numpy.random.bit_generator import BitGenerator, SeedSequence
|
| 4 |
+
from numpy._typing import _ArrayLikeInt_co
|
| 5 |
+
|
| 6 |
+
class _PCG64Internal(TypedDict):
|
| 7 |
+
state: int
|
| 8 |
+
inc: int
|
| 9 |
+
|
| 10 |
+
class _PCG64State(TypedDict):
|
| 11 |
+
bit_generator: str
|
| 12 |
+
state: _PCG64Internal
|
| 13 |
+
has_uint32: int
|
| 14 |
+
uinteger: int
|
| 15 |
+
|
| 16 |
+
class PCG64(BitGenerator):
|
| 17 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
|
| 18 |
+
def jumped(self, jumps: int = ...) -> PCG64: ...
|
| 19 |
+
@property
|
| 20 |
+
def state(
|
| 21 |
+
self,
|
| 22 |
+
) -> _PCG64State: ...
|
| 23 |
+
@state.setter
|
| 24 |
+
def state(
|
| 25 |
+
self,
|
| 26 |
+
value: _PCG64State,
|
| 27 |
+
) -> None: ...
|
| 28 |
+
def advance(self, delta: int) -> PCG64: ...
|
| 29 |
+
|
| 30 |
+
class PCG64DXSM(BitGenerator):
|
| 31 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
|
| 32 |
+
def jumped(self, jumps: int = ...) -> PCG64DXSM: ...
|
| 33 |
+
@property
|
| 34 |
+
def state(
|
| 35 |
+
self,
|
| 36 |
+
) -> _PCG64State: ...
|
| 37 |
+
@state.setter
|
| 38 |
+
def state(
|
| 39 |
+
self,
|
| 40 |
+
value: _PCG64State,
|
| 41 |
+
) -> None: ...
|
| 42 |
+
def advance(self, delta: int) -> PCG64DXSM: ...
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_pickle.py
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .mtrand import RandomState
|
| 2 |
+
from ._philox import Philox
|
| 3 |
+
from ._pcg64 import PCG64, PCG64DXSM
|
| 4 |
+
from ._sfc64 import SFC64
|
| 5 |
+
|
| 6 |
+
from ._generator import Generator
|
| 7 |
+
from ._mt19937 import MT19937
|
| 8 |
+
|
| 9 |
+
BitGenerators = {'MT19937': MT19937,
|
| 10 |
+
'PCG64': PCG64,
|
| 11 |
+
'PCG64DXSM': PCG64DXSM,
|
| 12 |
+
'Philox': Philox,
|
| 13 |
+
'SFC64': SFC64,
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def __bit_generator_ctor(bit_generator_name='MT19937'):
|
| 18 |
+
"""
|
| 19 |
+
Pickling helper function that returns a bit generator object
|
| 20 |
+
|
| 21 |
+
Parameters
|
| 22 |
+
----------
|
| 23 |
+
bit_generator_name : str
|
| 24 |
+
String containing the name of the BitGenerator
|
| 25 |
+
|
| 26 |
+
Returns
|
| 27 |
+
-------
|
| 28 |
+
bit_generator : BitGenerator
|
| 29 |
+
BitGenerator instance
|
| 30 |
+
"""
|
| 31 |
+
if bit_generator_name in BitGenerators:
|
| 32 |
+
bit_generator = BitGenerators[bit_generator_name]
|
| 33 |
+
else:
|
| 34 |
+
raise ValueError(str(bit_generator_name) + ' is not a known '
|
| 35 |
+
'BitGenerator module.')
|
| 36 |
+
|
| 37 |
+
return bit_generator()
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def __generator_ctor(bit_generator_name="MT19937",
|
| 41 |
+
bit_generator_ctor=__bit_generator_ctor):
|
| 42 |
+
"""
|
| 43 |
+
Pickling helper function that returns a Generator object
|
| 44 |
+
|
| 45 |
+
Parameters
|
| 46 |
+
----------
|
| 47 |
+
bit_generator_name : str
|
| 48 |
+
String containing the core BitGenerator's name
|
| 49 |
+
bit_generator_ctor : callable, optional
|
| 50 |
+
Callable function that takes bit_generator_name as its only argument
|
| 51 |
+
and returns an instantized bit generator.
|
| 52 |
+
|
| 53 |
+
Returns
|
| 54 |
+
-------
|
| 55 |
+
rg : Generator
|
| 56 |
+
Generator using the named core BitGenerator
|
| 57 |
+
"""
|
| 58 |
+
return Generator(bit_generator_ctor(bit_generator_name))
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def __randomstate_ctor(bit_generator_name="MT19937",
|
| 62 |
+
bit_generator_ctor=__bit_generator_ctor):
|
| 63 |
+
"""
|
| 64 |
+
Pickling helper function that returns a legacy RandomState-like object
|
| 65 |
+
|
| 66 |
+
Parameters
|
| 67 |
+
----------
|
| 68 |
+
bit_generator_name : str
|
| 69 |
+
String containing the core BitGenerator's name
|
| 70 |
+
bit_generator_ctor : callable, optional
|
| 71 |
+
Callable function that takes bit_generator_name as its only argument
|
| 72 |
+
and returns an instantized bit generator.
|
| 73 |
+
|
| 74 |
+
Returns
|
| 75 |
+
-------
|
| 76 |
+
rs : RandomState
|
| 77 |
+
Legacy RandomState using the named core BitGenerator
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
return RandomState(bit_generator_ctor(bit_generator_name))
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/_sfc64.pyi
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Any, TypedDict
|
| 2 |
+
|
| 3 |
+
from numpy import dtype as dtype
|
| 4 |
+
from numpy import ndarray as ndarray
|
| 5 |
+
from numpy import uint64
|
| 6 |
+
from numpy.random.bit_generator import BitGenerator, SeedSequence
|
| 7 |
+
from numpy._typing import _ArrayLikeInt_co
|
| 8 |
+
|
| 9 |
+
class _SFC64Internal(TypedDict):
|
| 10 |
+
state: ndarray[Any, dtype[uint64]]
|
| 11 |
+
|
| 12 |
+
class _SFC64State(TypedDict):
|
| 13 |
+
bit_generator: str
|
| 14 |
+
state: _SFC64Internal
|
| 15 |
+
has_uint32: int
|
| 16 |
+
uinteger: int
|
| 17 |
+
|
| 18 |
+
class SFC64(BitGenerator):
|
| 19 |
+
def __init__(self, seed: None | _ArrayLikeInt_co | SeedSequence = ...) -> None: ...
|
| 20 |
+
@property
|
| 21 |
+
def state(
|
| 22 |
+
self,
|
| 23 |
+
) -> _SFC64State: ...
|
| 24 |
+
@state.setter
|
| 25 |
+
def state(
|
| 26 |
+
self,
|
| 27 |
+
value: _SFC64State,
|
| 28 |
+
) -> None: ...
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/random/c_distributions.pxd
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!python
|
| 2 |
+
#cython: wraparound=False, nonecheck=False, boundscheck=False, cdivision=True, language_level=3
|
| 3 |
+
from numpy cimport npy_intp
|
| 4 |
+
|
| 5 |
+
from libc.stdint cimport (uint64_t, int32_t, int64_t)
|
| 6 |
+
from numpy.random cimport bitgen_t
|
| 7 |
+
|
| 8 |
+
cdef extern from "numpy/random/distributions.h":
|
| 9 |
+
|
| 10 |
+
struct s_binomial_t:
|
| 11 |
+
int has_binomial
|
| 12 |
+
double psave
|
| 13 |
+
int64_t nsave
|
| 14 |
+
double r
|
| 15 |
+
double q
|
| 16 |
+
double fm
|
| 17 |
+
int64_t m
|
| 18 |
+
double p1
|
| 19 |
+
double xm
|
| 20 |
+
double xl
|
| 21 |
+
double xr
|
| 22 |
+
double c
|
| 23 |
+
double laml
|
| 24 |
+
double lamr
|
| 25 |
+
double p2
|
| 26 |
+
double p3
|
| 27 |
+
double p4
|
| 28 |
+
|
| 29 |
+
ctypedef s_binomial_t binomial_t
|
| 30 |
+
|
| 31 |
+
float random_standard_uniform_f(bitgen_t *bitgen_state) nogil
|
| 32 |
+
double random_standard_uniform(bitgen_t *bitgen_state) nogil
|
| 33 |
+
void random_standard_uniform_fill(bitgen_t* bitgen_state, npy_intp cnt, double *out) nogil
|
| 34 |
+
void random_standard_uniform_fill_f(bitgen_t *bitgen_state, npy_intp cnt, float *out) nogil
|
| 35 |
+
|
| 36 |
+
double random_standard_exponential(bitgen_t *bitgen_state) nogil
|
| 37 |
+
float random_standard_exponential_f(bitgen_t *bitgen_state) nogil
|
| 38 |
+
void random_standard_exponential_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) nogil
|
| 39 |
+
void random_standard_exponential_fill_f(bitgen_t *bitgen_state, npy_intp cnt, float *out) nogil
|
| 40 |
+
void random_standard_exponential_inv_fill(bitgen_t *bitgen_state, npy_intp cnt, double *out) nogil
|
| 41 |
+
void random_standard_exponential_inv_fill_f(bitgen_t *bitgen_state, npy_intp cnt, float *out) nogil
|
| 42 |
+
|
| 43 |
+
double random_standard_normal(bitgen_t* bitgen_state) nogil
|
| 44 |
+
float random_standard_normal_f(bitgen_t *bitgen_state) nogil
|
| 45 |
+
void random_standard_normal_fill(bitgen_t *bitgen_state, npy_intp count, double *out) nogil
|
| 46 |
+
void random_standard_normal_fill_f(bitgen_t *bitgen_state, npy_intp count, float *out) nogil
|
| 47 |
+
double random_standard_gamma(bitgen_t *bitgen_state, double shape) nogil
|
| 48 |
+
float random_standard_gamma_f(bitgen_t *bitgen_state, float shape) nogil
|
| 49 |
+
|
| 50 |
+
float random_standard_uniform_f(bitgen_t *bitgen_state) nogil
|
| 51 |
+
void random_standard_uniform_fill_f(bitgen_t* bitgen_state, npy_intp cnt, float *out) nogil
|
| 52 |
+
float random_standard_normal_f(bitgen_t* bitgen_state) nogil
|
| 53 |
+
float random_standard_gamma_f(bitgen_t *bitgen_state, float shape) nogil
|
| 54 |
+
|
| 55 |
+
int64_t random_positive_int64(bitgen_t *bitgen_state) nogil
|
| 56 |
+
int32_t random_positive_int32(bitgen_t *bitgen_state) nogil
|
| 57 |
+
int64_t random_positive_int(bitgen_t *bitgen_state) nogil
|
| 58 |
+
uint64_t random_uint(bitgen_t *bitgen_state) nogil
|
| 59 |
+
|
| 60 |
+
double random_normal(bitgen_t *bitgen_state, double loc, double scale) nogil
|
| 61 |
+
|
| 62 |
+
double random_gamma(bitgen_t *bitgen_state, double shape, double scale) nogil
|
| 63 |
+
float random_gamma_f(bitgen_t *bitgen_state, float shape, float scale) nogil
|
| 64 |
+
|
| 65 |
+
double random_exponential(bitgen_t *bitgen_state, double scale) nogil
|
| 66 |
+
double random_uniform(bitgen_t *bitgen_state, double lower, double range) nogil
|
| 67 |
+
double random_beta(bitgen_t *bitgen_state, double a, double b) nogil
|
| 68 |
+
double random_chisquare(bitgen_t *bitgen_state, double df) nogil
|
| 69 |
+
double random_f(bitgen_t *bitgen_state, double dfnum, double dfden) nogil
|
| 70 |
+
double random_standard_cauchy(bitgen_t *bitgen_state) nogil
|
| 71 |
+
double random_pareto(bitgen_t *bitgen_state, double a) nogil
|
| 72 |
+
double random_weibull(bitgen_t *bitgen_state, double a) nogil
|
| 73 |
+
double random_power(bitgen_t *bitgen_state, double a) nogil
|
| 74 |
+
double random_laplace(bitgen_t *bitgen_state, double loc, double scale) nogil
|
| 75 |
+
double random_gumbel(bitgen_t *bitgen_state, double loc, double scale) nogil
|
| 76 |
+
double random_logistic(bitgen_t *bitgen_state, double loc, double scale) nogil
|
| 77 |
+
double random_lognormal(bitgen_t *bitgen_state, double mean, double sigma) nogil
|
| 78 |
+
double random_rayleigh(bitgen_t *bitgen_state, double mode) nogil
|
| 79 |
+
double random_standard_t(bitgen_t *bitgen_state, double df) nogil
|
| 80 |
+
double random_noncentral_chisquare(bitgen_t *bitgen_state, double df,
|
| 81 |
+
double nonc) nogil
|
| 82 |
+
double random_noncentral_f(bitgen_t *bitgen_state, double dfnum,
|
| 83 |
+
double dfden, double nonc) nogil
|
| 84 |
+
double random_wald(bitgen_t *bitgen_state, double mean, double scale) nogil
|
| 85 |
+
double random_vonmises(bitgen_t *bitgen_state, double mu, double kappa) nogil
|
| 86 |
+
double random_triangular(bitgen_t *bitgen_state, double left, double mode,
|
| 87 |
+
double right) nogil
|
| 88 |
+
|
| 89 |
+
int64_t random_poisson(bitgen_t *bitgen_state, double lam) nogil
|
| 90 |
+
int64_t random_negative_binomial(bitgen_t *bitgen_state, double n, double p) nogil
|
| 91 |
+
int64_t random_binomial(bitgen_t *bitgen_state, double p, int64_t n, binomial_t *binomial) nogil
|
| 92 |
+
int64_t random_logseries(bitgen_t *bitgen_state, double p) nogil
|
| 93 |
+
int64_t random_geometric_search(bitgen_t *bitgen_state, double p) nogil
|
| 94 |
+
int64_t random_geometric_inversion(bitgen_t *bitgen_state, double p) nogil
|
| 95 |
+
int64_t random_geometric(bitgen_t *bitgen_state, double p) nogil
|
| 96 |
+
int64_t random_zipf(bitgen_t *bitgen_state, double a) nogil
|
| 97 |
+
int64_t random_hypergeometric(bitgen_t *bitgen_state, int64_t good, int64_t bad,
|
| 98 |
+
int64_t sample) nogil
|
| 99 |
+
|
| 100 |
+
uint64_t random_interval(bitgen_t *bitgen_state, uint64_t max) nogil
|
| 101 |
+
|
| 102 |
+
# Generate random uint64 numbers in closed interval [off, off + rng].
|
| 103 |
+
uint64_t random_bounded_uint64(bitgen_t *bitgen_state,
|
| 104 |
+
uint64_t off, uint64_t rng,
|
| 105 |
+
uint64_t mask, bint use_masked) nogil
|
| 106 |
+
|
| 107 |
+
void random_multinomial(bitgen_t *bitgen_state, int64_t n, int64_t *mnix,
|
| 108 |
+
double *pix, npy_intp d, binomial_t *binomial) nogil
|
| 109 |
+
|
| 110 |
+
int random_multivariate_hypergeometric_count(bitgen_t *bitgen_state,
|
| 111 |
+
int64_t total,
|
| 112 |
+
size_t num_colors, int64_t *colors,
|
| 113 |
+
int64_t nsample,
|
| 114 |
+
size_t num_variates, int64_t *variates) nogil
|
| 115 |
+
void random_multivariate_hypergeometric_marginals(bitgen_t *bitgen_state,
|
| 116 |
+
int64_t total,
|
| 117 |
+
size_t num_colors, int64_t *colors,
|
| 118 |
+
int64_t nsample,
|
| 119 |
+
size_t num_variates, int64_t *variates) nogil
|
| 120 |
+
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/fsmt/__init__.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2024 The HuggingFace Team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
from typing import TYPE_CHECKING
|
| 15 |
+
|
| 16 |
+
from ...utils import _LazyModule
|
| 17 |
+
from ...utils.import_utils import define_import_structure
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
if TYPE_CHECKING:
|
| 21 |
+
from .configuration_fsmt import *
|
| 22 |
+
from .modeling_fsmt import *
|
| 23 |
+
from .tokenization_fsmt import *
|
| 24 |
+
else:
|
| 25 |
+
import sys
|
| 26 |
+
|
| 27 |
+
_file = globals()["__file__"]
|
| 28 |
+
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/fsmt/modeling_fsmt.py
ADDED
|
@@ -0,0 +1,1136 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2020 The Facebook AI Research Team Authors and The HuggingFace Inc. team.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
#
|
| 15 |
+
# Original implementation: https://github.com/pytorch/fairseq/tree/master/examples/wmt19
|
| 16 |
+
# Authors:
|
| 17 |
+
# - @alexeib Alexei Baevski
|
| 18 |
+
# - @edunov Sergey Edunov
|
| 19 |
+
# - @michaelauli Michael Auli
|
| 20 |
+
# - @myleott Myle Ott
|
| 21 |
+
# - @nng555 Nathan Ng
|
| 22 |
+
# - David Grangier
|
| 23 |
+
# - Kyra Yee
|
| 24 |
+
#
|
| 25 |
+
# Paper: Facebook FAIR's WMT19 News Translation Task Submission https://huggingface.co/papers/1907.06616
|
| 26 |
+
#
|
| 27 |
+
"""PyTorch Fairseq model, ported from https://github.com/pytorch/fairseq/tree/master/examples/wmt19"""
|
| 28 |
+
|
| 29 |
+
import math
|
| 30 |
+
from typing import Any
|
| 31 |
+
|
| 32 |
+
import torch
|
| 33 |
+
from torch import Tensor, nn
|
| 34 |
+
from torch.nn import CrossEntropyLoss, LayerNorm
|
| 35 |
+
|
| 36 |
+
from ... import initialization as init
|
| 37 |
+
from ...activations import ACT2FN
|
| 38 |
+
from ...cache_utils import Cache, DynamicCache, EncoderDecoderCache
|
| 39 |
+
from ...generation import GenerationMixin
|
| 40 |
+
from ...modeling_outputs import (
|
| 41 |
+
BaseModelOutput,
|
| 42 |
+
BaseModelOutputWithPastAndCrossAttentions,
|
| 43 |
+
Seq2SeqLMOutput,
|
| 44 |
+
Seq2SeqModelOutput,
|
| 45 |
+
)
|
| 46 |
+
from ...modeling_utils import PreTrainedModel
|
| 47 |
+
from ...utils import auto_docstring, logging
|
| 48 |
+
from .configuration_fsmt import FSMTConfig
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
logger = logging.get_logger(__name__)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
# See all FSMT models at https://huggingface.co/models?filter=fsmt
|
| 55 |
+
|
| 56 |
+
# Porting notes:
|
| 57 |
+
# this one is modeled after BartModel*
|
| 58 |
+
#
|
| 59 |
+
# Currently only translation (fairseq also has weights for LM)
|
| 60 |
+
#
|
| 61 |
+
# fairseq provides weights for ru-en, en-ru and de-en, en-de pairs. All have been ported.
|
| 62 |
+
# - ru-en, en-ru use asymmetric vocab
|
| 63 |
+
# - de-en, en-de use a merged single vocab (but the code works as if they are separate)
|
| 64 |
+
#
|
| 65 |
+
# Differences with Bart:
|
| 66 |
+
# - not using bos token
|
| 67 |
+
# - 2 separate vocabs (src and target)
|
| 68 |
+
# - embed weights aren't tied
|
| 69 |
+
# - uses a model Ensemble (but that part isn't ported/implemented yet) - so we
|
| 70 |
+
# aren't getting as good of a BLEU score
|
| 71 |
+
# - uses a projection layer at the end of the decoder
|
| 72 |
+
# - doesn't use final_logits_bias
|
| 73 |
+
# - beam search: stops as soon as num_beams == len(hypos) (whereas transformers
|
| 74 |
+
# is not satisfied there and will continue searching until the next cycles
|
| 75 |
+
# aren't promising something better), comparing BLEU scores - the transformers
|
| 76 |
+
# algorithm is slightly superior, therefore using the latter. But if you want
|
| 77 |
+
# to match fairseq outputs, you need to pass ``early_stopping=True`` to ``generate()``.
|
| 78 |
+
#
|
| 79 |
+
# SinusoidalPositionalEmbedding is slightly different from Bart's - generates
|
| 80 |
+
# different embeddings. This implementation is copied verbatim from fairseq with
|
| 81 |
+
# some small changes to make it work here.
|
| 82 |
+
#
|
| 83 |
+
# Other changes:
|
| 84 |
+
# - doesn't support use_cache as Bart's version does
|
| 85 |
+
#
|
| 86 |
+
#
|
| 87 |
+
# FSMTConfig changes with BartConfig
|
| 88 |
+
#
|
| 89 |
+
# Differences with BART:
|
| 90 |
+
# - src/tgt vocabs aren't shared
|
| 91 |
+
# - token embeddings aren't shared
|
| 92 |
+
# - needs a language pair
|
| 93 |
+
# - scale_embedding are True
|
| 94 |
+
#
|
| 95 |
+
# some unused args were removed too
|
| 96 |
+
#
|
| 97 |
+
#
|
| 98 |
+
# TODO:
|
| 99 |
+
# - port model ensemble (fs uses 4 model checkpoints)
|
| 100 |
+
# - solve beam search discrepancies
|
| 101 |
+
# docstyle-ignore
|
| 102 |
+
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
Here is how to compare BLEU scores against fairseq implementation:
|
| 106 |
+
(don't forget to install sacrebleu: `pip install sacrebleu`)
|
| 107 |
+
|
| 108 |
+
# en-ru
|
| 109 |
+
|
| 110 |
+
export PAIR=en-ru
|
| 111 |
+
export DATA_DIR=data/$PAIR
|
| 112 |
+
export SAVE_DIR=data/$PAIR
|
| 113 |
+
export BS=8
|
| 114 |
+
export NUM_BEAMS=50
|
| 115 |
+
mkdir -p $DATA_DIR
|
| 116 |
+
sacrebleu -t wmt19 -l $PAIR --echo src > $DATA_DIR/val.source
|
| 117 |
+
sacrebleu -t wmt19 -l $PAIR --echo ref > $DATA_DIR/val.target
|
| 118 |
+
echo $PAIR
|
| 119 |
+
PYTHONPATH="src:examples/seq2seq" python examples/seq2seq/run_eval.py facebook/wmt19-$PAIR $DATA_DIR/val.source $SAVE_DIR/test_translations.txt --reference_path $DATA_DIR/val.target --score_path $SAVE_DIR/test_bleu.json --bs $BS --task translation --num_beams $NUM_BEAMS
|
| 120 |
+
|
| 121 |
+
# (fairseq BLEU: 36.4 http://matrix.statmt.org/matrix/output/1914?score_id=37605)
|
| 122 |
+
|
| 123 |
+
|
| 124 |
+
# ru-en
|
| 125 |
+
|
| 126 |
+
export PAIR=ru-en
|
| 127 |
+
export DATA_DIR=data/$PAIR
|
| 128 |
+
export SAVE_DIR=data/$PAIR
|
| 129 |
+
export BS=8
|
| 130 |
+
export NUM_BEAMS=50
|
| 131 |
+
mkdir -p $DATA_DIR
|
| 132 |
+
sacrebleu -t wmt19 -l $PAIR --echo src > $DATA_DIR/val.source
|
| 133 |
+
sacrebleu -t wmt19 -l $PAIR --echo ref > $DATA_DIR/val.target
|
| 134 |
+
PYTHONPATH="src:examples/seq2seq" python examples/seq2seq/run_eval.py facebook/wmt19-$PAIR $DATA_DIR/val.source $SAVE_DIR/test_translations.txt --reference_path $DATA_DIR/val.target --score_path $SAVE_DIR/test_bleu.json --bs $BS --task translation --num_beams $NUM_BEAMS
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
# (fairseq BLEU: 41.3 http://matrix.statmt.org/matrix/output/1907?run_id=6937)
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
# de-en
|
| 141 |
+
|
| 142 |
+
export PAIR=de-en
|
| 143 |
+
export DATA_DIR=data/$PAIR
|
| 144 |
+
export SAVE_DIR=data/$PAIR
|
| 145 |
+
export BS=8
|
| 146 |
+
export NUM_BEAMS=50
|
| 147 |
+
mkdir -p $DATA_DIR
|
| 148 |
+
sacrebleu -t wmt19 -l $PAIR --echo src > $DATA_DIR/val.source
|
| 149 |
+
sacrebleu -t wmt19 -l $PAIR --echo ref > $DATA_DIR/val.target
|
| 150 |
+
echo $PAIR
|
| 151 |
+
PYTHONPATH="src:examples/seq2seq" python examples/seq2seq/run_eval.py facebook/wmt19-$PAIR $DATA_DIR/val.source $SAVE_DIR/test_translations.txt --reference_path $DATA_DIR/val.target --score_path $SAVE_DIR/test_bleu.json --bs $BS --task translation --num_beams $NUM_BEAMS
|
| 152 |
+
|
| 153 |
+
# (fairseq BLEU: 42.3 http://matrix.statmt.org/matrix/output/1902?run_id=6750)
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
# en-de
|
| 158 |
+
|
| 159 |
+
export PAIR=en-de
|
| 160 |
+
export DATA_DIR=data/$PAIR
|
| 161 |
+
export SAVE_DIR=data/$PAIR
|
| 162 |
+
export BS=8
|
| 163 |
+
mkdir -p $DATA_DIR
|
| 164 |
+
sacrebleu -t wmt19 -l $PAIR --echo src > $DATA_DIR/val.source
|
| 165 |
+
sacrebleu -t wmt19 -l $PAIR --echo ref > $DATA_DIR/val.target
|
| 166 |
+
echo $PAIR
|
| 167 |
+
PYTHONPATH="src:examples/seq2seq" python examples/seq2seq/run_eval.py facebook/wmt19-$PAIR $DATA_DIR/val.source $SAVE_DIR/test_translations.txt --reference_path $DATA_DIR/val.target --score_path $SAVE_DIR/test_bleu.json --bs $BS --task translation --num_beams $NUM_BEAMS
|
| 168 |
+
|
| 169 |
+
# (fairseq BLEU: 43.1 http://matrix.statmt.org/matrix/output/1909?run_id=6862)
|
| 170 |
+
|
| 171 |
+
"""
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
def invert_mask(attention_mask):
|
| 175 |
+
"""Turns 1->0, 0->1, False->True, True-> False"""
|
| 176 |
+
assert attention_mask.dim() == 2
|
| 177 |
+
return attention_mask.eq(0)
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
def triu_onnx(x, diagonal=0):
|
| 181 |
+
l = x.shape[0]
|
| 182 |
+
arange = torch.arange(l, device=x.device)
|
| 183 |
+
mask = arange.expand(l, l)
|
| 184 |
+
arange = arange.unsqueeze(-1)
|
| 185 |
+
if diagonal:
|
| 186 |
+
arange = arange + diagonal
|
| 187 |
+
mask = mask >= arange
|
| 188 |
+
return x.masked_fill(mask == 0, 0)
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def _prepare_fsmt_decoder_inputs(
|
| 192 |
+
config,
|
| 193 |
+
input_ids,
|
| 194 |
+
decoder_input_ids=None,
|
| 195 |
+
decoder_padding_mask=None,
|
| 196 |
+
causal_mask_dtype=torch.float32,
|
| 197 |
+
):
|
| 198 |
+
"""
|
| 199 |
+
Prepare masks that ignore padding tokens in the decoder and a causal mask for the decoder if none are provided.
|
| 200 |
+
This mimics the default behavior in fairseq. To override it pass in masks. Note: this is not called during
|
| 201 |
+
generation
|
| 202 |
+
"""
|
| 203 |
+
pad_token_id = config.pad_token_id
|
| 204 |
+
if decoder_input_ids is None:
|
| 205 |
+
decoder_input_ids = shift_tokens_right(input_ids, pad_token_id)
|
| 206 |
+
bsz, tgt_len = decoder_input_ids.size()
|
| 207 |
+
if decoder_padding_mask is None:
|
| 208 |
+
decoder_padding_mask = make_padding_mask(decoder_input_ids, pad_token_id)
|
| 209 |
+
else:
|
| 210 |
+
decoder_padding_mask = invert_mask(decoder_padding_mask)
|
| 211 |
+
causal_mask = triu_onnx(fill_with_neg_inf(torch.zeros(tgt_len, tgt_len, dtype=causal_mask_dtype)), 1).to(
|
| 212 |
+
device=decoder_input_ids.device
|
| 213 |
+
)
|
| 214 |
+
return decoder_input_ids, decoder_padding_mask, causal_mask
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
@auto_docstring
|
| 218 |
+
class PretrainedFSMTModel(PreTrainedModel):
|
| 219 |
+
config: FSMTConfig
|
| 220 |
+
base_model_prefix = "model"
|
| 221 |
+
|
| 222 |
+
@torch.no_grad()
|
| 223 |
+
def _init_weights(self, module):
|
| 224 |
+
std = self.config.init_std
|
| 225 |
+
if isinstance(module, nn.Linear):
|
| 226 |
+
init.normal_(module.weight, mean=0.0, std=std)
|
| 227 |
+
if module.bias is not None:
|
| 228 |
+
init.zeros_(module.bias)
|
| 229 |
+
elif isinstance(module, SinusoidalPositionalEmbedding):
|
| 230 |
+
weight = module.get_embedding(*module.weight.shape, module.padding_idx)
|
| 231 |
+
init.copy_(module.weight, weight)
|
| 232 |
+
elif isinstance(module, nn.Embedding):
|
| 233 |
+
init.normal_(module.weight, mean=0.0, std=std)
|
| 234 |
+
# Here we need the check explicitly, as we slice the weight in the `zeros_` call, so it looses the flag
|
| 235 |
+
if module.padding_idx is not None and not getattr(module.weight, "_is_hf_initialized", False):
|
| 236 |
+
init.zeros_(module.weight[module.padding_idx])
|
| 237 |
+
|
| 238 |
+
@property
|
| 239 |
+
def dummy_inputs(self):
|
| 240 |
+
pad_token = self.config.pad_token_id
|
| 241 |
+
input_ids = torch.tensor([[0, 6, 10, 4, 2], [0, 8, 12, 2, pad_token]], device=self.device)
|
| 242 |
+
dummy_inputs = {
|
| 243 |
+
"attention_mask": input_ids.ne(pad_token),
|
| 244 |
+
"input_ids": input_ids,
|
| 245 |
+
}
|
| 246 |
+
return dummy_inputs
|
| 247 |
+
|
| 248 |
+
|
| 249 |
+
def _make_linear_from_emb(emb):
|
| 250 |
+
vocab_size, emb_size = emb.weight.shape
|
| 251 |
+
lin_layer = nn.Linear(vocab_size, emb_size, bias=False)
|
| 252 |
+
lin_layer.weight.data = emb.weight.data
|
| 253 |
+
return lin_layer
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
# Helper Functions, mostly for making masks
|
| 257 |
+
def _check_shapes(shape_1, shape2):
|
| 258 |
+
if shape_1 != shape2:
|
| 259 |
+
raise AssertionError(f"shape mismatch: {shape_1} != {shape2}")
|
| 260 |
+
|
| 261 |
+
|
| 262 |
+
def shift_tokens_right(input_ids, pad_token_id):
|
| 263 |
+
"""Shift input ids one token to the right, and wrap the last non pad token (usually <eos>)."""
|
| 264 |
+
|
| 265 |
+
# replace possible -100 values in labels by `pad_token_id`
|
| 266 |
+
input_ids.masked_fill_(input_ids == -100, pad_token_id)
|
| 267 |
+
|
| 268 |
+
prev_output_tokens = input_ids.clone()
|
| 269 |
+
index_of_eos = (input_ids.ne(pad_token_id).sum(dim=1) - 1).unsqueeze(-1)
|
| 270 |
+
prev_output_tokens[:, 0] = input_ids.gather(1, index_of_eos).squeeze()
|
| 271 |
+
prev_output_tokens[:, 1:] = input_ids[:, :-1]
|
| 272 |
+
return prev_output_tokens
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def make_padding_mask(input_ids, padding_idx=1):
|
| 276 |
+
"""True for pad tokens"""
|
| 277 |
+
padding_mask = input_ids.eq(padding_idx)
|
| 278 |
+
if not padding_mask.any():
|
| 279 |
+
padding_mask = None
|
| 280 |
+
return padding_mask
|
| 281 |
+
|
| 282 |
+
|
| 283 |
+
# Helper Modules
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
class EncoderLayer(nn.Module):
|
| 287 |
+
def __init__(self, config: FSMTConfig):
|
| 288 |
+
super().__init__()
|
| 289 |
+
self.embed_dim = config.d_model
|
| 290 |
+
self.self_attn = Attention(self.embed_dim, config.encoder_attention_heads, dropout=config.attention_dropout)
|
| 291 |
+
self.self_attn_layer_norm = LayerNorm(self.embed_dim)
|
| 292 |
+
self.dropout = config.dropout
|
| 293 |
+
self.activation_fn = ACT2FN[config.activation_function]
|
| 294 |
+
self.activation_dropout = config.activation_dropout
|
| 295 |
+
self.fc1 = nn.Linear(self.embed_dim, config.encoder_ffn_dim)
|
| 296 |
+
self.fc2 = nn.Linear(config.encoder_ffn_dim, self.embed_dim)
|
| 297 |
+
self.final_layer_norm = LayerNorm(self.embed_dim)
|
| 298 |
+
|
| 299 |
+
def forward(self, x, encoder_padding_mask, output_attentions=False):
|
| 300 |
+
"""
|
| 301 |
+
Args:
|
| 302 |
+
x (`torch.Tensor`): input to the layer of shape *(seq_len, batch, embed_dim)*
|
| 303 |
+
encoder_padding_mask (`torch.ByteTensor`): binary ByteTensor of shape
|
| 304 |
+
*(batch, src_len)* where padding elements are indicated by `1`.
|
| 305 |
+
for t_tgt, t_src is excluded (or masked out), =0 means it is
|
| 306 |
+
included in attention
|
| 307 |
+
|
| 308 |
+
Returns:
|
| 309 |
+
encoded output of shape *(seq_len, batch, embed_dim)*
|
| 310 |
+
"""
|
| 311 |
+
residual = x
|
| 312 |
+
x, attn_weights = self.self_attn(
|
| 313 |
+
query=x,
|
| 314 |
+
key=x,
|
| 315 |
+
key_padding_mask=encoder_padding_mask,
|
| 316 |
+
output_attentions=output_attentions,
|
| 317 |
+
)
|
| 318 |
+
x = nn.functional.dropout(x, p=self.dropout, training=self.training)
|
| 319 |
+
x = residual + x
|
| 320 |
+
x = self.self_attn_layer_norm(x)
|
| 321 |
+
|
| 322 |
+
residual = x
|
| 323 |
+
x = self.activation_fn(self.fc1(x))
|
| 324 |
+
x = nn.functional.dropout(x, p=self.activation_dropout, training=self.training)
|
| 325 |
+
x = self.fc2(x)
|
| 326 |
+
x = nn.functional.dropout(x, p=self.dropout, training=self.training)
|
| 327 |
+
x = residual + x
|
| 328 |
+
x = self.final_layer_norm(x)
|
| 329 |
+
return x, attn_weights
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
class FSMTEncoder(nn.Module):
|
| 333 |
+
"""
|
| 334 |
+
Transformer encoder consisting of *config.encoder_layers* self attention layers. Each layer is a [`EncoderLayer`].
|
| 335 |
+
|
| 336 |
+
Args:
|
| 337 |
+
config: FSMTConfig
|
| 338 |
+
"""
|
| 339 |
+
|
| 340 |
+
def __init__(self, config: FSMTConfig):
|
| 341 |
+
super().__init__()
|
| 342 |
+
self.dropout = config.dropout
|
| 343 |
+
self.layerdrop = config.encoder_layerdrop
|
| 344 |
+
self.padding_idx = config.pad_token_id
|
| 345 |
+
self.embed_tokens = nn.Embedding(config.src_vocab_size, config.d_model, config.pad_token_id)
|
| 346 |
+
embed_dim = self.embed_tokens.embedding_dim
|
| 347 |
+
self.embed_scale = math.sqrt(embed_dim) if config.scale_embedding else 1.0
|
| 348 |
+
self.embed_positions = SinusoidalPositionalEmbedding(
|
| 349 |
+
config.max_position_embeddings + self.padding_idx + 1, embed_dim, self.padding_idx
|
| 350 |
+
)
|
| 351 |
+
self.layers = nn.ModuleList([EncoderLayer(config) for _ in range(config.encoder_layers)]) # type: list[EncoderLayer]
|
| 352 |
+
|
| 353 |
+
def forward(
|
| 354 |
+
self,
|
| 355 |
+
input_ids: torch.Tensor,
|
| 356 |
+
attention_mask: torch.Tensor | None = None,
|
| 357 |
+
inputs_embeds: torch.Tensor | None = None,
|
| 358 |
+
output_attentions: bool = False,
|
| 359 |
+
output_hidden_states: bool = False,
|
| 360 |
+
return_dict: bool = True,
|
| 361 |
+
):
|
| 362 |
+
"""
|
| 363 |
+
Args:
|
| 364 |
+
input_ids (`torch.LongTensor`): tokens in the source language of shape
|
| 365 |
+
*(batch, src_len)*
|
| 366 |
+
attention_mask (`torch.LongTensor`): indicating which indices are padding tokens
|
| 367 |
+
inputs_embeds (`torch.FloatTensor`):
|
| 368 |
+
embedding vectors of shape *(batch, src_len, embed_dim)*
|
| 369 |
+
|
| 370 |
+
Returns:
|
| 371 |
+
BaseModelOutput or Tuple comprised of:
|
| 372 |
+
|
| 373 |
+
- **x** (`torch.Tensor`): the last encoder layer's output of shape *(src_len, batch, embed_dim)*
|
| 374 |
+
- **encoder_states** (`Tuple(torch.FloatTensor)`): all intermediate hidden states of shape *(src_len,
|
| 375 |
+
batch, embed_dim)*. Only populated if *output_hidden_states:* is True.
|
| 376 |
+
- **all_attentions** (`Tuple(torch.FloatTensor)`): Attention weights for each layer.
|
| 377 |
+
During training might not be of length n_layers because of layer dropout.
|
| 378 |
+
"""
|
| 379 |
+
# check attention mask and invert
|
| 380 |
+
if attention_mask is not None:
|
| 381 |
+
attention_mask = invert_mask(attention_mask)
|
| 382 |
+
|
| 383 |
+
if input_ids is not None and inputs_embeds is not None:
|
| 384 |
+
raise ValueError("You cannot specify both input_ids and inputs_embeds at the same time")
|
| 385 |
+
elif input_ids is not None:
|
| 386 |
+
inputs_embeds = self.embed_tokens(input_ids) * self.embed_scale
|
| 387 |
+
embed_pos = self.embed_positions(input_ids)
|
| 388 |
+
elif inputs_embeds is not None:
|
| 389 |
+
inputs_embeds = inputs_embeds * self.embed_scale
|
| 390 |
+
|
| 391 |
+
# We assume zeros hidden states correspond to padding tokens
|
| 392 |
+
# and create `position_ids` where inputs_embeds[:, :, 0] == 0
|
| 393 |
+
position_ids = inputs_embeds[:, :, 0].masked_fill(
|
| 394 |
+
inputs_embeds[:, :, 0].eq(0), self.embed_positions.padding_idx
|
| 395 |
+
)
|
| 396 |
+
|
| 397 |
+
embed_pos = self.embed_positions(position_ids)
|
| 398 |
+
else:
|
| 399 |
+
raise ValueError("You have to specify either input_ids or inputs_embeds")
|
| 400 |
+
|
| 401 |
+
x = inputs_embeds + embed_pos
|
| 402 |
+
x = nn.functional.dropout(x, p=self.dropout, training=self.training)
|
| 403 |
+
|
| 404 |
+
# B x T x C -> T x B x C
|
| 405 |
+
x = x.transpose(0, 1)
|
| 406 |
+
|
| 407 |
+
encoder_states = () if output_hidden_states else None
|
| 408 |
+
all_attentions = () if output_attentions else None
|
| 409 |
+
for idx, encoder_layer in enumerate(self.layers):
|
| 410 |
+
if output_hidden_states:
|
| 411 |
+
x = x.transpose(0, 1) # T x B x C -> B x T x C
|
| 412 |
+
encoder_states += (x,)
|
| 413 |
+
x = x.transpose(0, 1) # B x T x C -> T x B x C
|
| 414 |
+
# add LayerDrop (see https://huggingface.co/papers/1909.11556 for description)
|
| 415 |
+
dropout_probability = torch.rand([])
|
| 416 |
+
if self.training and (dropout_probability < self.layerdrop): # skip the layer
|
| 417 |
+
attn = None
|
| 418 |
+
else:
|
| 419 |
+
x, attn = encoder_layer(
|
| 420 |
+
x,
|
| 421 |
+
attention_mask,
|
| 422 |
+
output_attentions=output_attentions,
|
| 423 |
+
)
|
| 424 |
+
|
| 425 |
+
if output_attentions:
|
| 426 |
+
all_attentions = all_attentions + (attn,)
|
| 427 |
+
|
| 428 |
+
# T x B x C -> B x T x C
|
| 429 |
+
x = x.transpose(0, 1)
|
| 430 |
+
|
| 431 |
+
if output_hidden_states:
|
| 432 |
+
encoder_states += (x,)
|
| 433 |
+
|
| 434 |
+
if not return_dict:
|
| 435 |
+
return tuple(v for v in [x, encoder_states, all_attentions] if v is not None)
|
| 436 |
+
return BaseModelOutput(last_hidden_state=x, hidden_states=encoder_states, attentions=all_attentions)
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
class DecoderLayer(nn.Module):
|
| 440 |
+
def __init__(self, config: FSMTConfig, layer_idx=None):
|
| 441 |
+
super().__init__()
|
| 442 |
+
self.embed_dim = config.d_model
|
| 443 |
+
|
| 444 |
+
self.self_attn = Attention(
|
| 445 |
+
embed_dim=self.embed_dim,
|
| 446 |
+
num_heads=config.decoder_attention_heads,
|
| 447 |
+
dropout=config.attention_dropout,
|
| 448 |
+
layer_idx=layer_idx,
|
| 449 |
+
)
|
| 450 |
+
self.dropout = config.dropout
|
| 451 |
+
self.activation_fn = ACT2FN[config.activation_function]
|
| 452 |
+
self.activation_dropout = config.activation_dropout
|
| 453 |
+
|
| 454 |
+
self.self_attn_layer_norm = LayerNorm(self.embed_dim)
|
| 455 |
+
self.encoder_attn = Attention(
|
| 456 |
+
self.embed_dim,
|
| 457 |
+
config.decoder_attention_heads,
|
| 458 |
+
dropout=config.attention_dropout,
|
| 459 |
+
encoder_decoder_attention=True,
|
| 460 |
+
layer_idx=layer_idx,
|
| 461 |
+
)
|
| 462 |
+
self.encoder_attn_layer_norm = LayerNorm(self.embed_dim)
|
| 463 |
+
self.fc1 = nn.Linear(self.embed_dim, config.decoder_ffn_dim)
|
| 464 |
+
self.fc2 = nn.Linear(config.decoder_ffn_dim, self.embed_dim)
|
| 465 |
+
self.final_layer_norm = LayerNorm(self.embed_dim)
|
| 466 |
+
|
| 467 |
+
def forward(
|
| 468 |
+
self,
|
| 469 |
+
x,
|
| 470 |
+
encoder_hidden_states,
|
| 471 |
+
encoder_attn_mask=None,
|
| 472 |
+
layer_state=None,
|
| 473 |
+
causal_mask=None,
|
| 474 |
+
decoder_padding_mask=None,
|
| 475 |
+
output_attentions=False,
|
| 476 |
+
**kwargs,
|
| 477 |
+
):
|
| 478 |
+
residual = x
|
| 479 |
+
|
| 480 |
+
# Self Attention
|
| 481 |
+
x, self_attn_weights = self.self_attn(
|
| 482 |
+
query=x,
|
| 483 |
+
key=x,
|
| 484 |
+
layer_state=layer_state, # adds keys to layer state
|
| 485 |
+
key_padding_mask=decoder_padding_mask,
|
| 486 |
+
attn_mask=causal_mask,
|
| 487 |
+
output_attentions=output_attentions,
|
| 488 |
+
)
|
| 489 |
+
x = nn.functional.dropout(x, p=self.dropout, training=self.training)
|
| 490 |
+
x = residual + x
|
| 491 |
+
x = self.self_attn_layer_norm(x)
|
| 492 |
+
|
| 493 |
+
# Cross attention
|
| 494 |
+
residual = x
|
| 495 |
+
assert self.encoder_attn.cache_key != self.self_attn.cache_key
|
| 496 |
+
x, cross_attn_weights = self.encoder_attn(
|
| 497 |
+
query=x,
|
| 498 |
+
key=encoder_hidden_states,
|
| 499 |
+
key_padding_mask=encoder_attn_mask,
|
| 500 |
+
layer_state=layer_state, # mutates layer state
|
| 501 |
+
output_attentions=output_attentions,
|
| 502 |
+
)
|
| 503 |
+
x = nn.functional.dropout(x, p=self.dropout, training=self.training)
|
| 504 |
+
x = residual + x
|
| 505 |
+
x = self.encoder_attn_layer_norm(x)
|
| 506 |
+
|
| 507 |
+
# Fully Connected
|
| 508 |
+
residual = x
|
| 509 |
+
x = self.activation_fn(self.fc1(x))
|
| 510 |
+
x = nn.functional.dropout(x, p=self.activation_dropout, training=self.training)
|
| 511 |
+
x = self.fc2(x)
|
| 512 |
+
x = nn.functional.dropout(x, p=self.dropout, training=self.training)
|
| 513 |
+
x = residual + x
|
| 514 |
+
x = self.final_layer_norm(x)
|
| 515 |
+
return (
|
| 516 |
+
x,
|
| 517 |
+
self_attn_weights,
|
| 518 |
+
cross_attn_weights,
|
| 519 |
+
)
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
class FSMTDecoder(nn.Module):
|
| 523 |
+
"""
|
| 524 |
+
Transformer decoder consisting of *config.decoder_layers* layers. Each layer is a [`DecoderLayer`]
|
| 525 |
+
|
| 526 |
+
Args:
|
| 527 |
+
config: FSMTConfig
|
| 528 |
+
embed_tokens (nn.Embedding): output embedding
|
| 529 |
+
"""
|
| 530 |
+
|
| 531 |
+
def __init__(self, config: FSMTConfig):
|
| 532 |
+
super().__init__()
|
| 533 |
+
self.dropout = config.dropout
|
| 534 |
+
self.layerdrop = config.decoder_layerdrop
|
| 535 |
+
self.padding_idx = config.pad_token_id
|
| 536 |
+
self.embed_scale = math.sqrt(config.d_model) if config.scale_embedding else 1.0
|
| 537 |
+
self.embed_tokens = nn.Embedding(config.tgt_vocab_size, config.d_model, self.padding_idx)
|
| 538 |
+
embed_dim = self.embed_tokens.embedding_dim
|
| 539 |
+
self.embed_positions = SinusoidalPositionalEmbedding(
|
| 540 |
+
config.max_position_embeddings + self.padding_idx + 1, embed_dim, self.padding_idx
|
| 541 |
+
)
|
| 542 |
+
self.layers = nn.ModuleList([DecoderLayer(config, layer_idx=i) for i in range(config.decoder_layers)]) # type: list[DecoderLayer]
|
| 543 |
+
self.output_projection = nn.Linear(config.d_model, config.tgt_vocab_size, bias=False)
|
| 544 |
+
|
| 545 |
+
def forward(
|
| 546 |
+
self,
|
| 547 |
+
input_ids: torch.Tensor,
|
| 548 |
+
encoder_hidden_states: torch.Tensor,
|
| 549 |
+
encoder_padding_mask: torch.Tensor,
|
| 550 |
+
decoder_padding_mask: torch.Tensor,
|
| 551 |
+
decoder_causal_mask: torch.Tensor,
|
| 552 |
+
inputs_embeds: torch.Tensor | None = None,
|
| 553 |
+
past_key_values: Cache | None = None,
|
| 554 |
+
use_cache: bool | None = False,
|
| 555 |
+
output_attentions: bool | None = False,
|
| 556 |
+
output_hidden_states: bool | None = False,
|
| 557 |
+
return_dict: bool | None = True,
|
| 558 |
+
**kwargs,
|
| 559 |
+
):
|
| 560 |
+
"""
|
| 561 |
+
Includes several features from "Jointly Learning to Align and Translate with Transformer Models" (Garg et al.,
|
| 562 |
+
EMNLP 2019).
|
| 563 |
+
|
| 564 |
+
Args:
|
| 565 |
+
input_ids (`torch.LongTensor` of shape `(batch, tgt_len)`):
|
| 566 |
+
previous decoder outputs for teacher forcing
|
| 567 |
+
encoder_hidden_states: output from the encoder, used for
|
| 568 |
+
encoder-side attention
|
| 569 |
+
encoder_padding_mask: for ignoring pad tokens
|
| 570 |
+
past_key_values (dict or None): dictionary used for storing state during generation
|
| 571 |
+
|
| 572 |
+
Returns:
|
| 573 |
+
BaseModelOutputWithPast or tuple:
|
| 574 |
+
|
| 575 |
+
- the decoder's features of shape *(batch, tgt_len, embed_dim)*
|
| 576 |
+
- the cache
|
| 577 |
+
- hidden states
|
| 578 |
+
- attentions
|
| 579 |
+
"""
|
| 580 |
+
# check attention mask and invert
|
| 581 |
+
if encoder_padding_mask is not None:
|
| 582 |
+
encoder_padding_mask = invert_mask(encoder_padding_mask)
|
| 583 |
+
|
| 584 |
+
if input_ids is not None and inputs_embeds is not None:
|
| 585 |
+
raise ValueError("You cannot specify both decoder_input_ids and decoder_inputs_embeds at the same time")
|
| 586 |
+
elif input_ids is not None:
|
| 587 |
+
# embed positions
|
| 588 |
+
positions = self.embed_positions(input_ids)
|
| 589 |
+
if use_cache:
|
| 590 |
+
input_ids = input_ids[:, -1:]
|
| 591 |
+
positions = positions[:, -1:] # happens after we embed them
|
| 592 |
+
x = self.embed_tokens(input_ids) * self.embed_scale
|
| 593 |
+
elif inputs_embeds is not None:
|
| 594 |
+
# We assume zeros hidden states correspond to padding tokens
|
| 595 |
+
# and create `position_ids` where inputs_embeds[:, :, 0] == 0
|
| 596 |
+
position_ids = inputs_embeds[:, :, 0].masked_fill(
|
| 597 |
+
inputs_embeds[:, :, 0].eq(0), self.embed_positions.padding_idx
|
| 598 |
+
)
|
| 599 |
+
positions = self.embed_positions(position_ids)
|
| 600 |
+
x = inputs_embeds * self.embed_scale
|
| 601 |
+
else:
|
| 602 |
+
raise ValueError("You have to specify either decoder_input_ids or decoder_inputs_embeds")
|
| 603 |
+
|
| 604 |
+
x += positions
|
| 605 |
+
x = nn.functional.dropout(x, p=self.dropout, training=self.training)
|
| 606 |
+
|
| 607 |
+
# Convert to FSMT output format: (BS, seq_len, model_dim) -> (seq_len, BS, model_dim)
|
| 608 |
+
x = x.transpose(0, 1)
|
| 609 |
+
encoder_hidden_states = encoder_hidden_states.transpose(0, 1)
|
| 610 |
+
|
| 611 |
+
# decoder layers
|
| 612 |
+
all_hidden_states = () if output_hidden_states else None
|
| 613 |
+
all_self_attns = () if output_attentions else None
|
| 614 |
+
all_cross_attns = () if output_attentions else None
|
| 615 |
+
|
| 616 |
+
for idx, decoder_layer in enumerate(self.layers):
|
| 617 |
+
# add LayerDrop (see https://huggingface.co/papers/1909.11556 for description)
|
| 618 |
+
if output_hidden_states:
|
| 619 |
+
x = x.transpose(0, 1)
|
| 620 |
+
all_hidden_states += (x,)
|
| 621 |
+
x = x.transpose(0, 1)
|
| 622 |
+
if self.training:
|
| 623 |
+
dropout_probability = torch.rand([])
|
| 624 |
+
if dropout_probability < self.layerdrop:
|
| 625 |
+
continue
|
| 626 |
+
|
| 627 |
+
x, layer_self_attn, layer_cross_attn = decoder_layer(
|
| 628 |
+
x,
|
| 629 |
+
encoder_hidden_states,
|
| 630 |
+
encoder_attn_mask=encoder_padding_mask,
|
| 631 |
+
decoder_padding_mask=decoder_padding_mask,
|
| 632 |
+
layer_state=past_key_values,
|
| 633 |
+
causal_mask=decoder_causal_mask,
|
| 634 |
+
output_attentions=output_attentions,
|
| 635 |
+
)
|
| 636 |
+
|
| 637 |
+
if output_attentions:
|
| 638 |
+
all_self_attns += (layer_self_attn,)
|
| 639 |
+
all_cross_attns += (layer_cross_attn,)
|
| 640 |
+
|
| 641 |
+
# add hidden states from the last decoder layer
|
| 642 |
+
if output_hidden_states:
|
| 643 |
+
x = x.transpose(0, 1)
|
| 644 |
+
all_hidden_states += (x,)
|
| 645 |
+
x = x.transpose(0, 1)
|
| 646 |
+
|
| 647 |
+
# Convert to standard output format: (seq_len, BS, model_dim) -> (BS, seq_len, model_dim)
|
| 648 |
+
x = x.transpose(0, 1)
|
| 649 |
+
encoder_hidden_states = encoder_hidden_states.transpose(0, 1)
|
| 650 |
+
|
| 651 |
+
x = self.output_projection(x)
|
| 652 |
+
|
| 653 |
+
if not return_dict:
|
| 654 |
+
return tuple(
|
| 655 |
+
v for v in [x, past_key_values, all_hidden_states, all_self_attns, all_cross_attns] if v is not None
|
| 656 |
+
)
|
| 657 |
+
return BaseModelOutputWithPastAndCrossAttentions(
|
| 658 |
+
last_hidden_state=x,
|
| 659 |
+
past_key_values=past_key_values,
|
| 660 |
+
hidden_states=all_hidden_states,
|
| 661 |
+
attentions=all_self_attns,
|
| 662 |
+
cross_attentions=all_cross_attns,
|
| 663 |
+
)
|
| 664 |
+
|
| 665 |
+
|
| 666 |
+
def _reorder_buffer(attn_cache, new_order):
|
| 667 |
+
for k, input_buffer_k in attn_cache.items():
|
| 668 |
+
if input_buffer_k is not None:
|
| 669 |
+
attn_cache[k] = input_buffer_k.index_select(0, new_order)
|
| 670 |
+
return attn_cache
|
| 671 |
+
|
| 672 |
+
|
| 673 |
+
class Attention(nn.Module):
|
| 674 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 675 |
+
|
| 676 |
+
def __init__(
|
| 677 |
+
self,
|
| 678 |
+
embed_dim,
|
| 679 |
+
num_heads,
|
| 680 |
+
dropout=0.0,
|
| 681 |
+
bias=True,
|
| 682 |
+
encoder_decoder_attention=False, # otherwise self_attention
|
| 683 |
+
layer_idx=None,
|
| 684 |
+
):
|
| 685 |
+
super().__init__()
|
| 686 |
+
self.embed_dim = embed_dim
|
| 687 |
+
self.num_heads = num_heads
|
| 688 |
+
self.dropout = dropout
|
| 689 |
+
self.head_dim = embed_dim // num_heads
|
| 690 |
+
assert self.head_dim * num_heads == self.embed_dim, "embed_dim must be divisible by num_heads"
|
| 691 |
+
self.scaling = self.head_dim**-0.5
|
| 692 |
+
self.layer_idx = layer_idx
|
| 693 |
+
|
| 694 |
+
self.encoder_decoder_attention = encoder_decoder_attention
|
| 695 |
+
self.k_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
| 696 |
+
self.v_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
| 697 |
+
self.q_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
| 698 |
+
self.out_proj = nn.Linear(embed_dim, embed_dim, bias=bias)
|
| 699 |
+
self.cache_key = "encoder_decoder" if self.encoder_decoder_attention else "self"
|
| 700 |
+
|
| 701 |
+
def forward(
|
| 702 |
+
self,
|
| 703 |
+
query,
|
| 704 |
+
key: Tensor | None,
|
| 705 |
+
key_padding_mask: Tensor | None = None,
|
| 706 |
+
layer_state: Cache | None = None,
|
| 707 |
+
attn_mask: Tensor | None = None,
|
| 708 |
+
output_attentions: bool | None = False,
|
| 709 |
+
**kwargs,
|
| 710 |
+
) -> tuple[Tensor, Tensor | None]:
|
| 711 |
+
"""Input shape: Time(SeqLen) x Batch x Channel"""
|
| 712 |
+
tgt_len, bsz, embed_dim = query.size()
|
| 713 |
+
assert embed_dim == self.embed_dim
|
| 714 |
+
assert list(query.size()) == [tgt_len, bsz, embed_dim]
|
| 715 |
+
|
| 716 |
+
if layer_state is not None:
|
| 717 |
+
if isinstance(layer_state, EncoderDecoderCache):
|
| 718 |
+
is_updated = layer_state.is_updated.get(self.layer_idx)
|
| 719 |
+
if self.encoder_decoder_attention:
|
| 720 |
+
# after the first generated id, we can subsequently re-use all key/value_states from cache
|
| 721 |
+
curr_past_key_values = layer_state.cross_attention_cache
|
| 722 |
+
else:
|
| 723 |
+
curr_past_key_values = layer_state.self_attention_cache
|
| 724 |
+
else:
|
| 725 |
+
curr_past_key_values = layer_state
|
| 726 |
+
|
| 727 |
+
# NOTE: FSMT has format (seq_len, BS, model_dim) for inputs
|
| 728 |
+
current_states = key if self.encoder_decoder_attention else query
|
| 729 |
+
if self.encoder_decoder_attention and layer_state is not None and is_updated:
|
| 730 |
+
# reuse k,v, cross_attentions
|
| 731 |
+
key_states = curr_past_key_values.layers[self.layer_idx].keys
|
| 732 |
+
value_states = curr_past_key_values.layers[self.layer_idx].values
|
| 733 |
+
else:
|
| 734 |
+
key_states = self.k_proj(current_states)
|
| 735 |
+
value_states = self.v_proj(current_states)
|
| 736 |
+
key_states = key_states.view(-1, bsz, self.num_heads, self.head_dim).permute(1, 2, 0, 3)
|
| 737 |
+
value_states = value_states.view(-1, bsz, self.num_heads, self.head_dim).permute(1, 2, 0, 3)
|
| 738 |
+
|
| 739 |
+
if layer_state is not None:
|
| 740 |
+
# save all key/value_states to cache to be re-used for fast auto-regressive generation
|
| 741 |
+
key_states, value_states = curr_past_key_values.update(key_states, value_states, self.layer_idx)
|
| 742 |
+
# set flag that curr layer for cross-attn is already updated so we can re-use in subsequent calls
|
| 743 |
+
if self.encoder_decoder_attention:
|
| 744 |
+
layer_state.is_updated[self.layer_idx] = True
|
| 745 |
+
|
| 746 |
+
query_states = self.q_proj(query) * self.scaling
|
| 747 |
+
|
| 748 |
+
# Reshape back to 3D tensors for `bmm`
|
| 749 |
+
query_states = query_states.view(-1, bsz * self.num_heads, self.head_dim).transpose(0, 1)
|
| 750 |
+
key_states = key_states.reshape(bsz * self.num_heads, -1, self.head_dim)
|
| 751 |
+
value_states = value_states.reshape(bsz * self.num_heads, -1, self.head_dim)
|
| 752 |
+
|
| 753 |
+
assert key_states is not None
|
| 754 |
+
src_len = key_states.size(1)
|
| 755 |
+
attn_weights = torch.bmm(query_states, key_states.transpose(1, 2))
|
| 756 |
+
assert attn_weights.size() == (bsz * self.num_heads, tgt_len, src_len)
|
| 757 |
+
|
| 758 |
+
if attn_mask is not None:
|
| 759 |
+
attn_weights = attn_weights.view(bsz, self.num_heads, tgt_len, src_len) + attn_mask
|
| 760 |
+
attn_weights = attn_weights.view(bsz * self.num_heads, tgt_len, src_len)
|
| 761 |
+
|
| 762 |
+
# This is part of a workaround to get around fork/join parallelism not supporting Optional types.
|
| 763 |
+
if key_padding_mask is not None and key_padding_mask.dim() == 0:
|
| 764 |
+
key_padding_mask = None
|
| 765 |
+
assert key_padding_mask is None or key_padding_mask.size()[:2] == (
|
| 766 |
+
bsz,
|
| 767 |
+
src_len,
|
| 768 |
+
)
|
| 769 |
+
|
| 770 |
+
if key_padding_mask is not None: # don't attend to padding symbols
|
| 771 |
+
attn_weights = attn_weights.view(bsz, self.num_heads, tgt_len, src_len)
|
| 772 |
+
reshaped = key_padding_mask.unsqueeze(1).unsqueeze(2)
|
| 773 |
+
attn_weights = attn_weights.masked_fill(reshaped, torch.finfo(attn_weights.dtype).min)
|
| 774 |
+
attn_weights = attn_weights.view(bsz * self.num_heads, tgt_len, src_len)
|
| 775 |
+
|
| 776 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1)
|
| 777 |
+
|
| 778 |
+
if output_attentions:
|
| 779 |
+
# make sure that attn_weights are included in graph
|
| 780 |
+
attn_weights_reshaped = attn_weights.view(bsz, self.num_heads, tgt_len, src_len)
|
| 781 |
+
attn_weights = attn_weights_reshaped.view(bsz * self.num_heads, tgt_len, src_len)
|
| 782 |
+
else:
|
| 783 |
+
attn_weights_reshaped = None
|
| 784 |
+
|
| 785 |
+
attn_probs = nn.functional.dropout(
|
| 786 |
+
attn_weights,
|
| 787 |
+
p=self.dropout,
|
| 788 |
+
training=self.training,
|
| 789 |
+
)
|
| 790 |
+
|
| 791 |
+
assert value_states is not None
|
| 792 |
+
attn_output = torch.bmm(attn_probs, value_states)
|
| 793 |
+
assert attn_output.size() == (bsz * self.num_heads, tgt_len, self.head_dim)
|
| 794 |
+
attn_output = attn_output.transpose(0, 1).contiguous().view(tgt_len, bsz, embed_dim)
|
| 795 |
+
attn_output = self.out_proj(attn_output)
|
| 796 |
+
|
| 797 |
+
return attn_output, attn_weights_reshaped
|
| 798 |
+
|
| 799 |
+
|
| 800 |
+
def fill_with_neg_inf(t):
|
| 801 |
+
"""FP16-compatible function that fills a input_ids with -inf."""
|
| 802 |
+
return t.float().fill_(torch.finfo(t.dtype).min).type_as(t)
|
| 803 |
+
|
| 804 |
+
|
| 805 |
+
# Public API
|
| 806 |
+
def _get_shape(t):
|
| 807 |
+
return getattr(t, "shape", None)
|
| 808 |
+
|
| 809 |
+
|
| 810 |
+
@auto_docstring
|
| 811 |
+
class FSMTModel(PretrainedFSMTModel):
|
| 812 |
+
_tied_weights_keys = {
|
| 813 |
+
"encoder.embed_tokens.weight": "decoder.embed_tokens.weight",
|
| 814 |
+
"decoder.output_projection.weight": "decoder.embed_tokens.weight",
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
def __init__(self, config: FSMTConfig):
|
| 818 |
+
super().__init__(config)
|
| 819 |
+
self.encoder = FSMTEncoder(config)
|
| 820 |
+
self.decoder = FSMTDecoder(config)
|
| 821 |
+
self.post_init()
|
| 822 |
+
|
| 823 |
+
@auto_docstring
|
| 824 |
+
def forward(
|
| 825 |
+
self,
|
| 826 |
+
input_ids: torch.LongTensor,
|
| 827 |
+
attention_mask: torch.Tensor | None = None,
|
| 828 |
+
decoder_input_ids: torch.LongTensor | None = None,
|
| 829 |
+
decoder_attention_mask: torch.BoolTensor | None = None,
|
| 830 |
+
encoder_outputs: tuple[torch.FloatTensor] | None = None,
|
| 831 |
+
past_key_values: Cache | None = None,
|
| 832 |
+
use_cache: bool | None = None,
|
| 833 |
+
output_attentions: bool | None = None,
|
| 834 |
+
output_hidden_states: bool | None = None,
|
| 835 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 836 |
+
decoder_inputs_embeds: torch.FloatTensor | None = None,
|
| 837 |
+
return_dict: bool | None = None,
|
| 838 |
+
**kwargs,
|
| 839 |
+
) -> tuple[torch.Tensor] | Seq2SeqModelOutput:
|
| 840 |
+
r"""
|
| 841 |
+
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
|
| 842 |
+
Indices of decoder input sequence tokens in the vocabulary.
|
| 843 |
+
|
| 844 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 845 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 846 |
+
|
| 847 |
+
[What are decoder input IDs?](../glossary#decoder-input-ids)
|
| 848 |
+
|
| 849 |
+
FSMT uses the `eos_token_id` as the starting token for `decoder_input_ids` generation. If `past_key_values`
|
| 850 |
+
is used, optionally only the last `decoder_input_ids` have to be input (see `past_key_values`).
|
| 851 |
+
decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
|
| 852 |
+
Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
|
| 853 |
+
be used by default.
|
| 854 |
+
"""
|
| 855 |
+
if decoder_input_ids is None:
|
| 856 |
+
use_cache = False
|
| 857 |
+
|
| 858 |
+
output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
|
| 859 |
+
output_hidden_states = (
|
| 860 |
+
output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
|
| 861 |
+
)
|
| 862 |
+
use_cache = use_cache if use_cache is not None else self.config.use_cache
|
| 863 |
+
return_dict = return_dict if return_dict is not None else self.config.return_dict
|
| 864 |
+
|
| 865 |
+
# make masks if user doesn't supply
|
| 866 |
+
if not use_cache and input_ids is not None:
|
| 867 |
+
decoder_input_ids, decoder_padding_mask, causal_mask = _prepare_fsmt_decoder_inputs(
|
| 868 |
+
self.config,
|
| 869 |
+
input_ids,
|
| 870 |
+
decoder_input_ids=decoder_input_ids,
|
| 871 |
+
decoder_padding_mask=decoder_attention_mask,
|
| 872 |
+
causal_mask_dtype=self.decoder.embed_tokens.weight.dtype,
|
| 873 |
+
)
|
| 874 |
+
else:
|
| 875 |
+
decoder_padding_mask, causal_mask = None, None
|
| 876 |
+
|
| 877 |
+
if decoder_input_ids is None and decoder_inputs_embeds is None:
|
| 878 |
+
raise ValueError("Make sure that `decoder_input_ids` or `decoder_inputs_embeds` are passed.")
|
| 879 |
+
|
| 880 |
+
if use_cache and past_key_values is None:
|
| 881 |
+
past_key_values = EncoderDecoderCache(DynamicCache(config=self.config), DynamicCache(config=self.config))
|
| 882 |
+
|
| 883 |
+
if encoder_outputs is None:
|
| 884 |
+
encoder_outputs = self.encoder(
|
| 885 |
+
input_ids=input_ids,
|
| 886 |
+
attention_mask=attention_mask,
|
| 887 |
+
inputs_embeds=inputs_embeds,
|
| 888 |
+
output_attentions=output_attentions,
|
| 889 |
+
output_hidden_states=output_hidden_states,
|
| 890 |
+
return_dict=return_dict,
|
| 891 |
+
)
|
| 892 |
+
# If the user passed a tuple for encoder_outputs, we wrap it in a BaseModelOutput when return_dict=False
|
| 893 |
+
elif return_dict and not isinstance(encoder_outputs, BaseModelOutput):
|
| 894 |
+
encoder_outputs = BaseModelOutput(
|
| 895 |
+
last_hidden_state=encoder_outputs[0],
|
| 896 |
+
hidden_states=encoder_outputs[1] if len(encoder_outputs) > 1 else None,
|
| 897 |
+
attentions=encoder_outputs[2] if len(encoder_outputs) > 2 else None,
|
| 898 |
+
)
|
| 899 |
+
|
| 900 |
+
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 901 |
+
decoder_outputs = self.decoder(
|
| 902 |
+
decoder_input_ids,
|
| 903 |
+
encoder_outputs[0],
|
| 904 |
+
attention_mask,
|
| 905 |
+
decoder_padding_mask,
|
| 906 |
+
decoder_causal_mask=causal_mask,
|
| 907 |
+
inputs_embeds=decoder_inputs_embeds,
|
| 908 |
+
past_key_values=past_key_values,
|
| 909 |
+
use_cache=use_cache,
|
| 910 |
+
output_attentions=output_attentions,
|
| 911 |
+
output_hidden_states=output_hidden_states,
|
| 912 |
+
return_dict=return_dict,
|
| 913 |
+
)
|
| 914 |
+
|
| 915 |
+
if not return_dict:
|
| 916 |
+
return decoder_outputs + encoder_outputs
|
| 917 |
+
|
| 918 |
+
return Seq2SeqModelOutput(
|
| 919 |
+
last_hidden_state=decoder_outputs.last_hidden_state,
|
| 920 |
+
past_key_values=decoder_outputs.past_key_values,
|
| 921 |
+
decoder_hidden_states=decoder_outputs.hidden_states,
|
| 922 |
+
decoder_attentions=decoder_outputs.attentions,
|
| 923 |
+
cross_attentions=decoder_outputs.cross_attentions,
|
| 924 |
+
encoder_last_hidden_state=encoder_outputs.last_hidden_state,
|
| 925 |
+
encoder_hidden_states=encoder_outputs.hidden_states,
|
| 926 |
+
encoder_attentions=encoder_outputs.attentions,
|
| 927 |
+
)
|
| 928 |
+
|
| 929 |
+
def get_input_embeddings(self):
|
| 930 |
+
return self.encoder.embed_tokens
|
| 931 |
+
|
| 932 |
+
def set_input_embeddings(self, value):
|
| 933 |
+
self.encoder.embed_tokens = value
|
| 934 |
+
|
| 935 |
+
def get_output_embeddings(self):
|
| 936 |
+
return self.decoder.embed_tokens
|
| 937 |
+
|
| 938 |
+
def set_output_embeddings(self, value):
|
| 939 |
+
self.decoder.embed_tokens = value
|
| 940 |
+
|
| 941 |
+
|
| 942 |
+
@auto_docstring(
|
| 943 |
+
custom_intro="""
|
| 944 |
+
The FSMT Model with a language modeling head. Can be used for summarization.
|
| 945 |
+
"""
|
| 946 |
+
)
|
| 947 |
+
class FSMTForConditionalGeneration(PretrainedFSMTModel, GenerationMixin):
|
| 948 |
+
base_model_prefix = "model"
|
| 949 |
+
|
| 950 |
+
def __init__(self, config: FSMTConfig):
|
| 951 |
+
super().__init__(config)
|
| 952 |
+
base_model = FSMTModel(config)
|
| 953 |
+
self.model = base_model
|
| 954 |
+
|
| 955 |
+
# Initialize weights and apply final processing
|
| 956 |
+
self.post_init()
|
| 957 |
+
|
| 958 |
+
@auto_docstring
|
| 959 |
+
def forward(
|
| 960 |
+
self,
|
| 961 |
+
input_ids: torch.LongTensor | None = None,
|
| 962 |
+
attention_mask: torch.Tensor | None = None,
|
| 963 |
+
decoder_input_ids: torch.LongTensor | None = None,
|
| 964 |
+
decoder_attention_mask: torch.BoolTensor | None = None,
|
| 965 |
+
encoder_outputs: tuple[torch.FloatTensor] | None = None,
|
| 966 |
+
past_key_values: Cache | None = None,
|
| 967 |
+
inputs_embeds: torch.Tensor | None = None,
|
| 968 |
+
decoder_inputs_embeds: torch.Tensor | None = None,
|
| 969 |
+
labels: torch.LongTensor | None = None,
|
| 970 |
+
use_cache: bool | None = None,
|
| 971 |
+
output_attentions: bool | None = None,
|
| 972 |
+
output_hidden_states: bool | None = None,
|
| 973 |
+
return_dict: bool | None = None,
|
| 974 |
+
**kwargs,
|
| 975 |
+
) -> tuple[torch.Tensor] | Seq2SeqLMOutput:
|
| 976 |
+
r"""
|
| 977 |
+
decoder_input_ids (`torch.LongTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
|
| 978 |
+
Indices of decoder input sequence tokens in the vocabulary.
|
| 979 |
+
|
| 980 |
+
Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
|
| 981 |
+
[`PreTrainedTokenizer.__call__`] for details.
|
| 982 |
+
|
| 983 |
+
[What are decoder input IDs?](../glossary#decoder-input-ids)
|
| 984 |
+
|
| 985 |
+
FSMT uses the `eos_token_id` as the starting token for `decoder_input_ids` generation. If `past_key_values`
|
| 986 |
+
is used, optionally only the last `decoder_input_ids` have to be input (see `past_key_values`).
|
| 987 |
+
decoder_attention_mask (`torch.BoolTensor` of shape `(batch_size, target_sequence_length)`, *optional*):
|
| 988 |
+
Default behavior: generate a tensor that ignores pad tokens in `decoder_input_ids`. Causal mask will also
|
| 989 |
+
be used by default.
|
| 990 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 991 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 992 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 993 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 994 |
+
|
| 995 |
+
Example Translation:
|
| 996 |
+
|
| 997 |
+
```python
|
| 998 |
+
>>> from transformers import AutoTokenizer, FSMTForConditionalGeneration
|
| 999 |
+
|
| 1000 |
+
>>> mname = "facebook/wmt19-ru-en"
|
| 1001 |
+
>>> model = FSMTForConditionalGeneration.from_pretrained(mname)
|
| 1002 |
+
>>> tokenizer = AutoTokenizer.from_pretrained(mname)
|
| 1003 |
+
|
| 1004 |
+
>>> src_text = "Машинное обучение - это здорово, не так ли?"
|
| 1005 |
+
>>> input_ids = tokenizer(src_text, return_tensors="pt").input_ids
|
| 1006 |
+
>>> outputs = model.generate(input_ids, num_beams=5, num_return_sequences=3)
|
| 1007 |
+
>>> tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 1008 |
+
"Machine learning is great, isn't it?"
|
| 1009 |
+
```
|
| 1010 |
+
"""
|
| 1011 |
+
return_dict = return_dict if return_dict is not None else self.config.return_dict
|
| 1012 |
+
|
| 1013 |
+
if labels is not None:
|
| 1014 |
+
use_cache = False
|
| 1015 |
+
|
| 1016 |
+
outputs = self.model(
|
| 1017 |
+
input_ids,
|
| 1018 |
+
inputs_embeds=inputs_embeds,
|
| 1019 |
+
attention_mask=attention_mask,
|
| 1020 |
+
decoder_input_ids=decoder_input_ids,
|
| 1021 |
+
decoder_inputs_embeds=decoder_inputs_embeds,
|
| 1022 |
+
encoder_outputs=encoder_outputs,
|
| 1023 |
+
decoder_attention_mask=decoder_attention_mask,
|
| 1024 |
+
past_key_values=past_key_values,
|
| 1025 |
+
use_cache=use_cache,
|
| 1026 |
+
output_attentions=output_attentions,
|
| 1027 |
+
output_hidden_states=output_hidden_states,
|
| 1028 |
+
return_dict=return_dict,
|
| 1029 |
+
)
|
| 1030 |
+
lm_logits = outputs[0]
|
| 1031 |
+
|
| 1032 |
+
masked_lm_loss = None
|
| 1033 |
+
if labels is not None:
|
| 1034 |
+
loss_fct = CrossEntropyLoss()
|
| 1035 |
+
# TODO(SS): do we need to ignore pad tokens in labels?
|
| 1036 |
+
masked_lm_loss = loss_fct(lm_logits.view(-1, self.config.tgt_vocab_size), labels.view(-1))
|
| 1037 |
+
|
| 1038 |
+
if not return_dict:
|
| 1039 |
+
output = (lm_logits,) + outputs[1:]
|
| 1040 |
+
return ((masked_lm_loss,) + output) if masked_lm_loss is not None else output
|
| 1041 |
+
|
| 1042 |
+
return Seq2SeqLMOutput(
|
| 1043 |
+
loss=masked_lm_loss,
|
| 1044 |
+
logits=lm_logits,
|
| 1045 |
+
past_key_values=outputs.past_key_values,
|
| 1046 |
+
decoder_hidden_states=outputs.decoder_hidden_states,
|
| 1047 |
+
decoder_attentions=outputs.decoder_attentions,
|
| 1048 |
+
cross_attentions=outputs.cross_attentions,
|
| 1049 |
+
encoder_last_hidden_state=outputs.encoder_last_hidden_state,
|
| 1050 |
+
encoder_hidden_states=outputs.encoder_hidden_states,
|
| 1051 |
+
encoder_attentions=outputs.encoder_attentions,
|
| 1052 |
+
)
|
| 1053 |
+
|
| 1054 |
+
def prepare_decoder_input_ids_from_labels(self, labels: torch.Tensor):
|
| 1055 |
+
return shift_tokens_right(labels, self.config.pad_token_id)
|
| 1056 |
+
|
| 1057 |
+
def get_output_embeddings(self):
|
| 1058 |
+
return self.model.decoder.embed_tokens
|
| 1059 |
+
|
| 1060 |
+
def set_output_embeddings(self, value):
|
| 1061 |
+
self.model.decoder.embed_tokens = value
|
| 1062 |
+
|
| 1063 |
+
|
| 1064 |
+
class SinusoidalPositionalEmbedding(nn.Embedding):
|
| 1065 |
+
"""
|
| 1066 |
+
This module produces sinusoidal positional embeddings of any length.
|
| 1067 |
+
|
| 1068 |
+
We don't want to save the weight of this embedding since it's not trained (deterministic) and it can be huge.
|
| 1069 |
+
|
| 1070 |
+
Padding symbols are ignored.
|
| 1071 |
+
|
| 1072 |
+
These embeddings get automatically extended in forward if more positions is needed.
|
| 1073 |
+
"""
|
| 1074 |
+
|
| 1075 |
+
def __init__(self, num_positions, embedding_dim, padding_idx):
|
| 1076 |
+
super().__init__(num_positions, embedding_dim, padding_idx)
|
| 1077 |
+
|
| 1078 |
+
def make_weight(self, num_positions, embedding_dim, padding_idx):
|
| 1079 |
+
weight = self.get_embedding(num_positions, embedding_dim, padding_idx)
|
| 1080 |
+
# in forward put the weights on the correct dtype and device of the param
|
| 1081 |
+
weight = weight.to(dtype=self.weight.dtype, device=self.weight.device)
|
| 1082 |
+
self.weight = nn.Parameter(weight)
|
| 1083 |
+
self.weight.detach_()
|
| 1084 |
+
self.weight.requires_grad = False
|
| 1085 |
+
|
| 1086 |
+
@staticmethod
|
| 1087 |
+
def get_embedding(num_embeddings, embedding_dim, padding_idx):
|
| 1088 |
+
"""
|
| 1089 |
+
Build sinusoidal embeddings.
|
| 1090 |
+
|
| 1091 |
+
This matches the implementation in tensor2tensor, but differs slightly from the description in Section 3.5 of
|
| 1092 |
+
"Attention Is All You Need".
|
| 1093 |
+
"""
|
| 1094 |
+
half_dim = embedding_dim // 2
|
| 1095 |
+
emb = math.log(10000) / (half_dim - 1)
|
| 1096 |
+
emb = torch.exp(torch.arange(half_dim, dtype=torch.int64).float() * -emb)
|
| 1097 |
+
emb = torch.arange(num_embeddings, dtype=torch.int64).float().unsqueeze(1) * emb.unsqueeze(0)
|
| 1098 |
+
emb = torch.cat([torch.sin(emb), torch.cos(emb)], dim=1).view(num_embeddings, -1)
|
| 1099 |
+
if embedding_dim % 2 == 1:
|
| 1100 |
+
# zero pad
|
| 1101 |
+
emb = torch.cat([emb, torch.zeros(num_embeddings, 1)], dim=1)
|
| 1102 |
+
if padding_idx is not None:
|
| 1103 |
+
emb[padding_idx, :] = 0
|
| 1104 |
+
return emb
|
| 1105 |
+
|
| 1106 |
+
@staticmethod
|
| 1107 |
+
def make_positions(tensor, padding_idx: int):
|
| 1108 |
+
"""
|
| 1109 |
+
Replace non-padding symbols with their position numbers.
|
| 1110 |
+
|
| 1111 |
+
Position numbers begin at padding_idx+1. Padding symbols are ignored.
|
| 1112 |
+
"""
|
| 1113 |
+
# The series of casts and type-conversions here are carefully
|
| 1114 |
+
# balanced to both work with ONNX export and XLA. In particular XLA
|
| 1115 |
+
# prefers ints, cumsum defaults to output longs, and ONNX doesn't know
|
| 1116 |
+
# how to handle the dtype kwarg in cumsum.
|
| 1117 |
+
mask = tensor.ne(padding_idx).int()
|
| 1118 |
+
return (torch.cumsum(mask, dim=1).type_as(mask) * mask).long() + padding_idx
|
| 1119 |
+
|
| 1120 |
+
def forward(
|
| 1121 |
+
self,
|
| 1122 |
+
input,
|
| 1123 |
+
incremental_state: Any | None = None,
|
| 1124 |
+
timestep: Tensor | None = None,
|
| 1125 |
+
):
|
| 1126 |
+
"""Input is expected to be of size [bsz x seqlen]."""
|
| 1127 |
+
bsz, seq_len = input.shape[:2]
|
| 1128 |
+
max_pos = self.padding_idx + 1 + seq_len
|
| 1129 |
+
if max_pos > self.weight.size(0):
|
| 1130 |
+
# expand embeddings if needed
|
| 1131 |
+
self.make_weight(max_pos, self.embedding_dim, self.padding_idx)
|
| 1132 |
+
positions = self.make_positions(input, self.padding_idx)
|
| 1133 |
+
return super().forward(positions)
|
| 1134 |
+
|
| 1135 |
+
|
| 1136 |
+
__all__ = ["FSMTForConditionalGeneration", "FSMTModel", "PretrainedFSMTModel"]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/qwen3_vl_moe/__init__.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
from typing import TYPE_CHECKING
|
| 15 |
+
|
| 16 |
+
from ...utils import _LazyModule
|
| 17 |
+
from ...utils.import_utils import define_import_structure
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
if TYPE_CHECKING:
|
| 21 |
+
from .configuration_qwen3_vl_moe import *
|
| 22 |
+
from .modeling_qwen3_vl_moe import *
|
| 23 |
+
else:
|
| 24 |
+
import sys
|
| 25 |
+
|
| 26 |
+
_file = globals()["__file__"]
|
| 27 |
+
sys.modules[__name__] = _LazyModule(__name__, _file, define_import_structure(_file), module_spec=__spec__)
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/qwen3_vl_moe/modeling_qwen3_vl_moe.py
ADDED
|
@@ -0,0 +1,1886 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 2 |
+
# This file was automatically generated from src/transformers/models/qwen3_vl_moe/modular_qwen3_vl_moe.py.
|
| 3 |
+
# Do NOT edit this file manually as any edits will be overwritten by the generation of
|
| 4 |
+
# the file from the modular. If any change should be done, please apply the change to the
|
| 5 |
+
# modular_qwen3_vl_moe.py file directly. One of our CI enforces this.
|
| 6 |
+
# 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
|
| 7 |
+
# Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved.
|
| 8 |
+
#
|
| 9 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 10 |
+
# you may not use this file except in compliance with the License.
|
| 11 |
+
# You may obtain a copy of the License at
|
| 12 |
+
#
|
| 13 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 14 |
+
#
|
| 15 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 16 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 17 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 18 |
+
# See the License for the specific language governing permissions and
|
| 19 |
+
# limitations under the License.
|
| 20 |
+
|
| 21 |
+
import itertools
|
| 22 |
+
import warnings
|
| 23 |
+
from collections.abc import Callable
|
| 24 |
+
from dataclasses import dataclass
|
| 25 |
+
from typing import Any, Optional
|
| 26 |
+
|
| 27 |
+
import torch
|
| 28 |
+
import torch.nn as nn
|
| 29 |
+
import torch.nn.functional as F
|
| 30 |
+
|
| 31 |
+
from ... import initialization as init
|
| 32 |
+
from ...activations import ACT2FN
|
| 33 |
+
from ...cache_utils import Cache, DynamicCache
|
| 34 |
+
from ...generation import GenerationMixin
|
| 35 |
+
from ...integrations import (
|
| 36 |
+
use_experts_implementation,
|
| 37 |
+
use_kernel_forward_from_hub,
|
| 38 |
+
use_kernel_func_from_hub,
|
| 39 |
+
use_kernelized_func,
|
| 40 |
+
)
|
| 41 |
+
from ...masking_utils import create_causal_mask
|
| 42 |
+
from ...modeling_flash_attention_utils import FlashAttentionKwargs
|
| 43 |
+
from ...modeling_layers import GradientCheckpointingLayer
|
| 44 |
+
from ...modeling_outputs import BaseModelOutputWithPooling, ModelOutput, MoeModelOutputWithPast
|
| 45 |
+
from ...modeling_rope_utils import ROPE_INIT_FUNCTIONS, dynamic_rope_update
|
| 46 |
+
from ...modeling_utils import ALL_ATTENTION_FUNCTIONS, PreTrainedModel
|
| 47 |
+
from ...processing_utils import Unpack
|
| 48 |
+
from ...utils import TransformersKwargs, auto_docstring, can_return_tuple, torch_compilable_check
|
| 49 |
+
from ...utils.generic import (
|
| 50 |
+
accepts_precomputed_kwargs,
|
| 51 |
+
is_flash_attention_requested,
|
| 52 |
+
maybe_autocast,
|
| 53 |
+
merge_with_config_defaults,
|
| 54 |
+
)
|
| 55 |
+
from ...utils.output_capturing import OutputRecorder, capture_outputs
|
| 56 |
+
from ...vision_utils import get_vision_bilinear_indices_and_weights, get_vision_cu_seqlens, get_vision_position_ids
|
| 57 |
+
from .configuration_qwen3_vl_moe import Qwen3VLMoeConfig, Qwen3VLMoeTextConfig, Qwen3VLMoeVisionConfig
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
@use_kernel_forward_from_hub("RMSNorm")
|
| 61 |
+
class Qwen3VLMoeTextRMSNorm(nn.Module):
|
| 62 |
+
def __init__(self, hidden_size, eps: float = 1e-6) -> None:
|
| 63 |
+
"""
|
| 64 |
+
Qwen3VLMoeTextRMSNorm is equivalent to T5LayerNorm
|
| 65 |
+
"""
|
| 66 |
+
super().__init__()
|
| 67 |
+
self.weight = nn.Parameter(torch.ones(hidden_size))
|
| 68 |
+
self.variance_epsilon = eps
|
| 69 |
+
|
| 70 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 71 |
+
input_dtype = hidden_states.dtype
|
| 72 |
+
hidden_states = hidden_states.to(torch.float32)
|
| 73 |
+
variance = hidden_states.pow(2).mean(-1, keepdim=True)
|
| 74 |
+
hidden_states = hidden_states * torch.rsqrt(variance + self.variance_epsilon)
|
| 75 |
+
return self.weight * hidden_states.to(input_dtype)
|
| 76 |
+
|
| 77 |
+
def extra_repr(self):
|
| 78 |
+
return f"{tuple(self.weight.shape)}, eps={self.variance_epsilon}"
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
@use_experts_implementation
|
| 82 |
+
class Qwen3VLMoeTextExperts(nn.Module):
|
| 83 |
+
"""Collection of expert weights stored as 3D tensors."""
|
| 84 |
+
|
| 85 |
+
def __init__(self, config):
|
| 86 |
+
super().__init__()
|
| 87 |
+
self.num_experts = config.num_experts
|
| 88 |
+
self.hidden_dim = config.hidden_size
|
| 89 |
+
self.intermediate_dim = config.moe_intermediate_size
|
| 90 |
+
self.gate_up_proj = nn.Parameter(torch.empty(self.num_experts, 2 * self.intermediate_dim, self.hidden_dim))
|
| 91 |
+
self.down_proj = nn.Parameter(torch.empty(self.num_experts, self.hidden_dim, self.intermediate_dim))
|
| 92 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 93 |
+
|
| 94 |
+
def forward(
|
| 95 |
+
self,
|
| 96 |
+
hidden_states: torch.Tensor,
|
| 97 |
+
top_k_index: torch.Tensor,
|
| 98 |
+
top_k_weights: torch.Tensor,
|
| 99 |
+
) -> torch.Tensor:
|
| 100 |
+
final_hidden_states = torch.zeros_like(hidden_states)
|
| 101 |
+
with torch.no_grad():
|
| 102 |
+
expert_mask = torch.nn.functional.one_hot(top_k_index, num_classes=self.num_experts)
|
| 103 |
+
expert_mask = expert_mask.permute(2, 1, 0)
|
| 104 |
+
expert_hit = torch.greater(expert_mask.sum(dim=(-1, -2)), 0).nonzero()
|
| 105 |
+
|
| 106 |
+
for expert_idx in expert_hit:
|
| 107 |
+
expert_idx = expert_idx[0]
|
| 108 |
+
if expert_idx == self.num_experts:
|
| 109 |
+
continue
|
| 110 |
+
top_k_pos, token_idx = torch.where(expert_mask[expert_idx])
|
| 111 |
+
current_state = hidden_states[token_idx]
|
| 112 |
+
gate, up = nn.functional.linear(current_state, self.gate_up_proj[expert_idx]).chunk(2, dim=-1)
|
| 113 |
+
current_hidden_states = self.act_fn(gate) * up
|
| 114 |
+
current_hidden_states = nn.functional.linear(current_hidden_states, self.down_proj[expert_idx])
|
| 115 |
+
current_hidden_states = current_hidden_states * top_k_weights[token_idx, top_k_pos, None]
|
| 116 |
+
final_hidden_states.index_add_(0, token_idx, current_hidden_states.to(final_hidden_states.dtype))
|
| 117 |
+
|
| 118 |
+
return final_hidden_states
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
class Qwen3VLMoeTextTopKRouter(nn.Module):
|
| 122 |
+
def __init__(self, config):
|
| 123 |
+
super().__init__()
|
| 124 |
+
self.top_k = config.num_experts_per_tok
|
| 125 |
+
self.num_experts = config.num_experts
|
| 126 |
+
self.hidden_dim = config.hidden_size
|
| 127 |
+
self.weight = nn.Parameter(torch.zeros(self.num_experts, self.hidden_dim))
|
| 128 |
+
|
| 129 |
+
def forward(self, hidden_states):
|
| 130 |
+
hidden_states = hidden_states.reshape(-1, self.hidden_dim)
|
| 131 |
+
router_logits = F.linear(hidden_states, self.weight) # (seq_len, num_experts)
|
| 132 |
+
router_probs = torch.nn.functional.softmax(router_logits, dtype=torch.float, dim=-1)
|
| 133 |
+
router_top_value, router_indices = torch.topk(router_probs, self.top_k, dim=-1) # (seq_len, top_k)
|
| 134 |
+
router_top_value /= router_top_value.sum(dim=-1, keepdim=True)
|
| 135 |
+
router_top_value = router_top_value.to(router_logits.dtype)
|
| 136 |
+
router_scores = router_top_value
|
| 137 |
+
return router_logits, router_scores, router_indices
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
class Qwen3VLMoeTextSparseMoeBlock(nn.Module):
|
| 141 |
+
def __init__(self, config: Qwen3VLMoeTextConfig):
|
| 142 |
+
super().__init__()
|
| 143 |
+
self.experts = Qwen3VLMoeTextExperts(config)
|
| 144 |
+
self.gate = Qwen3VLMoeTextTopKRouter(config)
|
| 145 |
+
|
| 146 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 147 |
+
batch_size, sequence_length, hidden_dim = hidden_states.shape
|
| 148 |
+
hidden_states_reshaped = hidden_states.view(-1, hidden_dim)
|
| 149 |
+
_, routing_weights, selected_experts = self.gate(hidden_states_reshaped)
|
| 150 |
+
final_hidden_states = self.experts(hidden_states_reshaped, selected_experts, routing_weights)
|
| 151 |
+
return final_hidden_states.reshape(batch_size, sequence_length, hidden_dim)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def rotate_half(x):
|
| 155 |
+
"""Rotates half the hidden dims of the input."""
|
| 156 |
+
x1 = x[..., : x.shape[-1] // 2]
|
| 157 |
+
x2 = x[..., x.shape[-1] // 2 :]
|
| 158 |
+
return torch.cat((-x2, x1), dim=-1)
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
def repeat_kv(hidden_states: torch.Tensor, n_rep: int) -> torch.Tensor:
|
| 162 |
+
"""
|
| 163 |
+
This is the equivalent of torch.repeat_interleave(x, dim=1, repeats=n_rep). The hidden states go from (batch,
|
| 164 |
+
num_key_value_heads, seqlen, head_dim) to (batch, num_attention_heads, seqlen, head_dim)
|
| 165 |
+
"""
|
| 166 |
+
batch, num_key_value_heads, slen, head_dim = hidden_states.shape
|
| 167 |
+
if n_rep == 1:
|
| 168 |
+
return hidden_states
|
| 169 |
+
hidden_states = hidden_states[:, :, None, :, :].expand(batch, num_key_value_heads, n_rep, slen, head_dim)
|
| 170 |
+
return hidden_states.reshape(batch, num_key_value_heads * n_rep, slen, head_dim)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def eager_attention_forward(
|
| 174 |
+
module: nn.Module,
|
| 175 |
+
query: torch.Tensor,
|
| 176 |
+
key: torch.Tensor,
|
| 177 |
+
value: torch.Tensor,
|
| 178 |
+
attention_mask: torch.Tensor | None,
|
| 179 |
+
scaling: float,
|
| 180 |
+
dropout: float = 0.0,
|
| 181 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 182 |
+
):
|
| 183 |
+
key_states = repeat_kv(key, module.num_key_value_groups)
|
| 184 |
+
value_states = repeat_kv(value, module.num_key_value_groups)
|
| 185 |
+
|
| 186 |
+
attn_weights = torch.matmul(query, key_states.transpose(2, 3)) * scaling
|
| 187 |
+
if attention_mask is not None:
|
| 188 |
+
attn_weights = attn_weights + attention_mask
|
| 189 |
+
|
| 190 |
+
attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query.dtype)
|
| 191 |
+
attn_weights = nn.functional.dropout(attn_weights, p=dropout, training=module.training)
|
| 192 |
+
attn_output = torch.matmul(attn_weights, value_states)
|
| 193 |
+
attn_output = attn_output.transpose(1, 2).contiguous()
|
| 194 |
+
|
| 195 |
+
return attn_output, attn_weights
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
@use_kernel_func_from_hub("rotary_pos_emb")
|
| 199 |
+
def apply_rotary_pos_emb(q, k, cos, sin, unsqueeze_dim=1):
|
| 200 |
+
"""Applies Rotary Position Embedding to the query and key tensors.
|
| 201 |
+
|
| 202 |
+
Args:
|
| 203 |
+
q (`torch.Tensor`): The query tensor.
|
| 204 |
+
k (`torch.Tensor`): The key tensor.
|
| 205 |
+
cos (`torch.Tensor`): The cosine part of the rotary embedding.
|
| 206 |
+
sin (`torch.Tensor`): The sine part of the rotary embedding.
|
| 207 |
+
unsqueeze_dim (`int`, *optional*, defaults to 1):
|
| 208 |
+
The 'unsqueeze_dim' argument specifies the dimension along which to unsqueeze cos[position_ids] and
|
| 209 |
+
sin[position_ids] so that they can be properly broadcasted to the dimensions of q and k. For example, note
|
| 210 |
+
that cos[position_ids] and sin[position_ids] have the shape [batch_size, seq_len, head_dim]. Then, if q and
|
| 211 |
+
k have the shape [batch_size, heads, seq_len, head_dim], then setting unsqueeze_dim=1 makes
|
| 212 |
+
cos[position_ids] and sin[position_ids] broadcastable to the shapes of q and k. Similarly, if q and k have
|
| 213 |
+
the shape [batch_size, seq_len, heads, head_dim], then set unsqueeze_dim=2.
|
| 214 |
+
Returns:
|
| 215 |
+
`tuple(torch.Tensor)` comprising of the query and key tensors rotated using the Rotary Position Embedding.
|
| 216 |
+
"""
|
| 217 |
+
cos = cos.unsqueeze(unsqueeze_dim)
|
| 218 |
+
sin = sin.unsqueeze(unsqueeze_dim)
|
| 219 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 220 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 221 |
+
return q_embed, k_embed
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
@use_kernelized_func(apply_rotary_pos_emb)
|
| 225 |
+
class Qwen3VLMoeTextAttention(nn.Module):
|
| 226 |
+
"""Multi-headed attention from 'Attention Is All You Need' paper"""
|
| 227 |
+
|
| 228 |
+
def __init__(self, config: Qwen3VLMoeTextConfig, layer_idx: int):
|
| 229 |
+
super().__init__()
|
| 230 |
+
self.layer_type = config.layer_types[layer_idx] if hasattr(config, "layer_types") else None
|
| 231 |
+
self.config = config
|
| 232 |
+
self.layer_idx = layer_idx
|
| 233 |
+
self.head_dim = getattr(config, "head_dim", config.hidden_size // config.num_attention_heads)
|
| 234 |
+
self.num_key_value_groups = config.num_attention_heads // config.num_key_value_heads
|
| 235 |
+
self.scaling = self.head_dim**-0.5
|
| 236 |
+
self.attention_dropout = config.attention_dropout
|
| 237 |
+
self.is_causal = True
|
| 238 |
+
|
| 239 |
+
self.q_proj = nn.Linear(
|
| 240 |
+
config.hidden_size, config.num_attention_heads * self.head_dim, bias=config.attention_bias
|
| 241 |
+
)
|
| 242 |
+
self.k_proj = nn.Linear(
|
| 243 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 244 |
+
)
|
| 245 |
+
self.v_proj = nn.Linear(
|
| 246 |
+
config.hidden_size, config.num_key_value_heads * self.head_dim, bias=config.attention_bias
|
| 247 |
+
)
|
| 248 |
+
self.o_proj = nn.Linear(
|
| 249 |
+
config.num_attention_heads * self.head_dim, config.hidden_size, bias=config.attention_bias
|
| 250 |
+
)
|
| 251 |
+
self.q_norm = Qwen3VLMoeTextRMSNorm(
|
| 252 |
+
self.head_dim, eps=config.rms_norm_eps
|
| 253 |
+
) # unlike olmo, only on the head dim!
|
| 254 |
+
self.k_norm = Qwen3VLMoeTextRMSNorm(
|
| 255 |
+
self.head_dim, eps=config.rms_norm_eps
|
| 256 |
+
) # thus post q_norm does not need reshape
|
| 257 |
+
|
| 258 |
+
def forward(
|
| 259 |
+
self,
|
| 260 |
+
hidden_states: torch.Tensor,
|
| 261 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor],
|
| 262 |
+
attention_mask: torch.Tensor | None,
|
| 263 |
+
past_key_values: Cache | None = None,
|
| 264 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 265 |
+
) -> tuple[torch.Tensor, torch.Tensor | None]:
|
| 266 |
+
input_shape = hidden_states.shape[:-1]
|
| 267 |
+
hidden_shape = (*input_shape, -1, self.head_dim)
|
| 268 |
+
|
| 269 |
+
query_states = self.q_norm(self.q_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
|
| 270 |
+
key_states = self.k_norm(self.k_proj(hidden_states).view(hidden_shape)).transpose(1, 2)
|
| 271 |
+
value_states = self.v_proj(hidden_states).view(hidden_shape).transpose(1, 2)
|
| 272 |
+
|
| 273 |
+
cos, sin = position_embeddings
|
| 274 |
+
query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)
|
| 275 |
+
|
| 276 |
+
if past_key_values is not None:
|
| 277 |
+
key_states, value_states = past_key_values.update(key_states, value_states, self.layer_idx)
|
| 278 |
+
|
| 279 |
+
attention_interface: Callable = ALL_ATTENTION_FUNCTIONS.get_interface(
|
| 280 |
+
self.config._attn_implementation, eager_attention_forward
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
attn_output, attn_weights = attention_interface(
|
| 284 |
+
self,
|
| 285 |
+
query_states,
|
| 286 |
+
key_states,
|
| 287 |
+
value_states,
|
| 288 |
+
attention_mask,
|
| 289 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 290 |
+
scaling=self.scaling,
|
| 291 |
+
**kwargs,
|
| 292 |
+
)
|
| 293 |
+
|
| 294 |
+
attn_output = attn_output.reshape(*input_shape, -1).contiguous()
|
| 295 |
+
attn_output = self.o_proj(attn_output)
|
| 296 |
+
return attn_output, attn_weights
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
class Qwen3VLMoeTextMLP(nn.Module):
|
| 300 |
+
def __init__(self, config, intermediate_size=None):
|
| 301 |
+
super().__init__()
|
| 302 |
+
self.config = config
|
| 303 |
+
self.hidden_size = config.hidden_size
|
| 304 |
+
self.intermediate_size = config.intermediate_size if intermediate_size is None else intermediate_size
|
| 305 |
+
self.gate_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 306 |
+
self.up_proj = nn.Linear(self.hidden_size, self.intermediate_size, bias=False)
|
| 307 |
+
self.down_proj = nn.Linear(self.intermediate_size, self.hidden_size, bias=False)
|
| 308 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 309 |
+
|
| 310 |
+
def forward(self, x):
|
| 311 |
+
down_proj = self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))
|
| 312 |
+
return down_proj
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
class Qwen3VLMoeTextDecoderLayer(GradientCheckpointingLayer):
|
| 316 |
+
def __init__(self, config: Qwen3VLMoeTextConfig, layer_idx: int):
|
| 317 |
+
super().__init__()
|
| 318 |
+
self.self_attn = Qwen3VLMoeTextAttention(config, layer_idx)
|
| 319 |
+
if (layer_idx not in config.mlp_only_layers) and (
|
| 320 |
+
config.num_experts > 0 and (layer_idx + 1) % config.decoder_sparse_step == 0
|
| 321 |
+
):
|
| 322 |
+
self.mlp = Qwen3VLMoeTextSparseMoeBlock(config)
|
| 323 |
+
else:
|
| 324 |
+
self.mlp = Qwen3VLMoeTextMLP(config, intermediate_size=config.intermediate_size)
|
| 325 |
+
self.input_layernorm = Qwen3VLMoeTextRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 326 |
+
self.post_attention_layernorm = Qwen3VLMoeTextRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 327 |
+
self.hidden_size = config.hidden_size
|
| 328 |
+
|
| 329 |
+
def forward(
|
| 330 |
+
self,
|
| 331 |
+
hidden_states: torch.Tensor,
|
| 332 |
+
attention_mask: torch.Tensor | None = None,
|
| 333 |
+
position_ids: torch.LongTensor | None = None,
|
| 334 |
+
past_key_values: Cache | None = None,
|
| 335 |
+
use_cache: bool | None = False,
|
| 336 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor] | None = None,
|
| 337 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 338 |
+
) -> torch.Tensor:
|
| 339 |
+
residual = hidden_states
|
| 340 |
+
hidden_states = self.input_layernorm(hidden_states)
|
| 341 |
+
# Self Attention
|
| 342 |
+
hidden_states, _ = self.self_attn(
|
| 343 |
+
hidden_states=hidden_states,
|
| 344 |
+
attention_mask=attention_mask,
|
| 345 |
+
position_ids=position_ids,
|
| 346 |
+
past_key_values=past_key_values,
|
| 347 |
+
use_cache=use_cache,
|
| 348 |
+
position_embeddings=position_embeddings,
|
| 349 |
+
**kwargs,
|
| 350 |
+
)
|
| 351 |
+
hidden_states = residual + hidden_states
|
| 352 |
+
|
| 353 |
+
# Fully Connected
|
| 354 |
+
residual = hidden_states
|
| 355 |
+
hidden_states = self.post_attention_layernorm(hidden_states)
|
| 356 |
+
hidden_states = self.mlp(hidden_states)
|
| 357 |
+
hidden_states = residual + hidden_states
|
| 358 |
+
return hidden_states
|
| 359 |
+
|
| 360 |
+
|
| 361 |
+
@auto_docstring
|
| 362 |
+
class Qwen3VLMoePreTrainedModel(PreTrainedModel):
|
| 363 |
+
config: Qwen3VLMoeConfig
|
| 364 |
+
base_model_prefix = "model"
|
| 365 |
+
supports_gradient_checkpointing = True
|
| 366 |
+
_no_split_modules = ["Qwen3VLMoeTextDecoderLayer", "Qwen3VLMoeVisionBlock"]
|
| 367 |
+
_skip_keys_device_placement = ["past_key_values"]
|
| 368 |
+
_supports_flash_attn = True
|
| 369 |
+
_supports_sdpa = True
|
| 370 |
+
_supports_flex_attn = True
|
| 371 |
+
|
| 372 |
+
_can_compile_fullgraph = True
|
| 373 |
+
_supports_attention_backend = True
|
| 374 |
+
_can_record_outputs = {
|
| 375 |
+
"router_logits": OutputRecorder(Qwen3VLMoeTextTopKRouter, index=0),
|
| 376 |
+
"hidden_states": Qwen3VLMoeTextDecoderLayer,
|
| 377 |
+
"attentions": Qwen3VLMoeTextAttention,
|
| 378 |
+
}
|
| 379 |
+
input_modalities = ("text", "image", "video")
|
| 380 |
+
|
| 381 |
+
@torch.no_grad()
|
| 382 |
+
def _init_weights(self, module):
|
| 383 |
+
"""Initialize the weights."""
|
| 384 |
+
super()._init_weights(module)
|
| 385 |
+
if hasattr(self.config, "initializer_range"):
|
| 386 |
+
std = self.config.initializer_range
|
| 387 |
+
else:
|
| 388 |
+
std = getattr(self.config.get_text_config(), "initializer_range", 0.02)
|
| 389 |
+
if isinstance(module, Qwen3VLMoeTextExperts):
|
| 390 |
+
init.normal_(module.gate_up_proj, mean=0.0, std=std)
|
| 391 |
+
init.normal_(module.down_proj, mean=0.0, std=std)
|
| 392 |
+
elif isinstance(module, Qwen3VLMoeTextTopKRouter):
|
| 393 |
+
init.normal_(module.weight, mean=0.0, std=std)
|
| 394 |
+
elif isinstance(module, Qwen3VLMoeVisionRotaryEmbedding):
|
| 395 |
+
inv_freq = 1.0 / (module.theta ** (torch.arange(0, module.dim, 2, dtype=torch.float) / module.dim))
|
| 396 |
+
init.copy_(module.inv_freq, inv_freq)
|
| 397 |
+
|
| 398 |
+
|
| 399 |
+
class Qwen3VLMoeVisionRotaryEmbedding(nn.Module):
|
| 400 |
+
inv_freq: torch.Tensor # fix linting for `register_buffer`
|
| 401 |
+
|
| 402 |
+
def __init__(self, dim: int, theta: float = 10000.0) -> None:
|
| 403 |
+
super().__init__()
|
| 404 |
+
self.dim = dim
|
| 405 |
+
self.theta = theta
|
| 406 |
+
inv_freq = 1.0 / (theta ** (torch.arange(0, dim, 2, dtype=torch.float) / dim))
|
| 407 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 408 |
+
|
| 409 |
+
def forward(self, position_ids: torch.Tensor) -> torch.Tensor:
|
| 410 |
+
return (position_ids.unsqueeze(-1) * self.inv_freq).flatten(1)
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def apply_rotary_pos_emb_vision(
|
| 414 |
+
q: torch.Tensor, k: torch.Tensor, cos: torch.Tensor, sin: torch.Tensor
|
| 415 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 416 |
+
orig_q_dtype = q.dtype
|
| 417 |
+
orig_k_dtype = k.dtype
|
| 418 |
+
q, k = q.float(), k.float()
|
| 419 |
+
cos, sin = cos.unsqueeze(-2).float(), sin.unsqueeze(-2).float()
|
| 420 |
+
q_embed = (q * cos) + (rotate_half(q) * sin)
|
| 421 |
+
k_embed = (k * cos) + (rotate_half(k) * sin)
|
| 422 |
+
q_embed = q_embed.to(orig_q_dtype)
|
| 423 |
+
k_embed = k_embed.to(orig_k_dtype)
|
| 424 |
+
return q_embed, k_embed
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
class Qwen3VLMoeVisionAttention(nn.Module):
|
| 428 |
+
def __init__(self, config: Qwen3VLMoeVisionConfig) -> None:
|
| 429 |
+
super().__init__()
|
| 430 |
+
self.dim = config.hidden_size
|
| 431 |
+
self.num_heads = config.num_heads
|
| 432 |
+
self.head_dim = self.dim // self.num_heads
|
| 433 |
+
self.num_key_value_groups = 1 # needed for eager attention
|
| 434 |
+
self.qkv = nn.Linear(self.dim, self.dim * 3, bias=True)
|
| 435 |
+
self.proj = nn.Linear(self.dim, self.dim)
|
| 436 |
+
self.scaling = self.head_dim**-0.5
|
| 437 |
+
self.config = config
|
| 438 |
+
self.attention_dropout = 0.0
|
| 439 |
+
self.is_causal = False
|
| 440 |
+
|
| 441 |
+
def forward(
|
| 442 |
+
self,
|
| 443 |
+
hidden_states: torch.Tensor,
|
| 444 |
+
cu_seqlens: torch.Tensor,
|
| 445 |
+
rotary_pos_emb: torch.Tensor | None = None,
|
| 446 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor] | None = None,
|
| 447 |
+
**kwargs,
|
| 448 |
+
) -> torch.Tensor:
|
| 449 |
+
seq_length = hidden_states.shape[0]
|
| 450 |
+
query_states, key_states, value_states = (
|
| 451 |
+
self.qkv(hidden_states).reshape(seq_length, 3, self.num_heads, -1).permute(1, 0, 2, 3).unbind(0)
|
| 452 |
+
)
|
| 453 |
+
cos, sin = position_embeddings
|
| 454 |
+
query_states, key_states = apply_rotary_pos_emb_vision(query_states, key_states, cos, sin)
|
| 455 |
+
|
| 456 |
+
query_states = query_states.transpose(0, 1).unsqueeze(0)
|
| 457 |
+
key_states = key_states.transpose(0, 1).unsqueeze(0)
|
| 458 |
+
value_states = value_states.transpose(0, 1).unsqueeze(0)
|
| 459 |
+
|
| 460 |
+
attention_interface: Callable = ALL_ATTENTION_FUNCTIONS.get_interface(
|
| 461 |
+
self.config._attn_implementation, eager_attention_forward
|
| 462 |
+
)
|
| 463 |
+
|
| 464 |
+
if is_flash_attention_requested(self.config):
|
| 465 |
+
# Flash Attention: Use cu_seqlens for variable length attention
|
| 466 |
+
max_seqlen = (cu_seqlens[1:] - cu_seqlens[:-1]).max()
|
| 467 |
+
attn_output, _ = attention_interface(
|
| 468 |
+
self,
|
| 469 |
+
query_states,
|
| 470 |
+
key_states,
|
| 471 |
+
value_states,
|
| 472 |
+
attention_mask=None,
|
| 473 |
+
scaling=self.scaling,
|
| 474 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 475 |
+
cu_seq_lens_q=cu_seqlens,
|
| 476 |
+
cu_seq_lens_k=cu_seqlens,
|
| 477 |
+
max_length_q=max_seqlen,
|
| 478 |
+
max_length_k=max_seqlen,
|
| 479 |
+
is_causal=False,
|
| 480 |
+
**kwargs,
|
| 481 |
+
)
|
| 482 |
+
else:
|
| 483 |
+
# Other implementations: Process each chunk separately
|
| 484 |
+
lengths = cu_seqlens[1:] - cu_seqlens[:-1]
|
| 485 |
+
splits = [
|
| 486 |
+
torch.split(tensor, lengths.tolist(), dim=2) for tensor in (query_states, key_states, value_states)
|
| 487 |
+
]
|
| 488 |
+
|
| 489 |
+
attn_outputs = [
|
| 490 |
+
attention_interface(
|
| 491 |
+
self,
|
| 492 |
+
q,
|
| 493 |
+
k,
|
| 494 |
+
v,
|
| 495 |
+
attention_mask=None,
|
| 496 |
+
scaling=self.scaling,
|
| 497 |
+
dropout=0.0 if not self.training else self.attention_dropout,
|
| 498 |
+
is_causal=False,
|
| 499 |
+
**kwargs,
|
| 500 |
+
)[0]
|
| 501 |
+
for q, k, v in zip(*splits)
|
| 502 |
+
]
|
| 503 |
+
attn_output = torch.cat(attn_outputs, dim=1)
|
| 504 |
+
|
| 505 |
+
attn_output = attn_output.reshape(seq_length, -1).contiguous()
|
| 506 |
+
attn_output = self.proj(attn_output)
|
| 507 |
+
return attn_output
|
| 508 |
+
|
| 509 |
+
|
| 510 |
+
class Qwen3VLMoeVisionMLP(nn.Module):
|
| 511 |
+
def __init__(self, config):
|
| 512 |
+
super().__init__()
|
| 513 |
+
self.hidden_size = config.hidden_size
|
| 514 |
+
self.intermediate_size = config.intermediate_size
|
| 515 |
+
self.linear_fc1 = nn.Linear(self.hidden_size, self.intermediate_size, bias=True)
|
| 516 |
+
self.linear_fc2 = nn.Linear(self.intermediate_size, self.hidden_size, bias=True)
|
| 517 |
+
self.act_fn = ACT2FN[config.hidden_act]
|
| 518 |
+
|
| 519 |
+
def forward(self, hidden_state):
|
| 520 |
+
return self.linear_fc2(self.act_fn(self.linear_fc1(hidden_state)))
|
| 521 |
+
|
| 522 |
+
|
| 523 |
+
class Qwen3VLMoeVisionBlock(GradientCheckpointingLayer):
|
| 524 |
+
def __init__(self, config, attn_implementation: str = "sdpa") -> None:
|
| 525 |
+
super().__init__()
|
| 526 |
+
self.norm1 = nn.LayerNorm(config.hidden_size, eps=1e-6)
|
| 527 |
+
self.norm2 = nn.LayerNorm(config.hidden_size, eps=1e-6)
|
| 528 |
+
self.attn = Qwen3VLMoeVisionAttention(config=config)
|
| 529 |
+
self.mlp = Qwen3VLMoeVisionMLP(config=config)
|
| 530 |
+
|
| 531 |
+
@auto_docstring
|
| 532 |
+
def forward(
|
| 533 |
+
self,
|
| 534 |
+
hidden_states: torch.Tensor,
|
| 535 |
+
cu_seqlens: torch.Tensor,
|
| 536 |
+
rotary_pos_emb: torch.Tensor | None = None,
|
| 537 |
+
position_embeddings: tuple[torch.Tensor, torch.Tensor] | None = None,
|
| 538 |
+
**kwargs,
|
| 539 |
+
) -> torch.Tensor:
|
| 540 |
+
r"""
|
| 541 |
+
cu_seqlens (`torch.Tensor`):
|
| 542 |
+
Cumulative sequence lengths used for packed variable-length attention in Flash Attention kernels.
|
| 543 |
+
rotary_pos_emb (`torch.Tensor`, *optional*):
|
| 544 |
+
Precomputed rotary positional embeddings applied to the vision attention query/key states.
|
| 545 |
+
"""
|
| 546 |
+
hidden_states = hidden_states + self.attn(
|
| 547 |
+
self.norm1(hidden_states),
|
| 548 |
+
cu_seqlens=cu_seqlens,
|
| 549 |
+
rotary_pos_emb=rotary_pos_emb,
|
| 550 |
+
position_embeddings=position_embeddings,
|
| 551 |
+
**kwargs,
|
| 552 |
+
)
|
| 553 |
+
hidden_states = hidden_states + self.mlp(self.norm2(hidden_states))
|
| 554 |
+
return hidden_states
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
@auto_docstring
|
| 558 |
+
@dataclass
|
| 559 |
+
class BaseModelOutputWithDeepstackFeatures(BaseModelOutputWithPooling):
|
| 560 |
+
r"""
|
| 561 |
+
deepstack_features (`List[torch.FloatTensor]`, *optional*):
|
| 562 |
+
List of hidden-states (feature maps) from deepstack layers.
|
| 563 |
+
"""
|
| 564 |
+
|
| 565 |
+
deepstack_features: list[torch.FloatTensor] | None = None
|
| 566 |
+
|
| 567 |
+
|
| 568 |
+
class Qwen3VLMoeVisionPatchEmbed(nn.Module):
|
| 569 |
+
def __init__(self, config) -> None:
|
| 570 |
+
super().__init__()
|
| 571 |
+
self.patch_size = config.patch_size
|
| 572 |
+
self.temporal_patch_size = config.temporal_patch_size
|
| 573 |
+
self.in_channels = config.in_channels
|
| 574 |
+
self.embed_dim = config.hidden_size
|
| 575 |
+
|
| 576 |
+
kernel_size = [self.temporal_patch_size, self.patch_size, self.patch_size]
|
| 577 |
+
self.proj = nn.Conv3d(self.in_channels, self.embed_dim, kernel_size=kernel_size, stride=kernel_size, bias=True)
|
| 578 |
+
|
| 579 |
+
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
|
| 580 |
+
target_dtype = self.proj.weight.dtype
|
| 581 |
+
hidden_states = hidden_states.view(
|
| 582 |
+
-1, self.in_channels, self.temporal_patch_size, self.patch_size, self.patch_size
|
| 583 |
+
)
|
| 584 |
+
hidden_states = self.proj(hidden_states.to(dtype=target_dtype)).view(-1, self.embed_dim)
|
| 585 |
+
return hidden_states
|
| 586 |
+
|
| 587 |
+
|
| 588 |
+
class Qwen3VLMoeVisionPatchMerger(nn.Module):
|
| 589 |
+
def __init__(self, config: Qwen3VLMoeVisionConfig, use_postshuffle_norm=False) -> None:
|
| 590 |
+
super().__init__()
|
| 591 |
+
self.hidden_size = config.hidden_size * (config.spatial_merge_size**2)
|
| 592 |
+
self.use_postshuffle_norm = use_postshuffle_norm
|
| 593 |
+
self.norm = nn.LayerNorm(self.hidden_size if use_postshuffle_norm else config.hidden_size, eps=1e-6)
|
| 594 |
+
self.linear_fc1 = nn.Linear(self.hidden_size, self.hidden_size)
|
| 595 |
+
self.act_fn = nn.GELU()
|
| 596 |
+
self.linear_fc2 = nn.Linear(self.hidden_size, config.out_hidden_size)
|
| 597 |
+
|
| 598 |
+
def forward(self, x: torch.Tensor) -> torch.Tensor:
|
| 599 |
+
x = self.norm(x.view(-1, self.hidden_size) if self.use_postshuffle_norm else x).view(-1, self.hidden_size)
|
| 600 |
+
x = self.linear_fc2(self.act_fn(self.linear_fc1(x)))
|
| 601 |
+
return x
|
| 602 |
+
|
| 603 |
+
|
| 604 |
+
class Qwen3VLMoeVisionModel(Qwen3VLMoePreTrainedModel):
|
| 605 |
+
config: Qwen3VLMoeVisionConfig
|
| 606 |
+
input_modalities = ("image", "video")
|
| 607 |
+
_no_split_modules = ["Qwen3VLMoeVisionBlock"]
|
| 608 |
+
_can_record_outputs = {
|
| 609 |
+
"router_logits": OutputRecorder(Qwen3VLMoeTextTopKRouter, layer_name="mlp.gate", index=0),
|
| 610 |
+
"hidden_states": Qwen3VLMoeVisionBlock,
|
| 611 |
+
"attentions": Qwen3VLMoeVisionAttention,
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
def __init__(self, config, *inputs, **kwargs) -> None:
|
| 615 |
+
super().__init__(config, *inputs, **kwargs)
|
| 616 |
+
self.spatial_merge_size = config.spatial_merge_size
|
| 617 |
+
self.patch_size = config.patch_size
|
| 618 |
+
self.spatial_merge_unit = self.spatial_merge_size * self.spatial_merge_size
|
| 619 |
+
|
| 620 |
+
self.patch_embed = Qwen3VLMoeVisionPatchEmbed(
|
| 621 |
+
config=config,
|
| 622 |
+
)
|
| 623 |
+
|
| 624 |
+
self.pos_embed = nn.Embedding(config.num_position_embeddings, config.hidden_size)
|
| 625 |
+
self.num_grid_per_side = int(config.num_position_embeddings**0.5)
|
| 626 |
+
|
| 627 |
+
head_dim = config.hidden_size // config.num_heads
|
| 628 |
+
self.rotary_pos_emb = Qwen3VLMoeVisionRotaryEmbedding(head_dim // 2)
|
| 629 |
+
|
| 630 |
+
self.blocks = nn.ModuleList([Qwen3VLMoeVisionBlock(config) for _ in range(config.depth)])
|
| 631 |
+
self.merger = Qwen3VLMoeVisionPatchMerger(
|
| 632 |
+
config=config,
|
| 633 |
+
use_postshuffle_norm=False,
|
| 634 |
+
)
|
| 635 |
+
|
| 636 |
+
self.deepstack_visual_indexes = config.deepstack_visual_indexes
|
| 637 |
+
self.deepstack_merger_list = nn.ModuleList(
|
| 638 |
+
[
|
| 639 |
+
Qwen3VLMoeVisionPatchMerger(
|
| 640 |
+
config=config,
|
| 641 |
+
use_postshuffle_norm=True,
|
| 642 |
+
)
|
| 643 |
+
for _ in range(len(config.deepstack_visual_indexes))
|
| 644 |
+
]
|
| 645 |
+
)
|
| 646 |
+
|
| 647 |
+
self.gradient_checkpointing = False
|
| 648 |
+
|
| 649 |
+
self.post_init()
|
| 650 |
+
|
| 651 |
+
def rot_pos_emb(self, grid_thw: torch.Tensor) -> torch.Tensor:
|
| 652 |
+
warnings.warn(
|
| 653 |
+
f"`{self.__class__.__name__}.rot_pos_emb` is deprecated and will be removed in v5.11. Use `get_vision_position_ids` from `transformers.vision_utils` and apply the rotary embedding module.",
|
| 654 |
+
FutureWarning,
|
| 655 |
+
stacklevel=2,
|
| 656 |
+
)
|
| 657 |
+
position_ids = get_vision_position_ids(grid_thw, self.spatial_merge_size)
|
| 658 |
+
rotary_pos_emb = self.rotary_pos_emb(position_ids)
|
| 659 |
+
return rotary_pos_emb
|
| 660 |
+
|
| 661 |
+
def fast_pos_embed_interpolate(self, grid_thw):
|
| 662 |
+
warnings.warn(
|
| 663 |
+
f"`{self.__class__.__name__}.fast_pos_embed_interpolate` is deprecated and will be removed in v5.11. Use `get_vision_bilinear_indices_and_weights` from `transformers.vision_utils` and apply `self.pos_embed`.",
|
| 664 |
+
FutureWarning,
|
| 665 |
+
stacklevel=2,
|
| 666 |
+
)
|
| 667 |
+
bilinear_indices, bilinear_weights = get_vision_bilinear_indices_and_weights(
|
| 668 |
+
grid_thw,
|
| 669 |
+
num_grid_per_side=self.num_grid_per_side,
|
| 670 |
+
spatial_merge_size=self.config.spatial_merge_size,
|
| 671 |
+
)
|
| 672 |
+
return (self.pos_embed(bilinear_indices) * bilinear_weights[:, :, None]).sum(0)
|
| 673 |
+
|
| 674 |
+
@merge_with_config_defaults
|
| 675 |
+
@capture_outputs
|
| 676 |
+
def forward(
|
| 677 |
+
self, hidden_states: torch.Tensor, grid_thw: torch.Tensor, **kwargs: Unpack[TransformersKwargs]
|
| 678 |
+
) -> tuple | BaseModelOutputWithDeepstackFeatures:
|
| 679 |
+
"""
|
| 680 |
+
Args:
|
| 681 |
+
hidden_states (`torch.Tensor` of shape `(seq_len, hidden_size)`):
|
| 682 |
+
The final hidden states of the model.
|
| 683 |
+
grid_thw (`torch.Tensor` of shape `(num_images_or_videos, 3)`):
|
| 684 |
+
The temporal, height and width of feature shape of each image in LLM.
|
| 685 |
+
|
| 686 |
+
Returns:
|
| 687 |
+
`torch.Tensor`: hidden_states.
|
| 688 |
+
"""
|
| 689 |
+
bilinear_indices, bilinear_weights = get_vision_bilinear_indices_and_weights(
|
| 690 |
+
grid_thw,
|
| 691 |
+
num_grid_per_side=self.num_grid_per_side,
|
| 692 |
+
spatial_merge_size=self.config.spatial_merge_size,
|
| 693 |
+
kwargs=kwargs,
|
| 694 |
+
)
|
| 695 |
+
position_ids = get_vision_position_ids(grid_thw, self.spatial_merge_size, kwargs=kwargs)
|
| 696 |
+
cu_seqlens = get_vision_cu_seqlens(grid_thw, kwargs=kwargs)
|
| 697 |
+
|
| 698 |
+
hidden_states = self.patch_embed(hidden_states)
|
| 699 |
+
pos_embeds = (self.pos_embed(bilinear_indices) * bilinear_weights[:, :, None]).sum(0)
|
| 700 |
+
hidden_states = hidden_states + pos_embeds.to(hidden_states.dtype)
|
| 701 |
+
rotary_pos_emb = self.rotary_pos_emb(position_ids)
|
| 702 |
+
|
| 703 |
+
seq_len, _ = hidden_states.size()
|
| 704 |
+
hidden_states = hidden_states.reshape(seq_len, -1)
|
| 705 |
+
rotary_pos_emb = rotary_pos_emb.reshape(seq_len, -1)
|
| 706 |
+
emb = torch.cat((rotary_pos_emb, rotary_pos_emb), dim=-1)
|
| 707 |
+
position_embeddings = (emb.cos(), emb.sin())
|
| 708 |
+
|
| 709 |
+
deepstack_feature_lists = []
|
| 710 |
+
for layer_num, blk in enumerate(self.blocks):
|
| 711 |
+
hidden_states = blk(
|
| 712 |
+
hidden_states,
|
| 713 |
+
cu_seqlens=cu_seqlens,
|
| 714 |
+
position_embeddings=position_embeddings,
|
| 715 |
+
**kwargs,
|
| 716 |
+
)
|
| 717 |
+
if layer_num in self.deepstack_visual_indexes:
|
| 718 |
+
deepstack_feature = self.deepstack_merger_list[self.deepstack_visual_indexes.index(layer_num)](
|
| 719 |
+
hidden_states
|
| 720 |
+
)
|
| 721 |
+
deepstack_feature_lists.append(deepstack_feature)
|
| 722 |
+
|
| 723 |
+
merged_hidden_states = self.merger(hidden_states)
|
| 724 |
+
|
| 725 |
+
return BaseModelOutputWithDeepstackFeatures(
|
| 726 |
+
last_hidden_state=hidden_states,
|
| 727 |
+
pooler_output=merged_hidden_states,
|
| 728 |
+
deepstack_features=deepstack_feature_lists,
|
| 729 |
+
)
|
| 730 |
+
|
| 731 |
+
|
| 732 |
+
class Qwen3VLMoeTextRotaryEmbedding(nn.Module):
|
| 733 |
+
inv_freq: torch.Tensor # fix linting for `register_buffer`
|
| 734 |
+
|
| 735 |
+
def __init__(self, config: Qwen3VLMoeTextConfig, device=None):
|
| 736 |
+
super().__init__()
|
| 737 |
+
self.max_seq_len_cached = config.max_position_embeddings
|
| 738 |
+
self.original_max_seq_len = config.max_position_embeddings
|
| 739 |
+
|
| 740 |
+
self.config = config
|
| 741 |
+
|
| 742 |
+
self.rope_type = self.config.rope_parameters["rope_type"]
|
| 743 |
+
rope_init_fn: Callable = self.compute_default_rope_parameters
|
| 744 |
+
if self.rope_type != "default":
|
| 745 |
+
rope_init_fn = ROPE_INIT_FUNCTIONS[self.rope_type]
|
| 746 |
+
inv_freq, self.attention_scaling = rope_init_fn(self.config, device)
|
| 747 |
+
|
| 748 |
+
self.register_buffer("inv_freq", inv_freq, persistent=False)
|
| 749 |
+
self.register_buffer("original_inv_freq", inv_freq.clone(), persistent=False)
|
| 750 |
+
|
| 751 |
+
self.mrope_section = config.rope_parameters.get("mrope_section", [24, 20, 20])
|
| 752 |
+
|
| 753 |
+
@staticmethod
|
| 754 |
+
def compute_default_rope_parameters(
|
| 755 |
+
config: Qwen3VLMoeTextConfig | None = None,
|
| 756 |
+
device: Optional["torch.device"] = None,
|
| 757 |
+
seq_len: int | None = None,
|
| 758 |
+
) -> tuple["torch.Tensor", float]:
|
| 759 |
+
"""
|
| 760 |
+
Computes the inverse frequencies according to the original RoPE implementation
|
| 761 |
+
Args:
|
| 762 |
+
config ([`~transformers.PreTrainedConfig`]):
|
| 763 |
+
The model configuration.
|
| 764 |
+
device (`torch.device`):
|
| 765 |
+
The device to use for initialization of the inverse frequencies.
|
| 766 |
+
seq_len (`int`, *optional*):
|
| 767 |
+
The current sequence length. Unused for this type of RoPE.
|
| 768 |
+
Returns:
|
| 769 |
+
Tuple of (`torch.Tensor`, `float`), containing the inverse frequencies for the RoPE embeddings and the
|
| 770 |
+
post-processing scaling factor applied to the computed cos/sin (unused in this type of RoPE).
|
| 771 |
+
"""
|
| 772 |
+
base = config.rope_parameters["rope_theta"]
|
| 773 |
+
dim = getattr(config, "head_dim", None) or config.hidden_size // config.num_attention_heads
|
| 774 |
+
|
| 775 |
+
attention_factor = 1.0 # Unused in this type of RoPE
|
| 776 |
+
|
| 777 |
+
# Compute the inverse frequencies
|
| 778 |
+
inv_freq = 1.0 / (
|
| 779 |
+
base ** (torch.arange(0, dim, 2, dtype=torch.int64).to(device=device, dtype=torch.float) / dim)
|
| 780 |
+
)
|
| 781 |
+
return inv_freq, attention_factor
|
| 782 |
+
|
| 783 |
+
@torch.no_grad()
|
| 784 |
+
@dynamic_rope_update # power user: used with advanced RoPE types (e.g. dynamic rope)
|
| 785 |
+
def forward(self, x, position_ids):
|
| 786 |
+
# In contrast to other models, Qwen3VLMoe has different position ids for the grids
|
| 787 |
+
# So we expand the inv_freq to shape (3, ...)
|
| 788 |
+
if position_ids.ndim == 2:
|
| 789 |
+
position_ids = position_ids[None, ...].expand(3, position_ids.shape[0], -1)
|
| 790 |
+
inv_freq_expanded = (
|
| 791 |
+
self.inv_freq[None, None, :, None].float().expand(3, position_ids.shape[1], -1, 1).to(x.device)
|
| 792 |
+
)
|
| 793 |
+
position_ids_expanded = position_ids[:, :, None, :].float() # shape (3, bs, 1, positions)
|
| 794 |
+
|
| 795 |
+
device_type = x.device.type if isinstance(x.device.type, str) and x.device.type != "mps" else "cpu"
|
| 796 |
+
with maybe_autocast(device_type=device_type, enabled=False): # Force float32
|
| 797 |
+
freqs = (inv_freq_expanded.float() @ position_ids_expanded.float()).transpose(2, 3)
|
| 798 |
+
freqs = self.apply_interleaved_mrope(freqs, self.mrope_section)
|
| 799 |
+
emb = torch.cat((freqs, freqs), dim=-1)
|
| 800 |
+
cos = emb.cos() * self.attention_scaling
|
| 801 |
+
sin = emb.sin() * self.attention_scaling
|
| 802 |
+
|
| 803 |
+
return cos.to(dtype=x.dtype), sin.to(dtype=x.dtype)
|
| 804 |
+
|
| 805 |
+
def apply_interleaved_mrope(self, freqs, mrope_section):
|
| 806 |
+
"""Apply interleaved MRoPE to 3D rotary embeddings.
|
| 807 |
+
Reorganizes frequency layout from chunked [TTT...HHH...WWW] to
|
| 808 |
+
interleaved [THWTHWTHW...TT], preserving frequency continuity.
|
| 809 |
+
args:
|
| 810 |
+
x: (3, bs, seq_len, head_dim // 2)
|
| 811 |
+
mrope_section: (3,)
|
| 812 |
+
returns:
|
| 813 |
+
x_t: (bs, seq_len, head_dim // 2)
|
| 814 |
+
"""
|
| 815 |
+
freqs_t = freqs[0] # just overwrite the first dimension T
|
| 816 |
+
for dim, offset in enumerate((1, 2), start=1): # H, W
|
| 817 |
+
length = mrope_section[dim] * 3
|
| 818 |
+
idx = slice(offset, length, 3)
|
| 819 |
+
freqs_t[..., idx] = freqs[dim, ..., idx]
|
| 820 |
+
return freqs_t
|
| 821 |
+
|
| 822 |
+
|
| 823 |
+
@auto_docstring(
|
| 824 |
+
custom_intro=(
|
| 825 |
+
"Text part of Qwen3VLMoe, "
|
| 826 |
+
"not a pure text-only model, as DeepStack integrates visual features into the early hidden states."
|
| 827 |
+
)
|
| 828 |
+
)
|
| 829 |
+
class Qwen3VLMoeTextModel(Qwen3VLMoePreTrainedModel):
|
| 830 |
+
config: Qwen3VLMoeTextConfig
|
| 831 |
+
input_modalities = ("text",)
|
| 832 |
+
_no_split_modules = ["Qwen3VLMoeTextDecoderLayer"]
|
| 833 |
+
|
| 834 |
+
def __init__(self, config: Qwen3VLMoeTextConfig):
|
| 835 |
+
super().__init__(config)
|
| 836 |
+
self.padding_idx = config.pad_token_id
|
| 837 |
+
self.vocab_size = config.vocab_size
|
| 838 |
+
|
| 839 |
+
self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
|
| 840 |
+
self.layers = nn.ModuleList(
|
| 841 |
+
[Qwen3VLMoeTextDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
|
| 842 |
+
)
|
| 843 |
+
self.norm = Qwen3VLMoeTextRMSNorm(config.hidden_size, eps=config.rms_norm_eps)
|
| 844 |
+
self.rotary_emb = Qwen3VLMoeTextRotaryEmbedding(config=config)
|
| 845 |
+
self.gradient_checkpointing = False
|
| 846 |
+
|
| 847 |
+
# Initialize weights and apply final processing
|
| 848 |
+
self.post_init()
|
| 849 |
+
|
| 850 |
+
@merge_with_config_defaults
|
| 851 |
+
@capture_outputs
|
| 852 |
+
@auto_docstring
|
| 853 |
+
def forward(
|
| 854 |
+
self,
|
| 855 |
+
input_ids: torch.LongTensor | None = None,
|
| 856 |
+
attention_mask: torch.Tensor | None = None,
|
| 857 |
+
position_ids: torch.LongTensor | None = None,
|
| 858 |
+
past_key_values: Cache | None = None,
|
| 859 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 860 |
+
use_cache: bool | None = None,
|
| 861 |
+
# args for deepstack
|
| 862 |
+
visual_pos_masks: torch.Tensor | None = None,
|
| 863 |
+
deepstack_visual_embeds: list[torch.Tensor] | None = None,
|
| 864 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 865 |
+
) -> tuple | MoeModelOutputWithPast:
|
| 866 |
+
r"""
|
| 867 |
+
visual_pos_masks (`torch.Tensor` of shape `(batch_size, seqlen)`, *optional*):
|
| 868 |
+
The mask of the visual positions.
|
| 869 |
+
deepstack_visual_embeds (`list[torch.Tensor]`, *optional*):
|
| 870 |
+
The deepstack visual embeddings. The shape is (num_layers, visual_seqlen, embed_dim).
|
| 871 |
+
The feature is extracted from the different visual encoder layers, and fed to the decoder
|
| 872 |
+
hidden states. It's from the paper DeepStack(https://arxiv.org/abs/2406.04334).
|
| 873 |
+
"""
|
| 874 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 875 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 876 |
+
|
| 877 |
+
# torch.jit.trace() doesn't support cache objects in the output
|
| 878 |
+
if use_cache and past_key_values is None and not torch.jit.is_tracing():
|
| 879 |
+
past_key_values = DynamicCache(config=self.config)
|
| 880 |
+
|
| 881 |
+
if inputs_embeds is None:
|
| 882 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 883 |
+
|
| 884 |
+
# the hard coded `4` is for text, temporal, height and width.
|
| 885 |
+
if position_ids is None:
|
| 886 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 887 |
+
position_ids = torch.arange(inputs_embeds.shape[1], device=inputs_embeds.device) + past_seen_tokens
|
| 888 |
+
position_ids = position_ids.view(1, 1, -1).expand(4, inputs_embeds.shape[0], -1)
|
| 889 |
+
elif position_ids.ndim == 2:
|
| 890 |
+
position_ids = position_ids[None, ...].expand(4, position_ids.shape[0], -1)
|
| 891 |
+
|
| 892 |
+
if position_ids.ndim == 3 and position_ids.shape[0] == 4:
|
| 893 |
+
text_position_ids = position_ids[0]
|
| 894 |
+
position_ids = position_ids[1:]
|
| 895 |
+
else:
|
| 896 |
+
text_position_ids = None
|
| 897 |
+
|
| 898 |
+
attention_mask = create_causal_mask(
|
| 899 |
+
config=self.config,
|
| 900 |
+
inputs_embeds=inputs_embeds,
|
| 901 |
+
attention_mask=attention_mask,
|
| 902 |
+
past_key_values=past_key_values,
|
| 903 |
+
position_ids=text_position_ids,
|
| 904 |
+
)
|
| 905 |
+
|
| 906 |
+
hidden_states = inputs_embeds
|
| 907 |
+
|
| 908 |
+
# create position embeddings to be shared across the decoder layers
|
| 909 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 910 |
+
|
| 911 |
+
# decoder layers
|
| 912 |
+
for layer_idx, decoder_layer in enumerate(self.layers):
|
| 913 |
+
layer_outputs = decoder_layer(
|
| 914 |
+
hidden_states,
|
| 915 |
+
attention_mask=attention_mask,
|
| 916 |
+
position_ids=text_position_ids,
|
| 917 |
+
past_key_values=past_key_values,
|
| 918 |
+
position_embeddings=position_embeddings,
|
| 919 |
+
**kwargs,
|
| 920 |
+
)
|
| 921 |
+
hidden_states = layer_outputs
|
| 922 |
+
|
| 923 |
+
# add visual features to the hidden states of first several layers
|
| 924 |
+
if deepstack_visual_embeds is not None and layer_idx in range(len(deepstack_visual_embeds)):
|
| 925 |
+
hidden_states = self._deepstack_process(
|
| 926 |
+
hidden_states,
|
| 927 |
+
visual_pos_masks,
|
| 928 |
+
deepstack_visual_embeds[layer_idx],
|
| 929 |
+
)
|
| 930 |
+
|
| 931 |
+
hidden_states = self.norm(hidden_states)
|
| 932 |
+
|
| 933 |
+
return MoeModelOutputWithPast( # only diff with Qwen3VLTextModel
|
| 934 |
+
last_hidden_state=hidden_states,
|
| 935 |
+
past_key_values=past_key_values,
|
| 936 |
+
)
|
| 937 |
+
|
| 938 |
+
def _deepstack_process(
|
| 939 |
+
self, hidden_states: torch.Tensor, visual_pos_masks: torch.Tensor, visual_embeds: torch.Tensor
|
| 940 |
+
):
|
| 941 |
+
visual_pos_masks = visual_pos_masks.to(hidden_states.device)
|
| 942 |
+
visual_embeds = visual_embeds.to(hidden_states.device, hidden_states.dtype)
|
| 943 |
+
hidden_states = hidden_states.clone()
|
| 944 |
+
local_this = hidden_states[visual_pos_masks, :] + visual_embeds
|
| 945 |
+
hidden_states[visual_pos_masks, :] = local_this
|
| 946 |
+
return hidden_states
|
| 947 |
+
|
| 948 |
+
|
| 949 |
+
@auto_docstring(
|
| 950 |
+
custom_intro="""
|
| 951 |
+
Base class for Llava outputs, with hidden states and attentions.
|
| 952 |
+
"""
|
| 953 |
+
)
|
| 954 |
+
@dataclass
|
| 955 |
+
class Qwen3VLMoeModelOutputWithPast(ModelOutput):
|
| 956 |
+
r"""
|
| 957 |
+
past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
| 958 |
+
It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
|
| 959 |
+
|
| 960 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
|
| 961 |
+
`past_key_values` input) to speed up sequential decoding.
|
| 962 |
+
rope_deltas (`torch.LongTensor` of shape `(batch_size, )`, *optional*):
|
| 963 |
+
The rope index difference between sequence length and multimodal rope.
|
| 964 |
+
"""
|
| 965 |
+
|
| 966 |
+
last_hidden_state: torch.FloatTensor | None = None
|
| 967 |
+
past_key_values: Cache | None = None
|
| 968 |
+
hidden_states: tuple[torch.FloatTensor] | None = None
|
| 969 |
+
attentions: tuple[torch.FloatTensor] | None = None
|
| 970 |
+
rope_deltas: torch.LongTensor | None = None
|
| 971 |
+
router_logits: tuple[torch.FloatTensor] | None = None
|
| 972 |
+
|
| 973 |
+
|
| 974 |
+
@auto_docstring(
|
| 975 |
+
custom_intro="""
|
| 976 |
+
Base class for Qwen3VLMoe causal language model (or autoregressive) outputs.
|
| 977 |
+
"""
|
| 978 |
+
)
|
| 979 |
+
@dataclass
|
| 980 |
+
class Qwen3VLMoeCausalLMOutputWithPast(ModelOutput):
|
| 981 |
+
r"""
|
| 982 |
+
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
|
| 983 |
+
Language modeling loss (for next-token prediction).
|
| 984 |
+
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
|
| 985 |
+
Prediction scores of the language modeling head (scores for each vocabulary token before SoftMax).
|
| 986 |
+
past_key_values (`Cache`, *optional*, returned when `use_cache=True` is passed or when `config.use_cache=True`):
|
| 987 |
+
It is a [`~cache_utils.Cache`] instance. For more details, see our [kv cache guide](https://huggingface.co/docs/transformers/en/kv_cache).
|
| 988 |
+
|
| 989 |
+
Contains pre-computed hidden-states (key and values in the self-attention blocks) that can be used (see
|
| 990 |
+
`past_key_values` input) to speed up sequential decoding.
|
| 991 |
+
rope_deltas (`torch.LongTensor` of shape `(batch_size, )`, *optional*):
|
| 992 |
+
The rope index difference between sequence length and multimodal rope.
|
| 993 |
+
"""
|
| 994 |
+
|
| 995 |
+
loss: torch.FloatTensor | None = None
|
| 996 |
+
logits: torch.FloatTensor | None = None
|
| 997 |
+
past_key_values: Cache | None = None
|
| 998 |
+
hidden_states: tuple[torch.FloatTensor] | None = None
|
| 999 |
+
attentions: tuple[torch.FloatTensor] | None = None
|
| 1000 |
+
rope_deltas: torch.LongTensor | None = None
|
| 1001 |
+
router_logits: tuple[torch.FloatTensor] | None = None
|
| 1002 |
+
aux_loss: torch.FloatTensor | None = None
|
| 1003 |
+
|
| 1004 |
+
|
| 1005 |
+
@auto_docstring
|
| 1006 |
+
class Qwen3VLMoeModel(Qwen3VLMoePreTrainedModel):
|
| 1007 |
+
base_model_prefix = "model"
|
| 1008 |
+
# Reference: fix gemma3 grad acc #37208
|
| 1009 |
+
accepts_loss_kwargs = False
|
| 1010 |
+
config: Qwen3VLMoeConfig
|
| 1011 |
+
_no_split_modules = ["Qwen3VLMoeTextDecoderLayer", "Qwen3VLMoeVisionBlock"]
|
| 1012 |
+
|
| 1013 |
+
def __init__(self, config):
|
| 1014 |
+
super().__init__(config)
|
| 1015 |
+
self.visual = Qwen3VLMoeVisionModel._from_config(config.vision_config)
|
| 1016 |
+
self.language_model = Qwen3VLMoeTextModel._from_config(config.text_config)
|
| 1017 |
+
self.rope_deltas = None # cache rope_deltas here
|
| 1018 |
+
|
| 1019 |
+
# Initialize weights and apply final processing
|
| 1020 |
+
self.post_init()
|
| 1021 |
+
|
| 1022 |
+
def get_vision_position_ids(
|
| 1023 |
+
self,
|
| 1024 |
+
start_position: int,
|
| 1025 |
+
grid_thw: list[int, int, int] | torch.Tensor,
|
| 1026 |
+
temp_merge_size: int = 1,
|
| 1027 |
+
spatial_merge_size: int = 1,
|
| 1028 |
+
time_interval: int = 1,
|
| 1029 |
+
device: str | torch.device | None = None,
|
| 1030 |
+
):
|
| 1031 |
+
"""
|
| 1032 |
+
Compute 3D positional indices for vision tokens derived from a single image or video input.
|
| 1033 |
+
|
| 1034 |
+
The positions are generated from the input grid defined by temporal (T), height (H), and
|
| 1035 |
+
width (W) dimensions. Temporal and spatial dimensions can be downscaled according to the
|
| 1036 |
+
merge sizes used in the vision backbone. The resulting positions are offset by `start_position`.
|
| 1037 |
+
|
| 1038 |
+
Args:
|
| 1039 |
+
start_position (`int`):
|
| 1040 |
+
Offset added to all computed positional indices.
|
| 1041 |
+
grid_thw (`Sequence[int]` or `torch.Tensor` of shape `(3,)`):
|
| 1042 |
+
The (T, H, W) grid representing the feature layout of the current image or video after patch embedding.
|
| 1043 |
+
temp_merge_size (`int`, *optional*):
|
| 1044 |
+
Factor by which the temporal dimension is reduced in the backbone. The temporal grid size is divided
|
| 1045 |
+
by this value. Defaults to 1.
|
| 1046 |
+
spatial_merge_size (`int`, *optional*):
|
| 1047 |
+
Factor by which the spatial dimensions (H and W) are reduced in the backbone. Both H and W are divided
|
| 1048 |
+
by this value. Defaults to 1.
|
| 1049 |
+
time_interval (`int`, *optional*):
|
| 1050 |
+
Spacing factor applied between consecutive temporal position indices.Defaults to 1.
|
| 1051 |
+
device (`str` or `torch.device`, *optional*):
|
| 1052 |
+
Device on which the resulting tensor is allocated. If `None`, uses the current default device.
|
| 1053 |
+
|
| 1054 |
+
Returns:
|
| 1055 |
+
torch.LongTensor of shape (3, sequence_length):
|
| 1056 |
+
Positional indices for temporal, height, and width dimensions,
|
| 1057 |
+
flattened into sequence form and offset by `start_position`.
|
| 1058 |
+
"""
|
| 1059 |
+
llm_grid_t, llm_grid_h, llm_grid_w = (
|
| 1060 |
+
grid_thw[0].item() // temp_merge_size,
|
| 1061 |
+
grid_thw[1].item() // spatial_merge_size,
|
| 1062 |
+
grid_thw[2].item() // spatial_merge_size,
|
| 1063 |
+
)
|
| 1064 |
+
|
| 1065 |
+
# Add `start_position` after arange for compile
|
| 1066 |
+
position_temporal = torch.arange(llm_grid_t, device=device) * time_interval
|
| 1067 |
+
position_width = torch.arange(llm_grid_w, device=device) + start_position
|
| 1068 |
+
position_height = torch.arange(llm_grid_h, device=device) + start_position
|
| 1069 |
+
|
| 1070 |
+
# Repeat the positions per each grid and per video frame. Repeat patterns are important
|
| 1071 |
+
# do not modify without checking values!
|
| 1072 |
+
position_width = position_width.repeat(llm_grid_h * llm_grid_t)
|
| 1073 |
+
position_height = position_height.repeat_interleave(llm_grid_w).repeat(llm_grid_t)
|
| 1074 |
+
# Important: add `start_positions` after applying `time_interval`, order matters
|
| 1075 |
+
position_temporal = position_temporal.repeat_interleave(llm_grid_h * llm_grid_w) + start_position
|
| 1076 |
+
vision_position_ids = torch.stack([position_temporal, position_height, position_width], dim=0)
|
| 1077 |
+
|
| 1078 |
+
return vision_position_ids
|
| 1079 |
+
|
| 1080 |
+
def get_rope_index(
|
| 1081 |
+
self,
|
| 1082 |
+
input_ids: torch.LongTensor,
|
| 1083 |
+
mm_token_type_ids: torch.IntTensor,
|
| 1084 |
+
image_grid_thw: torch.LongTensor | None = None,
|
| 1085 |
+
video_grid_thw: torch.LongTensor | None = None,
|
| 1086 |
+
attention_mask: torch.Tensor | None = None,
|
| 1087 |
+
**kwargs,
|
| 1088 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 1089 |
+
"""
|
| 1090 |
+
Difference from Qwen2VL/Qwen2.5VL's get_rope_index:
|
| 1091 |
+
- Since Qwen3.5 use timestamps to separate videos, like <t1> <vision_start> <frame1> <vision_end> <t2> <vision_start> <frame2> <vision_end>, the video_grid_thw should also be split too.
|
| 1092 |
+
|
| 1093 |
+
Args:
|
| 1094 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 1095 |
+
Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide
|
| 1096 |
+
it.
|
| 1097 |
+
mm_token_type_ids (`torch.IntTensor` of shape `(batch_size, sequence_length)`):
|
| 1098 |
+
Token type ids matching each modality to a different value in the input sequence, i.e. text (0), image (1), video (2).
|
| 1099 |
+
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
|
| 1100 |
+
The temporal, height and width of feature shape of each image in LLM.
|
| 1101 |
+
video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
|
| 1102 |
+
The temporal, height and width of feature shape of each video in LLM.
|
| 1103 |
+
attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1104 |
+
Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:
|
| 1105 |
+
|
| 1106 |
+
- 1 for tokens that are **not masked**,
|
| 1107 |
+
- 0 for tokens that are **masked**.
|
| 1108 |
+
|
| 1109 |
+
Returns:
|
| 1110 |
+
position_ids (`torch.LongTensor` of shape `(3, batch_size, sequence_length)`)
|
| 1111 |
+
mrope_position_deltas (`torch.Tensor` of shape `(batch_size)`)
|
| 1112 |
+
"""
|
| 1113 |
+
|
| 1114 |
+
# Separate video grid thw into multiple grids because timestamps are used to separate videos.
|
| 1115 |
+
if video_grid_thw is not None:
|
| 1116 |
+
video_grid_thw = torch.repeat_interleave(video_grid_thw, video_grid_thw[:, 0], dim=0)
|
| 1117 |
+
video_grid_thw[:, 0] = 1
|
| 1118 |
+
spatial_merge_size = self.config.vision_config.spatial_merge_size
|
| 1119 |
+
|
| 1120 |
+
mrope_position_deltas = []
|
| 1121 |
+
position_ids = torch.zeros(
|
| 1122 |
+
3,
|
| 1123 |
+
input_ids.shape[0],
|
| 1124 |
+
input_ids.shape[1],
|
| 1125 |
+
dtype=input_ids.dtype,
|
| 1126 |
+
device=input_ids.device,
|
| 1127 |
+
)
|
| 1128 |
+
grid_iters = {
|
| 1129 |
+
1: iter(image_grid_thw) if image_grid_thw is not None else None,
|
| 1130 |
+
2: iter(video_grid_thw) if video_grid_thw is not None else None,
|
| 1131 |
+
}
|
| 1132 |
+
|
| 1133 |
+
for batch_idx, current_input_ids in enumerate(input_ids):
|
| 1134 |
+
input_token_type = mm_token_type_ids[batch_idx]
|
| 1135 |
+
if attention_mask is not None:
|
| 1136 |
+
current_input_ids = current_input_ids[attention_mask[batch_idx].bool()]
|
| 1137 |
+
input_token_type = input_token_type[attention_mask[batch_idx].bool()]
|
| 1138 |
+
|
| 1139 |
+
input_type_group = []
|
| 1140 |
+
for key, group in itertools.groupby(enumerate(input_token_type.tolist()), lambda x: x[1]):
|
| 1141 |
+
group = list(group)
|
| 1142 |
+
start_index = group[0][0]
|
| 1143 |
+
end_index = group[-1][0] + 1
|
| 1144 |
+
input_type_group.append((key, start_index, end_index))
|
| 1145 |
+
|
| 1146 |
+
current_pos = 0
|
| 1147 |
+
llm_pos_ids_list = []
|
| 1148 |
+
for modality_type, start_idx, end_idx in input_type_group:
|
| 1149 |
+
# text == 0
|
| 1150 |
+
if modality_type == 0:
|
| 1151 |
+
text_len = end_idx - start_idx
|
| 1152 |
+
llm_pos_ids_list.append(
|
| 1153 |
+
torch.arange(text_len, device=input_ids.device).view(1, -1).expand(3, -1) + current_pos
|
| 1154 |
+
)
|
| 1155 |
+
current_pos += text_len
|
| 1156 |
+
# image == 1, video == 2
|
| 1157 |
+
else:
|
| 1158 |
+
grid_thw = next(grid_iters[modality_type])
|
| 1159 |
+
vision_position_ids = self.get_vision_position_ids(
|
| 1160 |
+
current_pos, grid_thw, 1, spatial_merge_size, device=input_ids.device
|
| 1161 |
+
)
|
| 1162 |
+
llm_pos_ids_list.append(vision_position_ids)
|
| 1163 |
+
current_pos += max(grid_thw[1], grid_thw[2]) // spatial_merge_size
|
| 1164 |
+
llm_positions = torch.cat(llm_pos_ids_list, dim=1).reshape(3, -1)
|
| 1165 |
+
if attention_mask is not None:
|
| 1166 |
+
position_ids[:, batch_idx, attention_mask[batch_idx].bool()] = llm_positions.to(position_ids.device)
|
| 1167 |
+
else:
|
| 1168 |
+
position_ids[:, batch_idx] = llm_positions.to(position_ids.device)
|
| 1169 |
+
mrope_position_deltas.append(llm_positions.max() + 1 - len(current_input_ids))
|
| 1170 |
+
mrope_position_deltas = torch.tensor(mrope_position_deltas, device=input_ids.device).unsqueeze(1)
|
| 1171 |
+
return position_ids, mrope_position_deltas
|
| 1172 |
+
|
| 1173 |
+
@accepts_precomputed_kwargs(modality="video")
|
| 1174 |
+
@can_return_tuple
|
| 1175 |
+
@auto_docstring
|
| 1176 |
+
def get_video_features(
|
| 1177 |
+
self,
|
| 1178 |
+
pixel_values_videos: torch.FloatTensor,
|
| 1179 |
+
video_grid_thw: torch.LongTensor | None = None,
|
| 1180 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1181 |
+
) -> tuple | BaseModelOutputWithDeepstackFeatures:
|
| 1182 |
+
r"""
|
| 1183 |
+
pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
|
| 1184 |
+
The tensors corresponding to the input videos.
|
| 1185 |
+
video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
|
| 1186 |
+
The temporal, height and width of feature shape of each video in LLM.
|
| 1187 |
+
"""
|
| 1188 |
+
# Same implementation as for images
|
| 1189 |
+
return self.get_image_features(pixel_values_videos, video_grid_thw, **kwargs)
|
| 1190 |
+
|
| 1191 |
+
@accepts_precomputed_kwargs(modality="image")
|
| 1192 |
+
@can_return_tuple
|
| 1193 |
+
@auto_docstring
|
| 1194 |
+
def get_image_features(
|
| 1195 |
+
self,
|
| 1196 |
+
pixel_values: torch.FloatTensor,
|
| 1197 |
+
image_grid_thw: torch.LongTensor | None = None,
|
| 1198 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1199 |
+
) -> tuple | BaseModelOutputWithDeepstackFeatures:
|
| 1200 |
+
r"""
|
| 1201 |
+
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
|
| 1202 |
+
The tensors corresponding to the input images.
|
| 1203 |
+
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
|
| 1204 |
+
The temporal, height and width of feature shape of each image in LLM.
|
| 1205 |
+
"""
|
| 1206 |
+
pixel_values = pixel_values.type(self.visual.dtype)
|
| 1207 |
+
vision_output: BaseModelOutputWithDeepstackFeatures = self.visual(
|
| 1208 |
+
pixel_values, grid_thw=image_grid_thw, return_dict=True, **kwargs
|
| 1209 |
+
)
|
| 1210 |
+
image_embeds = vision_output.pooler_output
|
| 1211 |
+
split_sizes = (image_grid_thw.prod(-1) // self.visual.spatial_merge_size**2).tolist()
|
| 1212 |
+
image_embeds = torch.split(image_embeds, split_sizes)
|
| 1213 |
+
vision_output.pooler_output = image_embeds
|
| 1214 |
+
|
| 1215 |
+
return vision_output
|
| 1216 |
+
|
| 1217 |
+
def get_placeholder_mask(
|
| 1218 |
+
self,
|
| 1219 |
+
input_ids: torch.LongTensor,
|
| 1220 |
+
inputs_embeds: torch.FloatTensor,
|
| 1221 |
+
image_features: torch.FloatTensor | None = None,
|
| 1222 |
+
video_features: torch.FloatTensor | None = None,
|
| 1223 |
+
):
|
| 1224 |
+
"""
|
| 1225 |
+
Obtains multimodal placeholder mask from `input_ids` or `inputs_embeds`, and checks that the placeholder token count is
|
| 1226 |
+
equal to the length of multimodal features. If the lengths are different, an error is raised.
|
| 1227 |
+
"""
|
| 1228 |
+
if input_ids is None:
|
| 1229 |
+
special_image_mask = inputs_embeds == self.get_input_embeddings()(
|
| 1230 |
+
torch.tensor(self.config.image_token_id, dtype=torch.long, device=inputs_embeds.device)
|
| 1231 |
+
)
|
| 1232 |
+
special_image_mask = special_image_mask.all(-1)
|
| 1233 |
+
special_video_mask = inputs_embeds == self.get_input_embeddings()(
|
| 1234 |
+
torch.tensor(self.config.video_token_id, dtype=torch.long, device=inputs_embeds.device)
|
| 1235 |
+
)
|
| 1236 |
+
special_video_mask = special_video_mask.all(-1)
|
| 1237 |
+
else:
|
| 1238 |
+
special_image_mask = input_ids == self.config.image_token_id
|
| 1239 |
+
special_video_mask = input_ids == self.config.video_token_id
|
| 1240 |
+
|
| 1241 |
+
n_image_tokens = special_image_mask.sum()
|
| 1242 |
+
special_image_mask = special_image_mask.unsqueeze(-1).expand_as(inputs_embeds).to(inputs_embeds.device)
|
| 1243 |
+
if image_features is not None:
|
| 1244 |
+
torch_compilable_check(
|
| 1245 |
+
inputs_embeds[special_image_mask].numel() == image_features.numel(),
|
| 1246 |
+
f"Image features and image tokens do not match, tokens: {n_image_tokens}, features: {image_features.shape[0]}",
|
| 1247 |
+
)
|
| 1248 |
+
|
| 1249 |
+
n_video_tokens = special_video_mask.sum()
|
| 1250 |
+
special_video_mask = special_video_mask.unsqueeze(-1).expand_as(inputs_embeds).to(inputs_embeds.device)
|
| 1251 |
+
if video_features is not None:
|
| 1252 |
+
torch_compilable_check(
|
| 1253 |
+
inputs_embeds[special_video_mask].numel() == video_features.numel(),
|
| 1254 |
+
f"Video features and video tokens do not match, tokens: {n_video_tokens}, features: {video_features.shape[0]}",
|
| 1255 |
+
)
|
| 1256 |
+
return special_image_mask, special_video_mask
|
| 1257 |
+
|
| 1258 |
+
def compute_3d_position_ids(
|
| 1259 |
+
self,
|
| 1260 |
+
input_ids: torch.Tensor | None,
|
| 1261 |
+
inputs_embeds: torch.Tensor | None,
|
| 1262 |
+
image_grid_thw: torch.Tensor | None = None,
|
| 1263 |
+
video_grid_thw: torch.Tensor | None = None,
|
| 1264 |
+
attention_mask: torch.Tensor | None = None,
|
| 1265 |
+
past_key_values: torch.Tensor | None = None,
|
| 1266 |
+
mm_token_type_ids: torch.IntTensor | None = None,
|
| 1267 |
+
) -> torch.Tensor | None:
|
| 1268 |
+
past_key_values_length = 0 if past_key_values is None else past_key_values.get_seq_length()
|
| 1269 |
+
has_multimodal = image_grid_thw is not None or video_grid_thw is not None
|
| 1270 |
+
if has_multimodal and mm_token_type_ids is None and input_ids is not None:
|
| 1271 |
+
raise ValueError(
|
| 1272 |
+
"Multimodal data was passed (via `image_grid_thw` or `video_grid_thw`) but `mm_token_type_ids` is "
|
| 1273 |
+
"missing. Please pass `mm_token_type_ids` to the model so that multimodal RoPE (M-RoPE) can be "
|
| 1274 |
+
"computed correctly. `mm_token_type_ids` is returned by the processor alongside `input_ids`."
|
| 1275 |
+
)
|
| 1276 |
+
can_compute_mrope = input_ids is not None and mm_token_type_ids is not None and has_multimodal
|
| 1277 |
+
|
| 1278 |
+
if can_compute_mrope and (self.rope_deltas is None or past_key_values_length == 0):
|
| 1279 |
+
position_ids, rope_deltas = self.get_rope_index(
|
| 1280 |
+
input_ids,
|
| 1281 |
+
image_grid_thw=image_grid_thw,
|
| 1282 |
+
video_grid_thw=video_grid_thw,
|
| 1283 |
+
attention_mask=attention_mask,
|
| 1284 |
+
mm_token_type_ids=mm_token_type_ids,
|
| 1285 |
+
)
|
| 1286 |
+
self.rope_deltas = rope_deltas
|
| 1287 |
+
# Use pre-calculated rope-deltas to infer correct 3D position ids during incremental
|
| 1288 |
+
# generation (past_key_values_length > 0) or when only inputs_embeds is provided (no input_ids
|
| 1289 |
+
# to recompute from). Skip when input_ids is provided without past_key_values to avoid shape
|
| 1290 |
+
# mismatches from stale rope_deltas (e.g., training forward pass after generation).
|
| 1291 |
+
elif self.rope_deltas is not None and (past_key_values_length > 0 or input_ids is None):
|
| 1292 |
+
batch_size, seq_length, _ = inputs_embeds.shape
|
| 1293 |
+
if attention_mask is not None:
|
| 1294 |
+
position_ids = attention_mask.long().cumsum(-1) - 1
|
| 1295 |
+
position_ids = position_ids.masked_fill(attention_mask == 0, 0)
|
| 1296 |
+
position_ids = position_ids.view(1, batch_size, -1).repeat(3, 1, 1).to(inputs_embeds.device)
|
| 1297 |
+
else:
|
| 1298 |
+
position_ids = torch.arange(past_key_values_length, past_key_values_length + seq_length)
|
| 1299 |
+
position_ids = position_ids.view(1, 1, -1).expand(3, batch_size, -1).to(inputs_embeds.device)
|
| 1300 |
+
delta = self.rope_deltas.repeat_interleave(batch_size // self.rope_deltas.shape[0], dim=0)
|
| 1301 |
+
position_ids = position_ids + delta.to(device=inputs_embeds.device)
|
| 1302 |
+
else:
|
| 1303 |
+
# Can't build correct 3D positions. Let the model infer it
|
| 1304 |
+
position_ids = None
|
| 1305 |
+
return position_ids
|
| 1306 |
+
|
| 1307 |
+
@auto_docstring
|
| 1308 |
+
@can_return_tuple
|
| 1309 |
+
def forward(
|
| 1310 |
+
self,
|
| 1311 |
+
input_ids: torch.LongTensor = None,
|
| 1312 |
+
attention_mask: torch.Tensor | None = None,
|
| 1313 |
+
position_ids: torch.LongTensor | None = None,
|
| 1314 |
+
past_key_values: Cache | None = None,
|
| 1315 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 1316 |
+
pixel_values: torch.Tensor | None = None,
|
| 1317 |
+
pixel_values_videos: torch.FloatTensor | None = None,
|
| 1318 |
+
image_grid_thw: torch.LongTensor | None = None,
|
| 1319 |
+
video_grid_thw: torch.LongTensor | None = None,
|
| 1320 |
+
mm_token_type_ids: torch.IntTensor | None = None,
|
| 1321 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1322 |
+
) -> tuple | Qwen3VLMoeModelOutputWithPast:
|
| 1323 |
+
r"""
|
| 1324 |
+
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
|
| 1325 |
+
The temporal, height and width of feature shape of each image in LLM.
|
| 1326 |
+
video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
|
| 1327 |
+
The temporal, height and width of feature shape of each video in LLM.
|
| 1328 |
+
"""
|
| 1329 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 1330 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 1331 |
+
|
| 1332 |
+
if inputs_embeds is None:
|
| 1333 |
+
inputs_embeds = self.get_input_embeddings()(input_ids)
|
| 1334 |
+
|
| 1335 |
+
image_mask = None
|
| 1336 |
+
video_mask = None
|
| 1337 |
+
|
| 1338 |
+
if pixel_values is not None:
|
| 1339 |
+
image_outputs: BaseModelOutputWithDeepstackFeatures = self.get_image_features(
|
| 1340 |
+
pixel_values, image_grid_thw, return_dict=True, **kwargs
|
| 1341 |
+
)
|
| 1342 |
+
image_embeds = image_outputs.pooler_output
|
| 1343 |
+
deepstack_image_embeds = image_outputs.deepstack_features
|
| 1344 |
+
image_embeds = torch.cat(image_embeds, dim=0).to(inputs_embeds.device, inputs_embeds.dtype)
|
| 1345 |
+
image_mask, _ = self.get_placeholder_mask(
|
| 1346 |
+
input_ids, inputs_embeds=inputs_embeds, image_features=image_embeds
|
| 1347 |
+
)
|
| 1348 |
+
inputs_embeds = inputs_embeds.masked_scatter(image_mask, image_embeds)
|
| 1349 |
+
|
| 1350 |
+
if pixel_values_videos is not None:
|
| 1351 |
+
video_outputs: BaseModelOutputWithDeepstackFeatures = self.get_video_features(
|
| 1352 |
+
pixel_values_videos, video_grid_thw, return_dict=True, **kwargs
|
| 1353 |
+
)
|
| 1354 |
+
video_embeds = video_outputs.pooler_output
|
| 1355 |
+
deepstack_video_embeds = video_outputs.deepstack_features
|
| 1356 |
+
video_embeds = torch.cat(video_embeds, dim=0).to(inputs_embeds.device, inputs_embeds.dtype)
|
| 1357 |
+
_, video_mask = self.get_placeholder_mask(
|
| 1358 |
+
input_ids, inputs_embeds=inputs_embeds, video_features=video_embeds
|
| 1359 |
+
)
|
| 1360 |
+
inputs_embeds = inputs_embeds.masked_scatter(video_mask, video_embeds)
|
| 1361 |
+
|
| 1362 |
+
visual_pos_masks = None
|
| 1363 |
+
deepstack_visual_embeds = None
|
| 1364 |
+
if image_mask is not None and video_mask is not None:
|
| 1365 |
+
# aggregate visual_pos_masks and deepstack_visual_embeds
|
| 1366 |
+
image_mask = image_mask[..., 0]
|
| 1367 |
+
video_mask = video_mask[..., 0]
|
| 1368 |
+
visual_pos_masks = image_mask | video_mask
|
| 1369 |
+
deepstack_visual_embeds = []
|
| 1370 |
+
image_mask_joint = image_mask[visual_pos_masks]
|
| 1371 |
+
video_mask_joint = video_mask[visual_pos_masks]
|
| 1372 |
+
for img_embed, vid_embed in zip(deepstack_image_embeds, deepstack_video_embeds):
|
| 1373 |
+
embed_joint = img_embed.new_zeros(visual_pos_masks.sum(), img_embed.shape[-1]).to(img_embed.device)
|
| 1374 |
+
embed_joint[image_mask_joint, :] = img_embed
|
| 1375 |
+
embed_joint[video_mask_joint, :] = vid_embed
|
| 1376 |
+
deepstack_visual_embeds.append(embed_joint)
|
| 1377 |
+
elif image_mask is not None:
|
| 1378 |
+
image_mask = image_mask[..., 0]
|
| 1379 |
+
visual_pos_masks = image_mask
|
| 1380 |
+
deepstack_visual_embeds = deepstack_image_embeds
|
| 1381 |
+
elif video_mask is not None:
|
| 1382 |
+
video_mask = video_mask[..., 0]
|
| 1383 |
+
visual_pos_masks = video_mask
|
| 1384 |
+
deepstack_visual_embeds = deepstack_video_embeds
|
| 1385 |
+
|
| 1386 |
+
if position_ids is None:
|
| 1387 |
+
position_ids = self.compute_3d_position_ids(
|
| 1388 |
+
input_ids=input_ids,
|
| 1389 |
+
image_grid_thw=image_grid_thw,
|
| 1390 |
+
video_grid_thw=video_grid_thw,
|
| 1391 |
+
inputs_embeds=inputs_embeds,
|
| 1392 |
+
attention_mask=attention_mask,
|
| 1393 |
+
past_key_values=past_key_values,
|
| 1394 |
+
mm_token_type_ids=mm_token_type_ids,
|
| 1395 |
+
)
|
| 1396 |
+
|
| 1397 |
+
outputs = self.language_model(
|
| 1398 |
+
input_ids=None,
|
| 1399 |
+
position_ids=position_ids,
|
| 1400 |
+
attention_mask=attention_mask,
|
| 1401 |
+
past_key_values=past_key_values,
|
| 1402 |
+
inputs_embeds=inputs_embeds,
|
| 1403 |
+
visual_pos_masks=visual_pos_masks,
|
| 1404 |
+
deepstack_visual_embeds=deepstack_visual_embeds,
|
| 1405 |
+
**kwargs,
|
| 1406 |
+
)
|
| 1407 |
+
|
| 1408 |
+
return Qwen3VLMoeModelOutputWithPast(
|
| 1409 |
+
**outputs,
|
| 1410 |
+
rope_deltas=self.rope_deltas,
|
| 1411 |
+
)
|
| 1412 |
+
|
| 1413 |
+
|
| 1414 |
+
def load_balancing_loss_func(
|
| 1415 |
+
gate_logits: torch.Tensor | tuple[torch.Tensor] | None,
|
| 1416 |
+
num_experts: int | None = None,
|
| 1417 |
+
top_k=2,
|
| 1418 |
+
attention_mask: torch.Tensor | None = None,
|
| 1419 |
+
) -> torch.Tensor | int:
|
| 1420 |
+
r"""
|
| 1421 |
+
Computes auxiliary load balancing loss as in Switch Transformer - implemented in Pytorch.
|
| 1422 |
+
|
| 1423 |
+
See Switch Transformer (https://huggingface.co/papers/2101.03961) for more details. This function implements the loss
|
| 1424 |
+
function presented in equations (4) - (6) of the paper. It aims at penalizing cases where the routing between
|
| 1425 |
+
experts is too unbalanced.
|
| 1426 |
+
|
| 1427 |
+
Args:
|
| 1428 |
+
gate_logits:
|
| 1429 |
+
Logits from the `gate`, should be a tuple of model.config.num_hidden_layers tensors of
|
| 1430 |
+
shape [batch_size X sequence_length, num_experts].
|
| 1431 |
+
num_experts:
|
| 1432 |
+
Number of experts
|
| 1433 |
+
top_k:
|
| 1434 |
+
The number of experts to route per-token, can be also interpreted as the `top-k` routing
|
| 1435 |
+
parameter.
|
| 1436 |
+
attention_mask (`torch.Tensor`, *optional*):
|
| 1437 |
+
The attention_mask used in forward function
|
| 1438 |
+
shape [batch_size X sequence_length] if not None.
|
| 1439 |
+
|
| 1440 |
+
Returns:
|
| 1441 |
+
The auxiliary loss.
|
| 1442 |
+
"""
|
| 1443 |
+
if gate_logits is None or not isinstance(gate_logits, tuple):
|
| 1444 |
+
return 0
|
| 1445 |
+
|
| 1446 |
+
if isinstance(gate_logits, tuple):
|
| 1447 |
+
compute_device = gate_logits[0].device
|
| 1448 |
+
concatenated_gate_logits = torch.cat([layer_gate.to(compute_device) for layer_gate in gate_logits], dim=0)
|
| 1449 |
+
|
| 1450 |
+
routing_weights = torch.nn.functional.softmax(concatenated_gate_logits, dim=-1)
|
| 1451 |
+
|
| 1452 |
+
_, selected_experts = torch.topk(routing_weights, top_k, dim=-1)
|
| 1453 |
+
|
| 1454 |
+
expert_mask = torch.nn.functional.one_hot(selected_experts, num_experts)
|
| 1455 |
+
|
| 1456 |
+
if attention_mask is None:
|
| 1457 |
+
# Compute the percentage of tokens routed to each experts
|
| 1458 |
+
tokens_per_expert = torch.mean(expert_mask.float(), dim=0)
|
| 1459 |
+
|
| 1460 |
+
# Compute the average probability of routing to these experts
|
| 1461 |
+
router_prob_per_expert = torch.mean(routing_weights, dim=0)
|
| 1462 |
+
else:
|
| 1463 |
+
batch_size, sequence_length = attention_mask.shape
|
| 1464 |
+
num_hidden_layers = concatenated_gate_logits.shape[0] // (batch_size * sequence_length)
|
| 1465 |
+
|
| 1466 |
+
# Compute the mask that masks all padding tokens as 0 with the same shape of expert_mask
|
| 1467 |
+
expert_attention_mask = (
|
| 1468 |
+
attention_mask[None, :, :, None, None]
|
| 1469 |
+
.expand((num_hidden_layers, batch_size, sequence_length, top_k, num_experts))
|
| 1470 |
+
.reshape(-1, top_k, num_experts)
|
| 1471 |
+
.to(compute_device)
|
| 1472 |
+
)
|
| 1473 |
+
|
| 1474 |
+
# Compute the percentage of tokens routed to each experts
|
| 1475 |
+
tokens_per_expert = torch.sum(expert_mask.float() * expert_attention_mask, dim=0) / torch.sum(
|
| 1476 |
+
expert_attention_mask, dim=0
|
| 1477 |
+
)
|
| 1478 |
+
|
| 1479 |
+
# Compute the mask that masks all padding tokens as 0 with the same shape of tokens_per_expert
|
| 1480 |
+
router_per_expert_attention_mask = (
|
| 1481 |
+
attention_mask[None, :, :, None]
|
| 1482 |
+
.expand((num_hidden_layers, batch_size, sequence_length, num_experts))
|
| 1483 |
+
.reshape(-1, num_experts)
|
| 1484 |
+
.to(compute_device)
|
| 1485 |
+
)
|
| 1486 |
+
|
| 1487 |
+
# Compute the average probability of routing to these experts
|
| 1488 |
+
router_prob_per_expert = torch.sum(routing_weights * router_per_expert_attention_mask, dim=0) / torch.sum(
|
| 1489 |
+
router_per_expert_attention_mask, dim=0
|
| 1490 |
+
)
|
| 1491 |
+
|
| 1492 |
+
overall_loss = torch.sum(tokens_per_expert * router_prob_per_expert.unsqueeze(0))
|
| 1493 |
+
return overall_loss * num_experts
|
| 1494 |
+
|
| 1495 |
+
|
| 1496 |
+
class Qwen3VLMoeForConditionalGeneration(Qwen3VLMoePreTrainedModel, GenerationMixin):
|
| 1497 |
+
_tied_weights_keys = {"lm_head.weight": "model.language_model.embed_tokens.weight"}
|
| 1498 |
+
# Reference: fix gemma3 grad acc #37208
|
| 1499 |
+
accepts_loss_kwargs = False
|
| 1500 |
+
config: Qwen3VLMoeConfig
|
| 1501 |
+
|
| 1502 |
+
def __init__(self, config):
|
| 1503 |
+
super().__init__(config)
|
| 1504 |
+
self.model = Qwen3VLMoeModel(config)
|
| 1505 |
+
self.lm_head = nn.Linear(config.text_config.hidden_size, config.text_config.vocab_size, bias=False)
|
| 1506 |
+
|
| 1507 |
+
self.post_init()
|
| 1508 |
+
|
| 1509 |
+
@auto_docstring
|
| 1510 |
+
def get_video_features(
|
| 1511 |
+
self,
|
| 1512 |
+
pixel_values_videos: torch.FloatTensor,
|
| 1513 |
+
video_grid_thw: torch.LongTensor | None = None,
|
| 1514 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1515 |
+
) -> tuple | BaseModelOutputWithDeepstackFeatures:
|
| 1516 |
+
r"""
|
| 1517 |
+
pixel_values_videos (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
|
| 1518 |
+
The tensors corresponding to the input videos.
|
| 1519 |
+
video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
|
| 1520 |
+
The temporal, height and width of feature shape of each video in LLM.
|
| 1521 |
+
"""
|
| 1522 |
+
return self.model.get_video_features(pixel_values_videos, video_grid_thw, **kwargs)
|
| 1523 |
+
|
| 1524 |
+
@auto_docstring
|
| 1525 |
+
def get_image_features(
|
| 1526 |
+
self,
|
| 1527 |
+
pixel_values: torch.FloatTensor,
|
| 1528 |
+
image_grid_thw: torch.LongTensor | None = None,
|
| 1529 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1530 |
+
) -> tuple | BaseModelOutputWithDeepstackFeatures:
|
| 1531 |
+
r"""
|
| 1532 |
+
pixel_values (`torch.FloatTensor` of shape `(batch_size, num_channels, image_size, image_size)`):
|
| 1533 |
+
The tensors corresponding to the input images.
|
| 1534 |
+
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
|
| 1535 |
+
The temporal, height and width of feature shape of each image in LLM.
|
| 1536 |
+
"""
|
| 1537 |
+
return self.model.get_image_features(pixel_values, image_grid_thw, **kwargs)
|
| 1538 |
+
|
| 1539 |
+
@can_return_tuple
|
| 1540 |
+
def forward(
|
| 1541 |
+
self,
|
| 1542 |
+
input_ids: torch.LongTensor = None,
|
| 1543 |
+
attention_mask: torch.Tensor | None = None,
|
| 1544 |
+
position_ids: torch.LongTensor | None = None,
|
| 1545 |
+
past_key_values: Cache | None = None,
|
| 1546 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 1547 |
+
labels: torch.LongTensor | None = None,
|
| 1548 |
+
pixel_values: torch.Tensor | None = None,
|
| 1549 |
+
pixel_values_videos: torch.FloatTensor | None = None,
|
| 1550 |
+
image_grid_thw: torch.LongTensor | None = None,
|
| 1551 |
+
video_grid_thw: torch.LongTensor | None = None,
|
| 1552 |
+
mm_token_type_ids: torch.IntTensor | None = None,
|
| 1553 |
+
logits_to_keep: int | torch.Tensor = 0,
|
| 1554 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 1555 |
+
) -> tuple | Qwen3VLMoeCausalLMOutputWithPast:
|
| 1556 |
+
r"""
|
| 1557 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 1558 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 1559 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 1560 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 1561 |
+
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
|
| 1562 |
+
The temporal, height and width of feature shape of each image in LLM.
|
| 1563 |
+
video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
|
| 1564 |
+
The temporal, height and width of feature shape of each video in LLM.
|
| 1565 |
+
|
| 1566 |
+
Example:
|
| 1567 |
+
```python
|
| 1568 |
+
>>> from PIL import Image
|
| 1569 |
+
>>> import httpx
|
| 1570 |
+
>>> from io import BytesIO
|
| 1571 |
+
>>> from transformers import AutoProcessor, Qwen3VLMoeForConditionalGeneration
|
| 1572 |
+
|
| 1573 |
+
>>> model = Qwen3VLMoeForConditionalGeneration.from_pretrained("Qwen/Qwen3-VL-30B-A3B-Instruct", dtype="auto", device_map="auto")
|
| 1574 |
+
>>> processor = AutoProcessor.from_pretrained("Qwen/Qwen3-VL-30B-A3B-Instruct")
|
| 1575 |
+
|
| 1576 |
+
>>> messages = [
|
| 1577 |
+
{
|
| 1578 |
+
"role": "user",
|
| 1579 |
+
"content": [
|
| 1580 |
+
{
|
| 1581 |
+
"type": "image",
|
| 1582 |
+
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
|
| 1583 |
+
},
|
| 1584 |
+
{"type": "text", "text": "Describe this image in short."},
|
| 1585 |
+
],
|
| 1586 |
+
}
|
| 1587 |
+
]
|
| 1588 |
+
|
| 1589 |
+
>>> # Preparation for inference
|
| 1590 |
+
>>> inputs = processor.apply_chat_template(
|
| 1591 |
+
messages,
|
| 1592 |
+
tokenize=True,
|
| 1593 |
+
add_generation_prompt=True,
|
| 1594 |
+
return_dict=True,
|
| 1595 |
+
return_tensors="pt"
|
| 1596 |
+
)
|
| 1597 |
+
>>> inputs = inputs.to(model.device)
|
| 1598 |
+
|
| 1599 |
+
>>> # Generate
|
| 1600 |
+
>>> generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 1601 |
+
>>> generated_ids_trimmed = [
|
| 1602 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 1603 |
+
]
|
| 1604 |
+
>>> processor.batch_decode(generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 1605 |
+
"A woman in a plaid shirt sits on a sandy beach at sunset, smiling as she gives a high-five to a yellow Labrador Retriever wearing a harness. The ocean waves roll in the background."
|
| 1606 |
+
```"""
|
| 1607 |
+
|
| 1608 |
+
outputs = self.model(
|
| 1609 |
+
input_ids=input_ids,
|
| 1610 |
+
pixel_values=pixel_values,
|
| 1611 |
+
pixel_values_videos=pixel_values_videos,
|
| 1612 |
+
image_grid_thw=image_grid_thw,
|
| 1613 |
+
video_grid_thw=video_grid_thw,
|
| 1614 |
+
mm_token_type_ids=mm_token_type_ids,
|
| 1615 |
+
position_ids=position_ids,
|
| 1616 |
+
attention_mask=attention_mask,
|
| 1617 |
+
past_key_values=past_key_values,
|
| 1618 |
+
inputs_embeds=inputs_embeds,
|
| 1619 |
+
**kwargs,
|
| 1620 |
+
)
|
| 1621 |
+
|
| 1622 |
+
hidden_states = outputs[0]
|
| 1623 |
+
|
| 1624 |
+
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
| 1625 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 1626 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 1627 |
+
|
| 1628 |
+
loss = None
|
| 1629 |
+
if labels is not None:
|
| 1630 |
+
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size)
|
| 1631 |
+
|
| 1632 |
+
aux_loss = None
|
| 1633 |
+
if kwargs.get("output_router_logits", False):
|
| 1634 |
+
aux_loss = load_balancing_loss_func(
|
| 1635 |
+
outputs.router_logits,
|
| 1636 |
+
self.config.text_config.num_experts,
|
| 1637 |
+
self.config.text_config.num_experts_per_tok,
|
| 1638 |
+
attention_mask,
|
| 1639 |
+
)
|
| 1640 |
+
if labels is not None:
|
| 1641 |
+
loss += self.config.text_config.router_aux_loss_coef * aux_loss.to(
|
| 1642 |
+
loss.device
|
| 1643 |
+
) # make sure to reside in the same device
|
| 1644 |
+
|
| 1645 |
+
return Qwen3VLMoeCausalLMOutputWithPast(
|
| 1646 |
+
loss=loss,
|
| 1647 |
+
aux_loss=aux_loss,
|
| 1648 |
+
logits=logits,
|
| 1649 |
+
past_key_values=outputs.past_key_values,
|
| 1650 |
+
hidden_states=outputs.hidden_states,
|
| 1651 |
+
attentions=outputs.attentions,
|
| 1652 |
+
rope_deltas=outputs.rope_deltas,
|
| 1653 |
+
router_logits=outputs.router_logits,
|
| 1654 |
+
)
|
| 1655 |
+
|
| 1656 |
+
def prepare_inputs_for_generation(
|
| 1657 |
+
self,
|
| 1658 |
+
input_ids,
|
| 1659 |
+
past_key_values=None,
|
| 1660 |
+
attention_mask=None,
|
| 1661 |
+
inputs_embeds=None,
|
| 1662 |
+
position_ids=None,
|
| 1663 |
+
use_cache=True,
|
| 1664 |
+
pixel_values=None,
|
| 1665 |
+
pixel_values_videos=None,
|
| 1666 |
+
image_grid_thw=None,
|
| 1667 |
+
video_grid_thw=None,
|
| 1668 |
+
is_first_iteration=False,
|
| 1669 |
+
**kwargs,
|
| 1670 |
+
):
|
| 1671 |
+
# Overwritten -- in specific circumstances we don't want to forward image inputs to the model
|
| 1672 |
+
|
| 1673 |
+
model_inputs = super().prepare_inputs_for_generation(
|
| 1674 |
+
input_ids,
|
| 1675 |
+
past_key_values=past_key_values,
|
| 1676 |
+
attention_mask=attention_mask,
|
| 1677 |
+
inputs_embeds=inputs_embeds,
|
| 1678 |
+
position_ids=position_ids,
|
| 1679 |
+
pixel_values=pixel_values,
|
| 1680 |
+
pixel_values_videos=pixel_values_videos,
|
| 1681 |
+
image_grid_thw=image_grid_thw,
|
| 1682 |
+
video_grid_thw=video_grid_thw,
|
| 1683 |
+
use_cache=use_cache,
|
| 1684 |
+
is_first_iteration=is_first_iteration,
|
| 1685 |
+
**kwargs,
|
| 1686 |
+
)
|
| 1687 |
+
|
| 1688 |
+
if not is_first_iteration and use_cache:
|
| 1689 |
+
model_inputs["pixel_values"] = None
|
| 1690 |
+
model_inputs["pixel_values_videos"] = None
|
| 1691 |
+
|
| 1692 |
+
return model_inputs
|
| 1693 |
+
|
| 1694 |
+
def _prepare_position_ids_for_generation(self, inputs_tensor, model_kwargs):
|
| 1695 |
+
# Overwritten -- requires 3D position ids
|
| 1696 |
+
|
| 1697 |
+
text_positions = super()._prepare_position_ids_for_generation(inputs_tensor, model_kwargs)
|
| 1698 |
+
|
| 1699 |
+
# Early exit in case we are continuing generation from past kv
|
| 1700 |
+
past_length = 0
|
| 1701 |
+
if (cache := model_kwargs.get("past_key_values")) is not None:
|
| 1702 |
+
past_length = cache.get_seq_length()
|
| 1703 |
+
if past_length != 0 and self.model.rope_deltas is not None:
|
| 1704 |
+
position_ids = text_positions[None, ...] + self.model.rope_deltas
|
| 1705 |
+
return position_ids
|
| 1706 |
+
|
| 1707 |
+
# Otherwise compute 3d position ids for vision tokens and concat with text position ids
|
| 1708 |
+
if "input_ids" in model_kwargs and model_kwargs["input_ids"].shape[1] > 0:
|
| 1709 |
+
inputs_tensor = model_kwargs["input_ids"]
|
| 1710 |
+
|
| 1711 |
+
is_input_ids = len(inputs_tensor.shape) == 2 and inputs_tensor.dtype in [torch.int, torch.long]
|
| 1712 |
+
if (
|
| 1713 |
+
is_input_ids
|
| 1714 |
+
and model_kwargs.get("mm_token_type_ids") is not None
|
| 1715 |
+
and (model_kwargs.get("image_grid_thw") is not None or model_kwargs.get("video_grid_thw") is not None)
|
| 1716 |
+
):
|
| 1717 |
+
model_kwargs = {k: v for k, v in model_kwargs.items() if k != "input_ids"}
|
| 1718 |
+
vision_positions, rope_deltas = self.model.get_rope_index(inputs_tensor, **model_kwargs)
|
| 1719 |
+
self.model.rope_deltas = rope_deltas
|
| 1720 |
+
else:
|
| 1721 |
+
vision_positions = text_positions.unsqueeze(0).expand(3, -1, -1)
|
| 1722 |
+
self.model.rope_deltas = torch.zeros(
|
| 1723 |
+
inputs_tensor.shape[0], 1, dtype=torch.long, device=inputs_tensor.device
|
| 1724 |
+
)
|
| 1725 |
+
|
| 1726 |
+
# Concatenate "text + vision" positions into [4, bs, seq-len]
|
| 1727 |
+
text_positions = text_positions[None, ...]
|
| 1728 |
+
position_ids = torch.cat([text_positions, vision_positions], dim=0)
|
| 1729 |
+
|
| 1730 |
+
return position_ids
|
| 1731 |
+
|
| 1732 |
+
def _get_image_nums_and_video_nums(
|
| 1733 |
+
self,
|
| 1734 |
+
input_ids: torch.LongTensor | None,
|
| 1735 |
+
inputs_embeds: torch.Tensor | None = None,
|
| 1736 |
+
) -> tuple[torch.Tensor, torch.Tensor]:
|
| 1737 |
+
"""
|
| 1738 |
+
Get the number of images and videos for each sample to calculate the separation length of the sample tensor.
|
| 1739 |
+
These parameters are not passed through the processor to avoid unpredictable impacts from interface modifications.
|
| 1740 |
+
|
| 1741 |
+
Args:
|
| 1742 |
+
input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
|
| 1743 |
+
Indices of input sequence tokens in the vocabulary.
|
| 1744 |
+
|
| 1745 |
+
Returns:
|
| 1746 |
+
image_nums (`torch.LongTensor` of shape `(batch_size, num_images_sample)`)
|
| 1747 |
+
video_nums (`torch.LongTensor` of shape `(batch_size, num_videos_sample)`)
|
| 1748 |
+
"""
|
| 1749 |
+
image_token_id = self.config.image_token_id
|
| 1750 |
+
video_token_id = self.config.video_token_id
|
| 1751 |
+
vision_start_token_id = self.config.vision_start_token_id
|
| 1752 |
+
|
| 1753 |
+
if inputs_embeds is not None:
|
| 1754 |
+
vision_start_mask = (
|
| 1755 |
+
inputs_embeds
|
| 1756 |
+
== self.get_input_embeddings()(
|
| 1757 |
+
torch.tensor(vision_start_token_id, dtype=torch.long, device=inputs_embeds.device)
|
| 1758 |
+
)
|
| 1759 |
+
)[..., 0]
|
| 1760 |
+
image_mask = (
|
| 1761 |
+
inputs_embeds
|
| 1762 |
+
== self.get_input_embeddings()(
|
| 1763 |
+
torch.tensor(image_token_id, dtype=torch.long, device=inputs_embeds.device)
|
| 1764 |
+
)
|
| 1765 |
+
)[..., 0]
|
| 1766 |
+
video_mask = (
|
| 1767 |
+
inputs_embeds
|
| 1768 |
+
== self.get_input_embeddings()(
|
| 1769 |
+
torch.tensor(video_token_id, dtype=torch.long, device=inputs_embeds.device)
|
| 1770 |
+
)
|
| 1771 |
+
)[..., 0]
|
| 1772 |
+
else:
|
| 1773 |
+
vision_start_mask = input_ids == vision_start_token_id
|
| 1774 |
+
image_mask = input_ids == image_token_id
|
| 1775 |
+
video_mask = input_ids == video_token_id
|
| 1776 |
+
|
| 1777 |
+
vision_first_mask = torch.roll(vision_start_mask, shifts=1, dims=1)
|
| 1778 |
+
image_nums = torch.sum(vision_first_mask & image_mask, dim=1)
|
| 1779 |
+
video_nums = torch.sum(vision_first_mask & video_mask, dim=1)
|
| 1780 |
+
|
| 1781 |
+
return image_nums, video_nums
|
| 1782 |
+
|
| 1783 |
+
def _expand_inputs_for_generation(
|
| 1784 |
+
self,
|
| 1785 |
+
expand_size: int = 1,
|
| 1786 |
+
is_encoder_decoder: bool = False,
|
| 1787 |
+
input_ids: torch.LongTensor | None = None,
|
| 1788 |
+
**model_kwargs,
|
| 1789 |
+
) -> tuple[torch.LongTensor, dict[str, Any]]:
|
| 1790 |
+
# Overwritten -- Qwen3VLMoe use timestamps and remove second_per_grid_ts
|
| 1791 |
+
# Support for expanding tensors without a batch size dimension
|
| 1792 |
+
# e.g., pixel_values, image_grid_thw, pixel_values_videos, video_grid_thw
|
| 1793 |
+
# pixel_values.shape[0] is sum(seqlen_images for samples)
|
| 1794 |
+
# image_grid_thw.shape[0] is sum(num_images for samples)
|
| 1795 |
+
|
| 1796 |
+
if expand_size == 1:
|
| 1797 |
+
return input_ids, model_kwargs
|
| 1798 |
+
|
| 1799 |
+
visual_keys = ["pixel_values", "image_grid_thw", "pixel_values_videos", "video_grid_thw"]
|
| 1800 |
+
|
| 1801 |
+
def _expand_dict_for_generation_visual(dict_to_expand):
|
| 1802 |
+
image_grid_thw = model_kwargs.get("image_grid_thw", None)
|
| 1803 |
+
video_grid_thw = model_kwargs.get("video_grid_thw", None)
|
| 1804 |
+
image_nums, video_nums = self._get_image_nums_and_video_nums(
|
| 1805 |
+
input_ids, inputs_embeds=model_kwargs.get("inputs_embeds", None)
|
| 1806 |
+
)
|
| 1807 |
+
|
| 1808 |
+
# video_nums: (batch_size,)
|
| 1809 |
+
# since video_nums is the number of videos in the input dependent on the input_ids(vision_start),
|
| 1810 |
+
# but Qwen3VLMoe append vision_start to each frame of each video, so we need to recover the real video_nums according to video_grid_thw
|
| 1811 |
+
if video_grid_thw is not None:
|
| 1812 |
+
cumulative_frame_counts = torch.cumsum(video_grid_thw[:, 0], dim=0)
|
| 1813 |
+
cumulative_token_video_counts = torch.cumsum(video_nums, dim=0)
|
| 1814 |
+
# Find video boundaries in cumulative_frame_counts
|
| 1815 |
+
video_boundary_indices = torch.searchsorted(cumulative_frame_counts, cumulative_token_video_counts)
|
| 1816 |
+
# example: video_boundary_indices = [3, 5] means video_nums = [4, 2]
|
| 1817 |
+
video_nums = torch.diff(torch.cat([-video_boundary_indices.new_ones(1), video_boundary_indices]))
|
| 1818 |
+
|
| 1819 |
+
def _repeat_interleave_samples(x, lengths, repeat_times):
|
| 1820 |
+
samples = torch.split(x, lengths)
|
| 1821 |
+
repeat_args = [repeat_times] + [1] * (x.dim() - 1)
|
| 1822 |
+
result = torch.cat([sample.repeat(*repeat_args) for sample in samples], dim=0)
|
| 1823 |
+
return result
|
| 1824 |
+
|
| 1825 |
+
for key in dict_to_expand:
|
| 1826 |
+
if key == "pixel_values":
|
| 1827 |
+
# split images into samples
|
| 1828 |
+
samples = torch.split(image_grid_thw, list(image_nums))
|
| 1829 |
+
# compute the sequence length of images for each sample
|
| 1830 |
+
lengths = [torch.prod(sample, dim=1).sum() for sample in samples]
|
| 1831 |
+
dict_to_expand[key] = _repeat_interleave_samples(
|
| 1832 |
+
dict_to_expand[key], lengths=lengths, repeat_times=expand_size
|
| 1833 |
+
)
|
| 1834 |
+
elif key == "image_grid_thw":
|
| 1835 |
+
# get the num of images for each sample
|
| 1836 |
+
lengths = list(image_nums)
|
| 1837 |
+
dict_to_expand[key] = _repeat_interleave_samples(
|
| 1838 |
+
dict_to_expand[key], lengths=lengths, repeat_times=expand_size
|
| 1839 |
+
)
|
| 1840 |
+
elif key == "pixel_values_videos":
|
| 1841 |
+
samples = torch.split(video_grid_thw, list(video_nums))
|
| 1842 |
+
lengths = [torch.prod(sample, dim=1).sum() for sample in samples]
|
| 1843 |
+
dict_to_expand[key] = _repeat_interleave_samples(
|
| 1844 |
+
dict_to_expand[key], lengths=lengths, repeat_times=expand_size
|
| 1845 |
+
)
|
| 1846 |
+
elif key == "video_grid_thw":
|
| 1847 |
+
lengths = list(video_nums)
|
| 1848 |
+
dict_to_expand[key] = _repeat_interleave_samples(
|
| 1849 |
+
dict_to_expand[key], lengths=lengths, repeat_times=expand_size
|
| 1850 |
+
)
|
| 1851 |
+
return dict_to_expand
|
| 1852 |
+
|
| 1853 |
+
def _expand_dict_for_generation(dict_to_expand):
|
| 1854 |
+
for key in dict_to_expand:
|
| 1855 |
+
if key == "position_ids" and dict_to_expand[key].ndim == 3:
|
| 1856 |
+
dict_to_expand[key] = dict_to_expand[key].repeat_interleave(expand_size, dim=1)
|
| 1857 |
+
elif (
|
| 1858 |
+
dict_to_expand[key] is not None
|
| 1859 |
+
and isinstance(dict_to_expand[key], torch.Tensor)
|
| 1860 |
+
and key not in visual_keys
|
| 1861 |
+
):
|
| 1862 |
+
dict_to_expand[key] = dict_to_expand[key].repeat_interleave(expand_size, dim=0)
|
| 1863 |
+
return dict_to_expand
|
| 1864 |
+
|
| 1865 |
+
model_kwargs = _expand_dict_for_generation_visual(model_kwargs)
|
| 1866 |
+
|
| 1867 |
+
if input_ids is not None:
|
| 1868 |
+
input_ids = input_ids.repeat_interleave(expand_size, dim=0)
|
| 1869 |
+
|
| 1870 |
+
model_kwargs = _expand_dict_for_generation(model_kwargs)
|
| 1871 |
+
|
| 1872 |
+
if is_encoder_decoder:
|
| 1873 |
+
if model_kwargs.get("encoder_outputs") is None:
|
| 1874 |
+
raise ValueError("If `is_encoder_decoder` is True, make sure that `encoder_outputs` is defined.")
|
| 1875 |
+
model_kwargs["encoder_outputs"] = _expand_dict_for_generation(model_kwargs["encoder_outputs"])
|
| 1876 |
+
|
| 1877 |
+
return input_ids, model_kwargs
|
| 1878 |
+
|
| 1879 |
+
|
| 1880 |
+
__all__ = [
|
| 1881 |
+
"Qwen3VLMoeVisionModel",
|
| 1882 |
+
"Qwen3VLMoeForConditionalGeneration",
|
| 1883 |
+
"Qwen3VLMoeModel",
|
| 1884 |
+
"Qwen3VLMoePreTrainedModel",
|
| 1885 |
+
"Qwen3VLMoeTextModel",
|
| 1886 |
+
]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/transformers/models/qwen3_vl_moe/modular_qwen3_vl_moe.py
ADDED
|
@@ -0,0 +1,467 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Copyright 2025 The Qwen Team and The HuggingFace Inc. team. All rights reserved.
|
| 2 |
+
#
|
| 3 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 4 |
+
# you may not use this file except in compliance with the License.
|
| 5 |
+
# You may obtain a copy of the License at
|
| 6 |
+
#
|
| 7 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 8 |
+
#
|
| 9 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 10 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 11 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 12 |
+
# See the License for the specific language governing permissions and
|
| 13 |
+
# limitations under the License.
|
| 14 |
+
"""PyTorch Qwen3-VL-MOE model."""
|
| 15 |
+
|
| 16 |
+
import torch
|
| 17 |
+
import torch.nn as nn
|
| 18 |
+
import torch.nn.functional as F
|
| 19 |
+
from huggingface_hub.dataclasses import strict
|
| 20 |
+
|
| 21 |
+
from ... import initialization as init
|
| 22 |
+
from ...cache_utils import Cache, DynamicCache
|
| 23 |
+
from ...masking_utils import create_causal_mask
|
| 24 |
+
from ...modeling_flash_attention_utils import FlashAttentionKwargs
|
| 25 |
+
from ...modeling_outputs import MoeModelOutputWithPast
|
| 26 |
+
from ...modeling_utils import PreTrainedModel
|
| 27 |
+
from ...processing_utils import Unpack
|
| 28 |
+
from ...utils import TransformersKwargs, auto_docstring, can_return_tuple, logging
|
| 29 |
+
from ...utils.output_capturing import OutputRecorder
|
| 30 |
+
from ..qwen3_moe.configuration_qwen3_moe import Qwen3MoeConfig
|
| 31 |
+
from ..qwen3_moe.modeling_qwen3_moe import (
|
| 32 |
+
Qwen3MoeDecoderLayer,
|
| 33 |
+
Qwen3MoeExperts,
|
| 34 |
+
Qwen3MoePreTrainedModel,
|
| 35 |
+
Qwen3MoeRMSNorm,
|
| 36 |
+
Qwen3MoeSparseMoeBlock,
|
| 37 |
+
load_balancing_loss_func,
|
| 38 |
+
)
|
| 39 |
+
from ..qwen3_vl.configuration_qwen3_vl import Qwen3VLConfig, Qwen3VLVisionConfig
|
| 40 |
+
from ..qwen3_vl.modeling_qwen3_vl import (
|
| 41 |
+
Qwen3VLCausalLMOutputWithPast,
|
| 42 |
+
Qwen3VLForConditionalGeneration,
|
| 43 |
+
Qwen3VLModelOutputWithPast,
|
| 44 |
+
Qwen3VLTextAttention,
|
| 45 |
+
Qwen3VLTextModel,
|
| 46 |
+
Qwen3VLVisionAttention,
|
| 47 |
+
Qwen3VLVisionBlock,
|
| 48 |
+
Qwen3VLVisionModel,
|
| 49 |
+
Qwen3VLVisionRotaryEmbedding,
|
| 50 |
+
)
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
logger = logging.get_logger(__name__)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
@auto_docstring(checkpoint="Qwen/Qwen3-VL-30B-A3B-Instruct")
|
| 57 |
+
@strict
|
| 58 |
+
class Qwen3VLMoeTextConfig(Qwen3MoeConfig):
|
| 59 |
+
r"""
|
| 60 |
+
decoder_sparse_step (`int`, *optional*, defaults to 1):
|
| 61 |
+
The frequency of the MoE layer.
|
| 62 |
+
mlp_only_layers (`List[int]`, *optional*, defaults to `[]`):
|
| 63 |
+
Indicate which layers use Qwen3VLMoeMLP rather than Qwen3VLMoeSparseMoeBlock
|
| 64 |
+
The list contains layer index, from 0 to num_layers-1 if we have num_layers layers
|
| 65 |
+
If `mlp_only_layers` is empty, `decoder_sparse_step` is used to determine the sparsity.
|
| 66 |
+
|
| 67 |
+
```python
|
| 68 |
+
>>> from transformers import Qwen3VLMoeForConditionalGeneration, Qwen3VLMoeConfig
|
| 69 |
+
|
| 70 |
+
>>> # Initializing a Qwen3VLMoe style configuration
|
| 71 |
+
>>> configuration = Qwen3VLMoeConfig()
|
| 72 |
+
|
| 73 |
+
>>> # Initializing a model from the Qwen3-VL-30B-A3B style configuration
|
| 74 |
+
>>> model = Qwen3VLMoeForConditionalGeneration(configuration)
|
| 75 |
+
|
| 76 |
+
>>> # Accessing the model configuration
|
| 77 |
+
>>> configuration = model.config
|
| 78 |
+
```"""
|
| 79 |
+
|
| 80 |
+
model_type = "qwen3_vl_moe_text"
|
| 81 |
+
base_config_key = "text_config"
|
| 82 |
+
keys_to_ignore_at_inference = ["past_key_values"]
|
| 83 |
+
default_theta = 500000.0
|
| 84 |
+
# Default tensor parallel plan for base model `Qwen3VLMoe`
|
| 85 |
+
base_model_tp_plan = {
|
| 86 |
+
"layers.*.self_attn.q_proj": "colwise",
|
| 87 |
+
"layers.*.self_attn.k_proj": "colwise",
|
| 88 |
+
"layers.*.self_attn.v_proj": "colwise",
|
| 89 |
+
"layers.*.self_attn.o_proj": "rowwise",
|
| 90 |
+
"layers.*.mlp.gate_proj": "colwise",
|
| 91 |
+
"layers.*.mlp.up_proj": "colwise",
|
| 92 |
+
"layers.*.mlp.down_proj": "rowwise",
|
| 93 |
+
}
|
| 94 |
+
base_model_ep_plan = {
|
| 95 |
+
"layers.*.mlp.gate": "ep_router",
|
| 96 |
+
"layers.*.mlp.experts.gate_up_proj": "grouped_gemm",
|
| 97 |
+
"layers.*.mlp.experts.down_proj": "grouped_gemm",
|
| 98 |
+
"layers.*.mlp.experts": "moe_tp_experts",
|
| 99 |
+
}
|
| 100 |
+
base_model_pp_plan = {
|
| 101 |
+
"embed_tokens": (["input_ids"], ["inputs_embeds"]),
|
| 102 |
+
"layers": (["hidden_states", "attention_mask"], ["hidden_states"]),
|
| 103 |
+
"norm": (["hidden_states"], ["hidden_states"]),
|
| 104 |
+
}
|
| 105 |
+
ignore_keys_at_rope_validation = {"mrope_section", "mrope_interleaved"}
|
| 106 |
+
|
| 107 |
+
intermediate_size: int = 5632
|
| 108 |
+
num_hidden_layers: int = 24
|
| 109 |
+
num_attention_heads: int = 16
|
| 110 |
+
num_key_value_heads: int = 16
|
| 111 |
+
max_position_embeddings: int = 128000
|
| 112 |
+
moe_intermediate_size: int = 1408
|
| 113 |
+
num_experts_per_tok: int = 4
|
| 114 |
+
num_experts: int = 60
|
| 115 |
+
head_dim: int | None = None
|
| 116 |
+
tie_word_embeddings: bool = True
|
| 117 |
+
|
| 118 |
+
norm_topk_prob = AttributeError()
|
| 119 |
+
output_router_logits = AttributeError()
|
| 120 |
+
use_sliding_window = AttributeError()
|
| 121 |
+
sliding_window = AttributeError()
|
| 122 |
+
|
| 123 |
+
def __post_init__(self, **kwargs):
|
| 124 |
+
if self.num_key_value_heads is None:
|
| 125 |
+
self.num_key_value_heads = self.num_attention_heads
|
| 126 |
+
|
| 127 |
+
self.head_dim = self.head_dim or self.hidden_size // self.num_attention_heads
|
| 128 |
+
super().__post_init__(**kwargs)
|
| 129 |
+
self.sliding_window = None
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
@auto_docstring(checkpoint="Qwen/Qwen3-VL-30B-A3B-Instruct")
|
| 133 |
+
@strict
|
| 134 |
+
class Qwen3VLMoeVisionConfig(Qwen3VLVisionConfig):
|
| 135 |
+
model_type = "qwen3_vl_moe_vision"
|
| 136 |
+
pass
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
@auto_docstring(checkpoint="Qwen/Qwen3-VL-30B-A3B-Instruct")
|
| 140 |
+
@strict
|
| 141 |
+
class Qwen3VLMoeConfig(Qwen3VLConfig):
|
| 142 |
+
r"""
|
| 143 |
+
Example:
|
| 144 |
+
|
| 145 |
+
```python
|
| 146 |
+
>>> from transformers import Qwen3VLMoeForConditionalGeneration, Qwen3VLMoeConfig
|
| 147 |
+
|
| 148 |
+
>>> # Initializing a Qwen3-VL-MOE style configuration
|
| 149 |
+
>>> configuration = Qwen3VLMoeConfig()
|
| 150 |
+
|
| 151 |
+
>>> # Initializing a model from the Qwen3-VL-30B-A3B style configuration
|
| 152 |
+
>>> model = Qwen3VLMoeForConditionalGeneration(configuration)
|
| 153 |
+
|
| 154 |
+
>>> # Accessing the model configuration
|
| 155 |
+
>>> configuration = model.config
|
| 156 |
+
```"""
|
| 157 |
+
|
| 158 |
+
pass
|
| 159 |
+
|
| 160 |
+
|
| 161 |
+
class Qwen3VLMoeTextRMSNorm(Qwen3MoeRMSNorm):
|
| 162 |
+
pass
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
class Qwen3VLMoeTextExperts(Qwen3MoeExperts):
|
| 166 |
+
pass
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
class Qwen3VLMoeTextTopKRouter(nn.Module):
|
| 170 |
+
def __init__(self, config):
|
| 171 |
+
super().__init__()
|
| 172 |
+
self.top_k = config.num_experts_per_tok
|
| 173 |
+
self.num_experts = config.num_experts
|
| 174 |
+
self.hidden_dim = config.hidden_size
|
| 175 |
+
self.weight = nn.Parameter(torch.zeros(self.num_experts, self.hidden_dim))
|
| 176 |
+
|
| 177 |
+
def forward(self, hidden_states):
|
| 178 |
+
hidden_states = hidden_states.reshape(-1, self.hidden_dim)
|
| 179 |
+
router_logits = F.linear(hidden_states, self.weight) # (seq_len, num_experts)
|
| 180 |
+
router_probs = torch.nn.functional.softmax(router_logits, dtype=torch.float, dim=-1)
|
| 181 |
+
router_top_value, router_indices = torch.topk(router_probs, self.top_k, dim=-1) # (seq_len, top_k)
|
| 182 |
+
router_top_value /= router_top_value.sum(dim=-1, keepdim=True)
|
| 183 |
+
router_top_value = router_top_value.to(router_logits.dtype)
|
| 184 |
+
router_scores = router_top_value
|
| 185 |
+
return router_logits, router_scores, router_indices
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
class Qwen3VLMoeTextSparseMoeBlock(Qwen3MoeSparseMoeBlock):
|
| 189 |
+
pass
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
class Qwen3VLMoeTextAttention(Qwen3VLTextAttention):
|
| 193 |
+
pass
|
| 194 |
+
|
| 195 |
+
|
| 196 |
+
class Qwen3VLMoeTextDecoderLayer(Qwen3MoeDecoderLayer):
|
| 197 |
+
pass
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
class Qwen3VLMoePreTrainedModel(Qwen3MoePreTrainedModel):
|
| 201 |
+
config: Qwen3VLMoeConfig
|
| 202 |
+
input_modalities = ("text", "image", "video")
|
| 203 |
+
_no_split_modules = ["Qwen3VLMoeTextDecoderLayer", "Qwen3VLMoeVisionBlock"]
|
| 204 |
+
|
| 205 |
+
@torch.no_grad()
|
| 206 |
+
def _init_weights(self, module):
|
| 207 |
+
"""Initialize the weights."""
|
| 208 |
+
PreTrainedModel._init_weights(self, module)
|
| 209 |
+
if hasattr(self.config, "initializer_range"):
|
| 210 |
+
std = self.config.initializer_range
|
| 211 |
+
else:
|
| 212 |
+
std = getattr(self.config.get_text_config(), "initializer_range", 0.02)
|
| 213 |
+
if isinstance(module, Qwen3VLMoeTextExperts):
|
| 214 |
+
init.normal_(module.gate_up_proj, mean=0.0, std=std)
|
| 215 |
+
init.normal_(module.down_proj, mean=0.0, std=std)
|
| 216 |
+
elif isinstance(module, Qwen3VLMoeTextTopKRouter):
|
| 217 |
+
init.normal_(module.weight, mean=0.0, std=std)
|
| 218 |
+
elif isinstance(module, Qwen3VLMoeVisionRotaryEmbedding):
|
| 219 |
+
inv_freq = 1.0 / (module.theta ** (torch.arange(0, module.dim, 2, dtype=torch.float) / module.dim))
|
| 220 |
+
init.copy_(module.inv_freq, inv_freq)
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
class Qwen3VLMoeVisionRotaryEmbedding(Qwen3VLVisionRotaryEmbedding):
|
| 224 |
+
pass
|
| 225 |
+
|
| 226 |
+
|
| 227 |
+
class Qwen3VLMoeVisionAttention(Qwen3VLVisionAttention):
|
| 228 |
+
pass
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
class Qwen3VLMoeVisionBlock(Qwen3VLVisionBlock):
|
| 232 |
+
pass
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
class Qwen3VLMoeVisionModel(Qwen3VLVisionModel):
|
| 236 |
+
_can_record_outputs = {
|
| 237 |
+
"router_logits": OutputRecorder(Qwen3VLMoeTextTopKRouter, layer_name="mlp.gate", index=0),
|
| 238 |
+
"hidden_states": Qwen3VLMoeVisionBlock,
|
| 239 |
+
"attentions": Qwen3VLMoeVisionAttention,
|
| 240 |
+
}
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
class Qwen3VLMoeTextModel(Qwen3VLTextModel):
|
| 244 |
+
def forward(
|
| 245 |
+
self,
|
| 246 |
+
input_ids: torch.LongTensor | None = None,
|
| 247 |
+
attention_mask: torch.Tensor | None = None,
|
| 248 |
+
position_ids: torch.LongTensor | None = None,
|
| 249 |
+
past_key_values: Cache | None = None,
|
| 250 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 251 |
+
use_cache: bool | None = None,
|
| 252 |
+
# args for deepstack
|
| 253 |
+
visual_pos_masks: torch.Tensor | None = None,
|
| 254 |
+
deepstack_visual_embeds: list[torch.Tensor] | None = None,
|
| 255 |
+
**kwargs: Unpack[FlashAttentionKwargs],
|
| 256 |
+
) -> tuple | MoeModelOutputWithPast:
|
| 257 |
+
r"""
|
| 258 |
+
visual_pos_masks (`torch.Tensor` of shape `(batch_size, seqlen)`, *optional*):
|
| 259 |
+
The mask of the visual positions.
|
| 260 |
+
deepstack_visual_embeds (`list[torch.Tensor]`, *optional*):
|
| 261 |
+
The deepstack visual embeddings. The shape is (num_layers, visual_seqlen, embed_dim).
|
| 262 |
+
The feature is extracted from the different visual encoder layers, and fed to the decoder
|
| 263 |
+
hidden states. It's from the paper DeepStack(https://arxiv.org/abs/2406.04334).
|
| 264 |
+
"""
|
| 265 |
+
if (input_ids is None) ^ (inputs_embeds is not None):
|
| 266 |
+
raise ValueError("You must specify exactly one of input_ids or inputs_embeds")
|
| 267 |
+
|
| 268 |
+
# torch.jit.trace() doesn't support cache objects in the output
|
| 269 |
+
if use_cache and past_key_values is None and not torch.jit.is_tracing():
|
| 270 |
+
past_key_values = DynamicCache(config=self.config)
|
| 271 |
+
|
| 272 |
+
if inputs_embeds is None:
|
| 273 |
+
inputs_embeds = self.embed_tokens(input_ids)
|
| 274 |
+
|
| 275 |
+
# the hard coded `4` is for text, temporal, height and width.
|
| 276 |
+
if position_ids is None:
|
| 277 |
+
past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
|
| 278 |
+
position_ids = torch.arange(inputs_embeds.shape[1], device=inputs_embeds.device) + past_seen_tokens
|
| 279 |
+
position_ids = position_ids.view(1, 1, -1).expand(4, inputs_embeds.shape[0], -1)
|
| 280 |
+
elif position_ids.ndim == 2:
|
| 281 |
+
position_ids = position_ids[None, ...].expand(4, position_ids.shape[0], -1)
|
| 282 |
+
|
| 283 |
+
if position_ids.ndim == 3 and position_ids.shape[0] == 4:
|
| 284 |
+
text_position_ids = position_ids[0]
|
| 285 |
+
position_ids = position_ids[1:]
|
| 286 |
+
else:
|
| 287 |
+
text_position_ids = None
|
| 288 |
+
|
| 289 |
+
attention_mask = create_causal_mask(
|
| 290 |
+
config=self.config,
|
| 291 |
+
inputs_embeds=inputs_embeds,
|
| 292 |
+
attention_mask=attention_mask,
|
| 293 |
+
past_key_values=past_key_values,
|
| 294 |
+
position_ids=text_position_ids,
|
| 295 |
+
)
|
| 296 |
+
|
| 297 |
+
hidden_states = inputs_embeds
|
| 298 |
+
|
| 299 |
+
# create position embeddings to be shared across the decoder layers
|
| 300 |
+
position_embeddings = self.rotary_emb(hidden_states, position_ids)
|
| 301 |
+
|
| 302 |
+
# decoder layers
|
| 303 |
+
for layer_idx, decoder_layer in enumerate(self.layers):
|
| 304 |
+
layer_outputs = decoder_layer(
|
| 305 |
+
hidden_states,
|
| 306 |
+
attention_mask=attention_mask,
|
| 307 |
+
position_ids=text_position_ids,
|
| 308 |
+
past_key_values=past_key_values,
|
| 309 |
+
position_embeddings=position_embeddings,
|
| 310 |
+
**kwargs,
|
| 311 |
+
)
|
| 312 |
+
hidden_states = layer_outputs
|
| 313 |
+
|
| 314 |
+
# add visual features to the hidden states of first several layers
|
| 315 |
+
if deepstack_visual_embeds is not None and layer_idx in range(len(deepstack_visual_embeds)):
|
| 316 |
+
hidden_states = self._deepstack_process(
|
| 317 |
+
hidden_states,
|
| 318 |
+
visual_pos_masks,
|
| 319 |
+
deepstack_visual_embeds[layer_idx],
|
| 320 |
+
)
|
| 321 |
+
|
| 322 |
+
hidden_states = self.norm(hidden_states)
|
| 323 |
+
|
| 324 |
+
return MoeModelOutputWithPast( # only diff with Qwen3VLTextModel
|
| 325 |
+
last_hidden_state=hidden_states,
|
| 326 |
+
past_key_values=past_key_values,
|
| 327 |
+
)
|
| 328 |
+
|
| 329 |
+
|
| 330 |
+
class Qwen3VLMoeModelOutputWithPast(Qwen3VLModelOutputWithPast):
|
| 331 |
+
router_logits: tuple[torch.FloatTensor] | None = None
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
class Qwen3VLMoeCausalLMOutputWithPast(Qwen3VLCausalLMOutputWithPast):
|
| 335 |
+
router_logits: tuple[torch.FloatTensor] | None = None
|
| 336 |
+
aux_loss: torch.FloatTensor | None = None
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
class Qwen3VLMoeForConditionalGeneration(Qwen3VLForConditionalGeneration):
|
| 340 |
+
@can_return_tuple
|
| 341 |
+
def forward(
|
| 342 |
+
self,
|
| 343 |
+
input_ids: torch.LongTensor = None,
|
| 344 |
+
attention_mask: torch.Tensor | None = None,
|
| 345 |
+
position_ids: torch.LongTensor | None = None,
|
| 346 |
+
past_key_values: Cache | None = None,
|
| 347 |
+
inputs_embeds: torch.FloatTensor | None = None,
|
| 348 |
+
labels: torch.LongTensor | None = None,
|
| 349 |
+
pixel_values: torch.Tensor | None = None,
|
| 350 |
+
pixel_values_videos: torch.FloatTensor | None = None,
|
| 351 |
+
image_grid_thw: torch.LongTensor | None = None,
|
| 352 |
+
video_grid_thw: torch.LongTensor | None = None,
|
| 353 |
+
mm_token_type_ids: torch.IntTensor | None = None,
|
| 354 |
+
logits_to_keep: int | torch.Tensor = 0,
|
| 355 |
+
**kwargs: Unpack[TransformersKwargs],
|
| 356 |
+
) -> tuple | Qwen3VLMoeCausalLMOutputWithPast:
|
| 357 |
+
r"""
|
| 358 |
+
labels (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):
|
| 359 |
+
Labels for computing the masked language modeling loss. Indices should either be in `[0, ...,
|
| 360 |
+
config.vocab_size]` or -100 (see `input_ids` docstring). Tokens with indices set to `-100` are ignored
|
| 361 |
+
(masked), the loss is only computed for the tokens with labels in `[0, ..., config.vocab_size]`.
|
| 362 |
+
image_grid_thw (`torch.LongTensor` of shape `(num_images, 3)`, *optional*):
|
| 363 |
+
The temporal, height and width of feature shape of each image in LLM.
|
| 364 |
+
video_grid_thw (`torch.LongTensor` of shape `(num_videos, 3)`, *optional*):
|
| 365 |
+
The temporal, height and width of feature shape of each video in LLM.
|
| 366 |
+
|
| 367 |
+
Example:
|
| 368 |
+
```python
|
| 369 |
+
>>> from PIL import Image
|
| 370 |
+
>>> import httpx
|
| 371 |
+
>>> from io import BytesIO
|
| 372 |
+
>>> from transformers import AutoProcessor, Qwen3VLMoeForConditionalGeneration
|
| 373 |
+
|
| 374 |
+
>>> model = Qwen3VLMoeForConditionalGeneration.from_pretrained("Qwen/Qwen3-VL-30B-A3B-Instruct", dtype="auto", device_map="auto")
|
| 375 |
+
>>> processor = AutoProcessor.from_pretrained("Qwen/Qwen3-VL-30B-A3B-Instruct")
|
| 376 |
+
|
| 377 |
+
>>> messages = [
|
| 378 |
+
{
|
| 379 |
+
"role": "user",
|
| 380 |
+
"content": [
|
| 381 |
+
{
|
| 382 |
+
"type": "image",
|
| 383 |
+
"image": "https://qianwen-res.oss-cn-beijing.aliyuncs.com/Qwen-VL/assets/demo.jpeg",
|
| 384 |
+
},
|
| 385 |
+
{"type": "text", "text": "Describe this image in short."},
|
| 386 |
+
],
|
| 387 |
+
}
|
| 388 |
+
]
|
| 389 |
+
|
| 390 |
+
>>> # Preparation for inference
|
| 391 |
+
>>> inputs = processor.apply_chat_template(
|
| 392 |
+
messages,
|
| 393 |
+
tokenize=True,
|
| 394 |
+
add_generation_prompt=True,
|
| 395 |
+
return_dict=True,
|
| 396 |
+
return_tensors="pt"
|
| 397 |
+
)
|
| 398 |
+
>>> inputs = inputs.to(model.device)
|
| 399 |
+
|
| 400 |
+
>>> # Generate
|
| 401 |
+
>>> generated_ids = model.generate(**inputs, max_new_tokens=128)
|
| 402 |
+
>>> generated_ids_trimmed = [
|
| 403 |
+
out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
|
| 404 |
+
]
|
| 405 |
+
>>> processor.batch_decode(generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False)[0]
|
| 406 |
+
"A woman in a plaid shirt sits on a sandy beach at sunset, smiling as she gives a high-five to a yellow Labrador Retriever wearing a harness. The ocean waves roll in the background."
|
| 407 |
+
```"""
|
| 408 |
+
|
| 409 |
+
outputs = self.model(
|
| 410 |
+
input_ids=input_ids,
|
| 411 |
+
pixel_values=pixel_values,
|
| 412 |
+
pixel_values_videos=pixel_values_videos,
|
| 413 |
+
image_grid_thw=image_grid_thw,
|
| 414 |
+
video_grid_thw=video_grid_thw,
|
| 415 |
+
mm_token_type_ids=mm_token_type_ids,
|
| 416 |
+
position_ids=position_ids,
|
| 417 |
+
attention_mask=attention_mask,
|
| 418 |
+
past_key_values=past_key_values,
|
| 419 |
+
inputs_embeds=inputs_embeds,
|
| 420 |
+
**kwargs,
|
| 421 |
+
)
|
| 422 |
+
|
| 423 |
+
hidden_states = outputs[0]
|
| 424 |
+
|
| 425 |
+
# Only compute necessary logits, and do not upcast them to float if we are not computing the loss
|
| 426 |
+
slice_indices = slice(-logits_to_keep, None) if isinstance(logits_to_keep, int) else logits_to_keep
|
| 427 |
+
logits = self.lm_head(hidden_states[:, slice_indices, :])
|
| 428 |
+
|
| 429 |
+
loss = None
|
| 430 |
+
if labels is not None:
|
| 431 |
+
loss = self.loss_function(logits=logits, labels=labels, vocab_size=self.config.text_config.vocab_size)
|
| 432 |
+
|
| 433 |
+
aux_loss = None
|
| 434 |
+
if kwargs.get("output_router_logits", False):
|
| 435 |
+
aux_loss = load_balancing_loss_func(
|
| 436 |
+
outputs.router_logits,
|
| 437 |
+
self.config.text_config.num_experts,
|
| 438 |
+
self.config.text_config.num_experts_per_tok,
|
| 439 |
+
attention_mask,
|
| 440 |
+
)
|
| 441 |
+
if labels is not None:
|
| 442 |
+
loss += self.config.text_config.router_aux_loss_coef * aux_loss.to(
|
| 443 |
+
loss.device
|
| 444 |
+
) # make sure to reside in the same device
|
| 445 |
+
|
| 446 |
+
return Qwen3VLMoeCausalLMOutputWithPast(
|
| 447 |
+
loss=loss,
|
| 448 |
+
aux_loss=aux_loss,
|
| 449 |
+
logits=logits,
|
| 450 |
+
past_key_values=outputs.past_key_values,
|
| 451 |
+
hidden_states=outputs.hidden_states,
|
| 452 |
+
attentions=outputs.attentions,
|
| 453 |
+
rope_deltas=outputs.rope_deltas,
|
| 454 |
+
router_logits=outputs.router_logits,
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
__all__ = [
|
| 459 |
+
"Qwen3VLMoeConfig",
|
| 460 |
+
"Qwen3VLMoeTextConfig",
|
| 461 |
+
"Qwen3VLMoeVisionConfig",
|
| 462 |
+
"Qwen3VLMoeVisionModel",
|
| 463 |
+
"Qwen3VLMoeForConditionalGeneration",
|
| 464 |
+
"Qwen3VLMoeModel", # noqa
|
| 465 |
+
"Qwen3VLMoePreTrainedModel",
|
| 466 |
+
"Qwen3VLMoeTextModel",
|
| 467 |
+
]
|
LTA_openwebtext_dualt/mini_owt_logdirichlet/logs/infer_not5_bottleneck128_170k_decode32_ema_20260611/lr4e3.log
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
checkpoint=runs/owt_t5_elftokenized_full_len1024_C1_to_1024_pow1_d768_l12_h12_gbs512_2x8gpu_50ep_lr4e3_ema0p9999_elfopt_not5_bottleneck128_unfixed_norm_stateprobadd_selfcond_ce_fast_20260610_020108/step_170000.pt
|
| 2 |
+
use_ema=1
|
| 3 |
+
step=170000
|
| 4 |
+
decode_steps=32
|
| 5 |
+
n=64 chunk_n=8 gpu=3
|
| 6 |
+
out_base=/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/docs/lta_samples/metrics_20260611
|
| 7 |
+
[2026-06-11T21:37:16+00:00] infer step=170000 decode=32 -> /e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/docs/lta_samples/metrics_20260611/owt_t5_not5_bottleneck128_norm_stateprobadd_selfcond_ce_fast_lr4e3_ema0p9999_step170000_ema_sc1p0_decode32_n64
|
| 8 |
+
[2026-06-11T21:37:16+00:00] run decode=32 chunk=0 n=8 seed=123
|
| 9 |
+
[2026-06-11T21:37:23+00:00] done decode=32 chunk=0
|
| 10 |
+
[2026-06-11T21:37:23+00:00] run decode=32 chunk=1 n=8 seed=124
|
| 11 |
+
[2026-06-11T21:37:29+00:00] done decode=32 chunk=1
|
| 12 |
+
[2026-06-11T21:37:29+00:00] run decode=32 chunk=2 n=8 seed=125
|
| 13 |
+
[2026-06-11T21:37:36+00:00] done decode=32 chunk=2
|
| 14 |
+
[2026-06-11T21:37:36+00:00] run decode=32 chunk=3 n=8 seed=126
|
| 15 |
+
[2026-06-11T21:37:43+00:00] done decode=32 chunk=3
|
| 16 |
+
[2026-06-11T21:37:43+00:00] run decode=32 chunk=4 n=8 seed=127
|
| 17 |
+
[2026-06-11T21:37:50+00:00] done decode=32 chunk=4
|
| 18 |
+
[2026-06-11T21:37:50+00:00] run decode=32 chunk=5 n=8 seed=128
|
| 19 |
+
[2026-06-11T21:37:57+00:00] done decode=32 chunk=5
|
| 20 |
+
[2026-06-11T21:37:57+00:00] run decode=32 chunk=6 n=8 seed=129
|
| 21 |
+
[2026-06-11T21:38:04+00:00] done decode=32 chunk=6
|
| 22 |
+
[2026-06-11T21:38:04+00:00] run decode=32 chunk=7 n=8 seed=130
|
| 23 |
+
[2026-06-11T21:38:11+00:00] done decode=32 chunk=7
|
| 24 |
+
merged 64 samples -> /e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/docs/lta_samples/metrics_20260611/owt_t5_not5_bottleneck128_norm_stateprobadd_selfcond_ce_fast_lr4e3_ema0p9999_step170000_ema_sc1p0_decode32_n64/sc1p0/samples64.txt
|
| 25 |
+
loading scorer /e2e-data/evad-tech-vla/wanghan58/models/flowtext_scorers/gpt2-large-standard dtype=fp32 device=cuda
|
| 26 |
+
run kind ppl mean_entropy distinct_1 distinct_2 top_token_mass eos_rows eos_total ppl_tokens t5_tokens path
|
| 27 |
+
sc1p0 raw_full 34.21054852666053 5.149774446140075 0.08880782318138622 0.522677457427078 0.02952086079519328 63 64 61342 65242 /e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/docs/lta_samples/metrics_20260611/owt_t5_not5_bottleneck128_norm_stateprobadd_selfcond_ce_fast_lr4e3_ema0p9999_step170000_ema_sc1p0_decode32_n64/sc1p0
|
| 28 |
+
sc1p0 pre_eos 41.24451616751232 5.1832901751118445 0.09159038087558696 0.5390526182646092 0.027779095321665163 0 0 57318 63249 /e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/docs/lta_samples/metrics_20260611/owt_t5_not5_bottleneck128_norm_stateprobadd_selfcond_ce_fast_lr4e3_ema0p9999_step170000_ema_sc1p0_decode32_n64/sc1p0
|
| 29 |
+
[2026-06-11T21:38:24+00:00] done
|