JinghuiLuAstronaut commited on
Commit
6174caa
·
verified ·
1 Parent(s): 58e5d81

Add files using upload-large-folder tool

Browse files
Files changed (20) hide show
  1. LTA_openwebtext_dualt/logs/ar_owt_gpt2_len1024_from100k_modelonly_lr1e4_wd0p1_b2p95_cosine_4gpu_smoke.log +79 -0
  2. LTA_openwebtext_dualt/logs/elfaligned_t5record_8gpu/lta_owt_t5record_len1024_elfaligned_dditelf_muon_logitnormal_m1p5_s0p8_gbs512_8gpu_5epoch_20260515_223036.log +642 -0
  3. LTA_openwebtext_dualt/logs/elfaligned_t5record_8gpu/lta_owt_t5record_len1024_elfaligned_dditelf_muon_logitnormal_m1p5_s0p8_none_floor0p0_gbs512_8gpu_5epoch_20260516_000824.log +636 -0
  4. LTA_openwebtext_dualt/logs/elfaligned_t5record_8gpu/lta_owt_t5record_len1024_elfaligned_dditelf_muon_logitnormal_m1p5_s0p8_none_floor0p0_gbs512_8gpu_5epoch_20260516_011453.log +0 -0
  5. LTA_openwebtext_dualt/logs/lta_lm1b_classic_dirichlet_len256_gbs512_4gpu_10k_save1k_20260523.watch.pid +1 -0
  6. LTA_openwebtext_dualt/logs/train_lta_owt_cached_fast10k_4gpu_500step.log +178 -0
  7. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/fsspec/implementations/http.py +902 -0
  8. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/fsspec/implementations/http_sync.py +937 -0
  9. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/fsspec/implementations/memory.py +311 -0
  10. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/fsspec/implementations/zip.py +183 -0
  11. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/_version.py +155 -0
  12. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/histograms.py +1072 -0
  13. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/index_tricks.py +1046 -0
  14. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/mixins.pyi +74 -0
  15. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/polynomial.pyi +303 -0
  16. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/recfunctions.py +1673 -0
  17. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/scimath.py +625 -0
  18. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/shape_base.py +1274 -0
  19. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/stride_tricks.pyi +80 -0
  20. LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/type_check.py +735 -0
LTA_openwebtext_dualt/logs/ar_owt_gpt2_len1024_from100k_modelonly_lr1e4_wd0p1_b2p95_cosine_4gpu_smoke.log ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ resumed_from=runs/ar_owt_gpt2_small_len1024_stream_gbs512_8gpu_1m_nw2/step_0100000.pt start_step=1 model_only=True
6
+ {
7
+ "task": "ar_lm",
8
+ "device": "cuda:0",
9
+ "rank": 0,
10
+ "world_size": 4,
11
+ "samples": "wrapped_stream",
12
+ "vocab_size": 50257,
13
+ "bos_id": 50256,
14
+ "eos_id": 50256,
15
+ "save_dir": "runs/ar_owt_gpt2_len1024_from100k_modelonly_lr1e4_wd0p1_b2p95_cosine_4gpu_smoke",
16
+ "params": 123597312,
17
+ "batch_size": 32,
18
+ "grad_accum": 4,
19
+ "effective_batch_size": 512,
20
+ "global_batch_size": 512,
21
+ "max_len": 1024,
22
+ "wrap": true,
23
+ "wrap_mode": "stream",
24
+ "wrap_record_buffer_size": 200,
25
+ "text_detokenizer": null,
26
+ "openwebtext_split": "train_minus_100k",
27
+ "torch_compile": false
28
+ }
29
+ step=10 micro_steps=40 elapsed=64.8s lr=1.100000e-05 loss=3.0297 ppl=20.7870 acc=0.4218 tokens=32736.0000
30
+ step=20 micro_steps=80 elapsed=40.3s lr=2.100000e-05 loss=3.0076 ppl=20.5603 acc=0.4284 tokens=32736.0000
31
+ step=30 micro_steps=120 elapsed=42.0s lr=3.100000e-05 loss=3.0299 ppl=20.9048 acc=0.4223 tokens=32736.0000
32
+ step=40 micro_steps=160 elapsed=43.8s lr=4.100000e-05 loss=3.0612 ppl=21.4560 acc=0.4161 tokens=32736.0000
33
+ step=50 micro_steps=200 elapsed=39.3s lr=5.100000e-05 loss=3.0069 ppl=20.4106 acc=0.4251 tokens=32736.0000
34
+ step=60 micro_steps=240 elapsed=41.4s lr=6.100000e-05 loss=3.0282 ppl=20.7534 acc=0.4220 tokens=32736.0000
35
+ step=70 micro_steps=280 elapsed=40.5s lr=7.100000e-05 loss=3.0461 ppl=21.1605 acc=0.4203 tokens=32736.0000
36
+ step=80 micro_steps=320 elapsed=39.7s lr=8.100000e-05 loss=3.0507 ppl=21.2206 acc=0.4187 tokens=32736.0000
37
+ step=90 micro_steps=360 elapsed=43.5s lr=9.100000e-05 loss=3.0519 ppl=21.3442 acc=0.4205 tokens=32736.0000
38
+ step=100 micro_steps=400 elapsed=37.2s lr=1.000000e-04 loss=3.0295 ppl=20.8015 acc=0.4238 tokens=32736.0000
39
+ step=110 micro_steps=440 elapsed=54.4s lr=9.996954e-05 loss=3.0593 ppl=21.4342 acc=0.4160 tokens=32736.0000
40
+ step=120 micro_steps=480 elapsed=39.0s lr=9.987820e-05 loss=3.0617 ppl=21.4853 acc=0.4155 tokens=32736.0000
41
+ step=130 micro_steps=520 elapsed=42.9s lr=9.972609e-05 loss=3.0732 ppl=21.7631 acc=0.4173 tokens=32736.0000
42
+ step=140 micro_steps=560 elapsed=39.2s lr=9.951340e-05 loss=3.0504 ppl=21.2292 acc=0.4199 tokens=32736.0000
43
+ step=150 micro_steps=600 elapsed=39.7s lr=9.924039e-05 loss=3.0754 ppl=22.0218 acc=0.4179 tokens=32736.0000
44
+ step=160 micro_steps=640 elapsed=41.2s lr=9.890738e-05 loss=3.0479 ppl=21.2237 acc=0.4195 tokens=32736.0000
45
+ step=170 micro_steps=680 elapsed=38.6s lr=9.851479e-05 loss=3.0272 ppl=20.8744 acc=0.4226 tokens=32736.0000
46
+ W0512 18:20:42.896000 230962 torch/distributed/elastic/agent/server/api.py:719] Received 15 death signal, shutting down workers
47
+ W0512 18:20:42.899000 230962 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 231028 closing signal SIGTERM
48
+ W0512 18:20:42.900000 230962 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 231029 closing signal SIGTERM
49
+ W0512 18:20:42.900000 230962 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 231030 closing signal SIGTERM
50
+ W0512 18:20:42.900000 230962 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 231031 closing signal SIGTERM
51
+ Traceback (most recent call last):
52
+ File "<frozen runpy>", line 198, in _run_module_as_main
53
+ File "<frozen runpy>", line 88, in _run_code
54
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 922, in <module>
55
+ main()
56
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 355, in wrapper
57
+ return f(*args, **kwargs)
58
+ ^^^^^^^^^^^^^^^^^^
59
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 918, in main
60
+ run(args)
61
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 909, in run
62
+ elastic_launch(
63
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/launcher/api.py", line 139, in __call__
64
+ return launch_agent(self._config, self._entrypoint, list(args))
65
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/launcher/api.py", line 261, in launch_agent
67
+ result = agent.run()
68
+ ^^^^^^^^^^^
69
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/elastic/metrics/api.py", line 137, in wrapper
70
+ result = f(*args, **kwargs)
71
+ ^^^^^^^^^^^^^^^^^^
72
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/elastic/agent/server/api.py", line 711, in run
73
+ result = self._invoke_run(role)
74
+ ^^^^^^^^^^^^^^^^^^^^^^
75
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/elastic/agent/server/api.py", line 870, in _invoke_run
76
+ time.sleep(monitor_interval)
77
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/elastic/multiprocessing/api.py", line 84, in _terminate_process_handler
78
+ raise SignalException(f"Process {os.getpid()} got signal: {sigval}", sigval=sigval)
79
+ torch.distributed.elastic.multiprocessing.api.SignalException: Process 230962 got signal: 15
LTA_openwebtext_dualt/logs/elfaligned_t5record_8gpu/lta_owt_t5record_len1024_elfaligned_dditelf_muon_logitnormal_m1p5_s0p8_gbs512_8gpu_5epoch_20260515_223036.log ADDED
@@ -0,0 +1,642 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ t-20260516062948-lst5d-worker-0:10241:10241 [0] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
2
+ t-20260516062948-lst5d-worker-0:10241:10241 [0] NCCL INFO Bootstrap: Using eth1:10.82.80.4<0>
3
+ t-20260516062948-lst5d-worker-0:10241:10241 [0] NCCL INFO cudaDriverVersion 12080
4
+ t-20260516062948-lst5d-worker-0:10241:10241 [0] NCCL INFO NCCL version 2.25.1+cuda12.8
5
+ t-20260516062948-lst5d-worker-0:10241:10241 [0] NCCL INFO Comm config Blocking set to 1
6
+ t-20260516062948-lst5d-worker-0:10247:10247 [6] NCCL INFO cudaDriverVersion 12080
7
+ t-20260516062948-lst5d-worker-0:10247:10247 [6] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
8
+ t-20260516062948-lst5d-worker-0:10247:10247 [6] NCCL INFO Bootstrap: Using eth1:10.82.80.4<0>
9
+ t-20260516062948-lst5d-worker-0:10247:10247 [6] NCCL INFO NCCL version 2.25.1+cuda12.8
10
+ t-20260516062948-lst5d-worker-0:10247:10247 [6] NCCL INFO Comm config Blocking set to 1
11
+ t-20260516062948-lst5d-worker-0:10243:10243 [2] NCCL INFO cudaDriverVersion 12080
12
+ t-20260516062948-lst5d-worker-0:10243:10243 [2] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
13
+ t-20260516062948-lst5d-worker-0:10243:10243 [2] NCCL INFO Bootstrap: Using eth1:10.82.80.4<0>
14
+ t-20260516062948-lst5d-worker-0:10243:10243 [2] NCCL INFO NCCL version 2.25.1+cuda12.8
15
+ t-20260516062948-lst5d-worker-0:10243:10243 [2] NCCL INFO Comm config Blocking set to 1
16
+ t-20260516062948-lst5d-worker-0:10242:10242 [1] NCCL INFO cudaDriverVersion 12080
17
+ t-20260516062948-lst5d-worker-0:10242:10242 [1] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
18
+ t-20260516062948-lst5d-worker-0:10242:10242 [1] NCCL INFO Bootstrap: Using eth1:10.82.80.4<0>
19
+ t-20260516062948-lst5d-worker-0:10242:10242 [1] NCCL INFO NCCL version 2.25.1+cuda12.8
20
+ t-20260516062948-lst5d-worker-0:10242:10242 [1] NCCL INFO Comm config Blocking set to 1
21
+ t-20260516062948-lst5d-worker-0:10248:10248 [7] NCCL INFO cudaDriverVersion 12080
22
+ t-20260516062948-lst5d-worker-0:10248:10248 [7] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
23
+ t-20260516062948-lst5d-worker-0:10248:10248 [7] NCCL INFO Bootstrap: Using eth1:10.82.80.4<0>
24
+ t-20260516062948-lst5d-worker-0:10248:10248 [7] NCCL INFO NCCL version 2.25.1+cuda12.8
25
+ t-20260516062948-lst5d-worker-0:10248:10248 [7] NCCL INFO Comm config Blocking set to 1
26
+ t-20260516062948-lst5d-worker-0:10246:10246 [5] NCCL INFO cudaDriverVersion 12080
27
+ t-20260516062948-lst5d-worker-0:10246:10246 [5] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
28
+ t-20260516062948-lst5d-worker-0:10246:10246 [5] NCCL INFO Bootstrap: Using eth1:10.82.80.4<0>
29
+ t-20260516062948-lst5d-worker-0:10246:10246 [5] NCCL INFO NCCL version 2.25.1+cuda12.8
30
+ t-20260516062948-lst5d-worker-0:10245:10245 [4] NCCL INFO cudaDriverVersion 12080
31
+ t-20260516062948-lst5d-worker-0:10245:10245 [4] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
32
+ t-20260516062948-lst5d-worker-0:10245:10245 [4] NCCL INFO Bootstrap: Using eth1:10.82.80.4<0>
33
+ t-20260516062948-lst5d-worker-0:10245:10245 [4] NCCL INFO NCCL version 2.25.1+cuda12.8
34
+ t-20260516062948-lst5d-worker-0:10244:10244 [3] NCCL INFO cudaDriverVersion 12080
35
+ t-20260516062948-lst5d-worker-0:10244:10244 [3] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
36
+ t-20260516062948-lst5d-worker-0:10244:10244 [3] NCCL INFO Bootstrap: Using eth1:10.82.80.4<0>
37
+ t-20260516062948-lst5d-worker-0:10244:10244 [3] NCCL INFO NCCL version 2.25.1+cuda12.8
38
+ t-20260516062948-lst5d-worker-0:10246:10246 [5] NCCL INFO Comm config Blocking set to 1
39
+ t-20260516062948-lst5d-worker-0:10245:10245 [4] NCCL INFO Comm config Blocking set to 1
40
+ t-20260516062948-lst5d-worker-0:10244:10244 [3] NCCL INFO Comm config Blocking set to 1
41
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
42
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
43
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
44
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO P2P plugin v9 IBext_v9
45
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
46
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
47
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
48
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
49
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO P2P plugin v9 IBext_v9
50
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
51
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
52
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
53
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
54
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO P2P plugin v9 IBext_v9
55
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
56
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
57
+ t-20260516062948-lst5d-worker-0:10241:10321 [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.80.4<0>
58
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
59
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Using network IBext_v9
60
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
61
+ t-20260516062948-lst5d-worker-0:10247:10322 [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.80.4<0>
62
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
63
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO Using network IBext_v9
64
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
65
+ t-20260516062948-lst5d-worker-0:10243:10323 [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.80.4<0>
66
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
67
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO Using network IBext_v9
68
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
69
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
70
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
71
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO P2P plugin v9 IBext_v9
72
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
73
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
74
+ t-20260516062948-lst5d-worker-0:10242:10324 [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.80.4<0>
75
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
76
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO Using network IBext_v9
77
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
78
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
79
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
80
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO P2P plugin v9 IBext_v9
81
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
82
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
83
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
84
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
85
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO P2P plugin v9 IBext_v9
86
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
87
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
88
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
89
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO P2P plugin v9 IBext_v9
90
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
91
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
92
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
93
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
94
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
95
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO P2P plugin v9 IBext_v9
96
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
97
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO ncclCommInitRankConfig comm 0x9929b80 rank 0 nranks 8 cudaDev 0 nvmlDev 0 busId 65040 commId 0x51bb37a311f021b4 - Init START
98
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO ncclCommInitRankConfig comm 0xaa53d10 rank 6 nranks 8 cudaDev 6 nvmlDev 6 busId 73020 commId 0x51bb37a311f021b4 - Init START
99
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
100
+ t-20260516062948-lst5d-worker-0:10248:10325 [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.80.4<0>
101
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
102
+ t-20260516062948-lst5d-worker-0:10245:10327 [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.80.4<0>
103
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
104
+ t-20260516062948-lst5d-worker-0:10246:10326 [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.80.4<0>
105
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
106
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO Using network IBext_v9
107
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
108
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO Using network IBext_v9
109
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
110
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO Using network IBext_v9
111
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
112
+ t-20260516062948-lst5d-worker-0:10244:10328 [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.80.4<0>
113
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
114
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO Using network IBext_v9
115
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO ncclCommInitRankConfig comm 0x9aad980 rank 2 nranks 8 cudaDev 2 nvmlDev 2 busId 69020 commId 0x51bb37a311f021b4 - Init START
116
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO ncclCommInitRankConfig comm 0xaf65240 rank 1 nranks 8 cudaDev 1 nvmlDev 1 busId 67020 commId 0x51bb37a311f021b4 - Init START
117
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO RAS client listening socket at ::1<28028>
118
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO ncclCommInitRankConfig comm 0xb1ff580 rank 5 nranks 8 cudaDev 5 nvmlDev 5 busId 71020 commId 0x51bb37a311f021b4 - Init START
119
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO ncclCommInitRankConfig comm 0x9f87a30 rank 7 nranks 8 cudaDev 7 nvmlDev 7 busId 75020 commId 0x51bb37a311f021b4 - Init START
120
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO RAS client listening socket at ::1<28028>
121
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO RAS client listening socket at ::1<28028>
122
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO RAS client listening socket at ::1<28028>
123
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO ncclCommInitRankConfig comm 0x9a6d0d0 rank 4 nranks 8 cudaDev 4 nvmlDev 4 busId 6f020 commId 0x51bb37a311f021b4 - Init START
124
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO RAS client listening socket at ::1<28028>
125
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO ncclCommInitRankConfig comm 0xb291ad0 rank 3 nranks 8 cudaDev 3 nvmlDev 3 busId 6b020 commId 0x51bb37a311f021b4 - Init START
126
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO RAS client listening socket at ::1<28028>
127
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO RAS client listening socket at ::1<28028>
128
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO RAS client listening socket at ::1<28028>
129
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO Bootstrap timings total 0.013801 (create 0.000021, send 0.000065, recv 0.000101, ring 0.005575, delay 0.000001)
130
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO Bootstrap timings total 0.006025 (create 0.000021, send 0.000065, recv 0.000083, ring 0.002751, delay 0.000001)
131
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO Bootstrap timings total 0.003151 (create 0.000014, send 0.000040, recv 0.000083, ring 0.000131, delay 0.000001)
132
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO Bootstrap timings total 0.498213 (create 0.000021, send 0.000069, recv 0.497686, ring 0.000105, delay 0.000001)
133
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO Bootstrap timings total 0.006545 (create 0.000022, send 0.000066, recv 0.000083, ring 0.006083, delay 0.000000)
134
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO Bootstrap timings total 0.275214 (create 0.000023, send 0.000068, recv 0.000123, ring 0.274695, delay 0.000001)
135
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Bootstrap timings total 0.598817 (create 0.000026, send 0.000074, recv 0.323721, ring 0.005980, delay 0.000001)
136
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO Bootstrap timings total 0.581473 (create 0.000020, send 0.000060, recv 0.575020, ring 0.005994, delay 0.000001)
137
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO MNNVL busId 0x71020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
138
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO MNNVL busId 0x6f020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
139
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO MNNVL busId 0x6b020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
140
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO MNNVL busId 0x75020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
141
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO MNNVL busId 0x67020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
142
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO MNNVL busId 0x65040 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
143
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO MNNVL busId 0x69020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
144
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO MNNVL busId 0x73020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
145
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
146
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
147
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
148
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
149
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
150
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
151
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
152
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
153
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO Setting affinity for GPU 5 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
154
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO NVLS multicast support is available on dev 5
155
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO Setting affinity for GPU 6 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
156
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO Setting affinity for GPU 2 to 03ffffff,ffffffff,ffffffff
157
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO NVLS multicast support is available on dev 2
158
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO Setting affinity for GPU 4 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
159
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO Setting affinity for GPU 1 to 03ffffff,ffffffff,ffffffff
160
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO NVLS multicast support is available on dev 6
161
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO NVLS multicast support is available on dev 1
162
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Setting affinity for GPU 0 to 03ffffff,ffffffff,ffffffff
163
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO NVLS multicast support is available on dev 0
164
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO Setting affinity for GPU 3 to 03ffffff,ffffffff,ffffffff
165
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO NVLS multicast support is available on dev 4
166
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO Setting affinity for GPU 7 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
167
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO NVLS multicast support is available on dev 7
168
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO NVLS multicast support is available on dev 3
169
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO comm 0x9aad980 rank 2 nRanks 8 nNodes 1 localRanks 8 localRank 2 MNNVL 0
170
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO comm 0xaf65240 rank 1 nRanks 8 nNodes 1 localRanks 8 localRank 1 MNNVL 0
171
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO comm 0x9929b80 rank 0 nRanks 8 nNodes 1 localRanks 8 localRank 0 MNNVL 0
172
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO comm 0x9f87a30 rank 7 nRanks 8 nNodes 1 localRanks 8 localRank 7 MNNVL 0
173
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO comm 0xaa53d10 rank 6 nRanks 8 nNodes 1 localRanks 8 localRank 6 MNNVL 0
174
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO comm 0xb1ff580 rank 5 nRanks 8 nNodes 1 localRanks 8 localRank 5 MNNVL 0
175
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO comm 0x9a6d0d0 rank 4 nRanks 8 nNodes 1 localRanks 8 localRank 4 MNNVL 0
176
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO comm 0xb291ad0 rank 3 nRanks 8 nNodes 1 localRanks 8 localRank 3 MNNVL 0
177
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 00/24 : 0 1 2 3 4 5 6 7
178
+ t-20260516062948-lst5d-worker-0:10243:10323 [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
179
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 01/24 : 0 1 2 3 4 5 6 7
180
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO P2P Chunksize set to 524288
181
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 02/24 : 0 1 2 3 4 5 6 7
182
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 03/24 : 0 1 2 3 4 5 6 7
183
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 04/24 : 0 1 2 3 4 5 6 7
184
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 05/24 : 0 1 2 3 4 5 6 7
185
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 06/24 : 0 1 2 3 4 5 6 7
186
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 07/24 : 0 1 2 3 4 5 6 7
187
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 08/24 : 0 1 2 3 4 5 6 7
188
+ t-20260516062948-lst5d-worker-0:10247:10322 [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
189
+ t-20260516062948-lst5d-worker-0:10246:10326 [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
190
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 09/24 : 0 1 2 3 4 5 6 7
191
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO P2P Chunksize set to 524288
192
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 10/24 : 0 1 2 3 4 5 6 7
193
+ t-20260516062948-lst5d-worker-0:10245:10327 [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
194
+ t-20260516062948-lst5d-worker-0:10248:10325 [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
195
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO P2P Chunksize set to 524288
196
+ t-20260516062948-lst5d-worker-0:10242:10324 [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
197
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 11/24 : 0 1 2 3 4 5 6 7
198
+ t-20260516062948-lst5d-worker-0:10244:10328 [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
199
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO P2P Chunksize set to 524288
200
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO P2P Chunksize set to 524288
201
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 12/24 : 0 1 2 3 4 5 6 7
202
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO P2P Chunksize set to 524288
203
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO P2P Chunksize set to 524288
204
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 13/24 : 0 1 2 3 4 5 6 7
205
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 14/24 : 0 1 2 3 4 5 6 7
206
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 15/24 : 0 1 2 3 4 5 6 7
207
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 16/24 : 0 1 2 3 4 5 6 7
208
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 17/24 : 0 1 2 3 4 5 6 7
209
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 18/24 : 0 1 2 3 4 5 6 7
210
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 19/24 : 0 1 2 3 4 5 6 7
211
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 20/24 : 0 1 2 3 4 5 6 7
212
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 21/24 : 0 1 2 3 4 5 6 7
213
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 22/24 : 0 1 2 3 4 5 6 7
214
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Channel 23/24 : 0 1 2 3 4 5 6 7
215
+ t-20260516062948-lst5d-worker-0:10241:10321 [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
216
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO P2P Chunksize set to 524288
217
+ t-20260516062948-lst5d-worker-0:10243:10401 [2] NCCL INFO [Proxy Service] Device 2 CPU core 43
218
+ t-20260516062948-lst5d-worker-0:10246:10402 [5] NCCL INFO [Proxy Service] Device 5 CPU core 100
219
+ t-20260516062948-lst5d-worker-0:10247:10405 [6] NCCL INFO [Proxy Service] Device 6 CPU core 94
220
+ t-20260516062948-lst5d-worker-0:10245:10406 [4] NCCL INFO [Proxy Service] Device 4 CPU core 104
221
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Check P2P Type intraNodeP2pSupport 1 directMode 0
222
+ t-20260516062948-lst5d-worker-0:10248:10409 [7] NCCL INFO [Proxy Service] Device 7 CPU core 128
223
+ t-20260516062948-lst5d-worker-0:10241:10410 [0] NCCL INFO [Proxy Service] Device 0 CPU core 74
224
+ t-20260516062948-lst5d-worker-0:10245:10408 [4] NCCL INFO [Proxy Service UDS] Device 4 CPU core 106
225
+ t-20260516062948-lst5d-worker-0:10247:10407 [6] NCCL INFO [Proxy Service UDS] Device 6 CPU core 96
226
+ t-20260516062948-lst5d-worker-0:10242:10412 [1] NCCL INFO [Proxy Service] Device 1 CPU core 2
227
+ t-20260516062948-lst5d-worker-0:10243:10403 [2] NCCL INFO [Proxy Service UDS] Device 2 CPU core 46
228
+ t-20260516062948-lst5d-worker-0:10246:10404 [5] NCCL INFO [Proxy Service UDS] Device 5 CPU core 104
229
+ t-20260516062948-lst5d-worker-0:10248:10411 [7] NCCL INFO [Proxy Service UDS] Device 7 CPU core 130
230
+ t-20260516062948-lst5d-worker-0:10241:10414 [0] NCCL INFO [Proxy Service UDS] Device 0 CPU core 76
231
+ t-20260516062948-lst5d-worker-0:10242:10413 [1] NCCL INFO [Proxy Service UDS] Device 1 CPU core 5
232
+ t-20260516062948-lst5d-worker-0:10244:10415 [3] NCCL INFO [Proxy Service] Device 3 CPU core 2
233
+ t-20260516062948-lst5d-worker-0:10244:10416 [3] NCCL INFO [Proxy Service UDS] Device 3 CPU core 5
234
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
235
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
236
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
237
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
238
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
239
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
240
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
241
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
242
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO CC Off, workFifoBytes 1048576
243
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
244
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
245
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
246
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
247
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
248
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
249
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
250
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
251
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
252
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
253
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
254
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
255
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
256
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
257
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
258
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
259
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
260
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
261
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
262
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
263
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
264
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
265
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
266
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO ncclCommInitRankConfig comm 0x9aad980 rank 2 nranks 8 cudaDev 2 nvmlDev 2 busId 69020 commId 0x51bb37a311f021b4 - Init COMPLETE
267
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO ncclCommInitRankConfig comm 0x9f87a30 rank 7 nranks 8 cudaDev 7 nvmlDev 7 busId 75020 commId 0x51bb37a311f021b4 - Init COMPLETE
268
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
269
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO ncclCommInitRankConfig comm 0xb291ad0 rank 3 nranks 8 cudaDev 3 nvmlDev 3 busId 6b020 commId 0x51bb37a311f021b4 - Init COMPLETE
270
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
271
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
272
+ t-20260516062948-lst5d-worker-0:10243:10323 [2] NCCL INFO Init timings - ncclCommInitRankConfig: rank 2 nranks 8 total 2.15 (kernels 0.19, alloc 0.53, bootstrap 0.50, allgathers 0.01, topo 0.53, graphs 0.01, connections 0.36, rest 0.02)
273
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO ncclCommInitRankConfig comm 0xb1ff580 rank 5 nranks 8 cudaDev 5 nvmlDev 5 busId 71020 commId 0x51bb37a311f021b4 - Init COMPLETE
274
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO ncclCommInitRankConfig comm 0xaa53d10 rank 6 nranks 8 cudaDev 6 nvmlDev 6 busId 73020 commId 0x51bb37a311f021b4 - Init COMPLETE
275
+ t-20260516062948-lst5d-worker-0:10248:10325 [7] NCCL INFO Init timings - ncclCommInitRankConfig: rank 7 nranks 8 total 2.06 (kernels 0.50, alloc 0.62, bootstrap 0.01, allgathers 0.00, topo 0.53, graphs 0.01, connections 0.36, rest 0.02)
276
+ t-20260516062948-lst5d-worker-0:10244:10328 [3] NCCL INFO Init timings - ncclCommInitRankConfig: rank 3 nranks 8 total 2.04 (kernels 0.49, alloc 0.61, bootstrap 0.00, allgathers 0.00, topo 0.53, graphs 0.01, connections 0.34, rest 0.04)
277
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO ncclCommInitRankConfig comm 0xaf65240 rank 1 nranks 8 cudaDev 1 nvmlDev 1 busId 67020 commId 0x51bb37a311f021b4 - Init COMPLETE
278
+ t-20260516062948-lst5d-worker-0:10246:10326 [5] NCCL INFO Init timings - ncclCommInitRankConfig: rank 5 nranks 8 total 2.04 (kernels 0.48, alloc 0.61, bootstrap 0.01, allgathers 0.01, topo 0.53, graphs 0.01, connections 0.36, rest 0.02)
279
+ t-20260516062948-lst5d-worker-0:10247:10322 [6] NCCL INFO Init timings - ncclCommInitRankConfig: rank 6 nranks 8 total 2.21 (kernels 0.20, alloc 0.50, bootstrap 0.58, allgathers 0.01, topo 0.53, graphs 0.01, connections 0.36, rest 0.03)
280
+ t-20260516062948-lst5d-worker-0:10242:10324 [1] NCCL INFO Init timings - ncclCommInitRankConfig: rank 1 nranks 8 total 2.11 (kernels 0.30, alloc 0.61, bootstrap 0.28, allgathers 0.01, topo 0.53, graphs 0.01, connections 0.36, rest 0.02)
281
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
282
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
283
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
284
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
285
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
286
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
287
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO ncclCommInitRankConfig comm 0x9a6d0d0 rank 4 nranks 8 cudaDev 4 nvmlDev 4 busId 6f020 commId 0x51bb37a311f021b4 - Init COMPLETE
288
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO ncclCommInitRankConfig comm 0x9929b80 rank 0 nranks 8 cudaDev 0 nvmlDev 0 busId 65040 commId 0x51bb37a311f021b4 - Init COMPLETE
289
+ t-20260516062948-lst5d-worker-0:10245:10327 [4] NCCL INFO Init timings - ncclCommInitRankConfig: rank 4 nranks 8 total 2.04 (kernels 0.48, alloc 0.62, bootstrap 0.01, allgathers 0.01, topo 0.53, graphs 0.01, connections 0.36, rest 0.03)
290
+ t-20260516062948-lst5d-worker-0:10241:10321 [0] NCCL INFO Init timings - ncclCommInitRankConfig: rank 0 nranks 8 total 2.21 (kernels 0.20, alloc 0.48, bootstrap 0.60, allgathers 0.01, topo 0.53, graphs 0.01, connections 0.36, rest 0.03)
291
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 00/0 : 6[6] -> 7[7] via P2P/CUMEM
292
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 00/0 : 0[0] -> 1[1] via P2P/CUMEM
293
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 00/0 : 1[1] -> 2[2] via P2P/CUMEM
294
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 01/0 : 6[6] -> 7[7] via P2P/CUMEM
295
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 01/0 : 0[0] -> 1[1] via P2P/CUMEM
296
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 01/0 : 1[1] -> 2[2] via P2P/CUMEM
297
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 02/0 : 6[6] -> 7[7] via P2P/CUMEM
298
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 02/0 : 0[0] -> 1[1] via P2P/CUMEM
299
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 02/0 : 1[1] -> 2[2] via P2P/CUMEM
300
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 03/0 : 6[6] -> 7[7] via P2P/CUMEM
301
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 03/0 : 0[0] -> 1[1] via P2P/CUMEM
302
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 03/0 : 1[1] -> 2[2] via P2P/CUMEM
303
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 04/0 : 6[6] -> 7[7] via P2P/CUMEM
304
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 04/0 : 0[0] -> 1[1] via P2P/CUMEM
305
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 04/0 : 1[1] -> 2[2] via P2P/CUMEM
306
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 05/0 : 6[6] -> 7[7] via P2P/CUMEM
307
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 05/0 : 0[0] -> 1[1] via P2P/CUMEM
308
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 05/0 : 1[1] -> 2[2] via P2P/CUMEM
309
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 06/0 : 6[6] -> 7[7] via P2P/CUMEM
310
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 00/0 : 4[4] -> 5[5] via P2P/CUMEM
311
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 06/0 : 0[0] -> 1[1] via P2P/CUMEM
312
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 06/0 : 1[1] -> 2[2] via P2P/CUMEM
313
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 07/0 : 6[6] -> 7[7] via P2P/CUMEM
314
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 01/0 : 4[4] -> 5[5] via P2P/CUMEM
315
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 07/0 : 0[0] -> 1[1] via P2P/CUMEM
316
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 00/0 : 3[3] -> 4[4] via P2P/CUMEM
317
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 07/0 : 1[1] -> 2[2] via P2P/CUMEM
318
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 08/0 : 6[6] -> 7[7] via P2P/CUMEM
319
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 02/0 : 4[4] -> 5[5] via P2P/CUMEM
320
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 08/0 : 0[0] -> 1[1] via P2P/CUMEM
321
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 01/0 : 3[3] -> 4[4] via P2P/CUMEM
322
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 08/0 : 1[1] -> 2[2] via P2P/CUMEM
323
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 00/0 : 2[2] -> 3[3] via P2P/CUMEM
324
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 09/0 : 6[6] -> 7[7] via P2P/CUMEM
325
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 02/0 : 3[3] -> 4[4] via P2P/CUMEM
326
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 10/0 : 6[6] -> 7[7] via P2P/CUMEM
327
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 00/0 : 5[5] -> 6[6] via P2P/CUMEM
328
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 00/0 : 7[7] -> 0[0] via P2P/CUMEM
329
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 03/0 : 4[4] -> 5[5] via P2P/CUMEM
330
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 09/0 : 1[1] -> 2[2] via P2P/CUMEM
331
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 11/0 : 6[6] -> 7[7] via P2P/CUMEM
332
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 01/0 : 5[5] -> 6[6] via P2P/CUMEM
333
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 01/0 : 7[7] -> 0[0] via P2P/CUMEM
334
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 04/0 : 4[4] -> 5[5] via P2P/CUMEM
335
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 10/0 : 1[1] -> 2[2] via P2P/CUMEM
336
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 12/0 : 6[6] -> 7[7] via P2P/CUMEM
337
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 02/0 : 5[5] -> 6[6] via P2P/CUMEM
338
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 02/0 : 7[7] -> 0[0] via P2P/CUMEM
339
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 05/0 : 4[4] -> 5[5] via P2P/CUMEM
340
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 11/0 : 1[1] -> 2[2] via P2P/CUMEM
341
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 13/0 : 6[6] -> 7[7] via P2P/CUMEM
342
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 03/0 : 5[5] -> 6[6] via P2P/CUMEM
343
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 03/0 : 7[7] -> 0[0] via P2P/CUMEM
344
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 06/0 : 4[4] -> 5[5] via P2P/CUMEM
345
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 12/0 : 1[1] -> 2[2] via P2P/CUMEM
346
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 14/0 : 6[6] -> 7[7] via P2P/CUMEM
347
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 04/0 : 5[5] -> 6[6] via P2P/CUMEM
348
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 04/0 : 7[7] -> 0[0] via P2P/CUMEM
349
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 07/0 : 4[4] -> 5[5] via P2P/CUMEM
350
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 13/0 : 1[1] -> 2[2] via P2P/CUMEM
351
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 15/0 : 6[6] -> 7[7] via P2P/CUMEM
352
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 05/0 : 5[5] -> 6[6] via P2P/CUMEM
353
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 09/0 : 0[0] -> 1[1] via P2P/CUMEM
354
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 05/0 : 7[7] -> 0[0] via P2P/CUMEM
355
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 08/0 : 4[4] -> 5[5] via P2P/CUMEM
356
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 14/0 : 1[1] -> 2[2] via P2P/CUMEM
357
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 16/0 : 6[6] -> 7[7] via P2P/CUMEM
358
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 06/0 : 5[5] -> 6[6] via P2P/CUMEM
359
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 10/0 : 0[0] -> 1[1] via P2P/CUMEM
360
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 06/0 : 7[7] -> 0[0] via P2P/CUMEM
361
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 01/0 : 2[2] -> 3[3] via P2P/CUMEM
362
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 09/0 : 4[4] -> 5[5] via P2P/CUMEM
363
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 15/0 : 1[1] -> 2[2] via P2P/CUMEM
364
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 17/0 : 6[6] -> 7[7] via P2P/CUMEM
365
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 07/0 : 5[5] -> 6[6] via P2P/CUMEM
366
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 03/0 : 3[3] -> 4[4] via P2P/CUMEM
367
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 11/0 : 0[0] -> 1[1] via P2P/CUMEM
368
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 08/0 : 5[5] -> 6[6] via P2P/CUMEM
369
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 04/0 : 3[3] -> 4[4] via P2P/CUMEM
370
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 12/0 : 0[0] -> 1[1] via P2P/CUMEM
371
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 09/0 : 5[5] -> 6[6] via P2P/CUMEM
372
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 05/0 : 3[3] -> 4[4] via P2P/CUMEM
373
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 13/0 : 0[0] -> 1[1] via P2P/CUMEM
374
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 10/0 : 5[5] -> 6[6] via P2P/CUMEM
375
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 06/0 : 3[3] -> 4[4] via P2P/CUMEM
376
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 14/0 : 0[0] -> 1[1] via P2P/CUMEM
377
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 11/0 : 5[5] -> 6[6] via P2P/CUMEM
378
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 07/0 : 3[3] -> 4[4] via P2P/CUMEM
379
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 15/0 : 0[0] -> 1[1] via P2P/CUMEM
380
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 12/0 : 5[5] -> 6[6] via P2P/CUMEM
381
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 08/0 : 3[3] -> 4[4] via P2P/CUMEM
382
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 16/0 : 0[0] -> 1[1] via P2P/CUMEM
383
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 13/0 : 5[5] -> 6[6] via P2P/CUMEM
384
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 09/0 : 3[3] -> 4[4] via P2P/CUMEM
385
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 07/0 : 7[7] -> 0[0] via P2P/CUMEM
386
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 02/0 : 2[2] -> 3[3] via P2P/CUMEM
387
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 17/0 : 0[0] -> 1[1] via P2P/CUMEM
388
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 10/0 : 4[4] -> 5[5] via P2P/CUMEM
389
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 16/0 : 1[1] -> 2[2] via P2P/CUMEM
390
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 14/0 : 5[5] -> 6[6] via P2P/CUMEM
391
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 10/0 : 3[3] -> 4[4] via P2P/CUMEM
392
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 08/0 : 7[7] -> 0[0] via P2P/CUMEM
393
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 03/0 : 2[2] -> 3[3] via P2P/CUMEM
394
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 18/0 : 0[0] -> 1[1] via P2P/CUMEM
395
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 11/0 : 4[4] -> 5[5] via P2P/CUMEM
396
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 17/0 : 1[1] -> 2[2] via P2P/CUMEM
397
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 18/0 : 6[6] -> 7[7] via P2P/CUMEM
398
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 15/0 : 5[5] -> 6[6] via P2P/CUMEM
399
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 11/0 : 3[3] -> 4[4] via P2P/CUMEM
400
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 09/0 : 7[7] -> 0[0] via P2P/CUMEM
401
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 04/0 : 2[2] -> 3[3] via P2P/CUMEM
402
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 19/0 : 0[0] -> 1[1] via P2P/CUMEM
403
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 12/0 : 4[4] -> 5[5] via P2P/CUMEM
404
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 18/0 : 1[1] -> 2[2] via P2P/CUMEM
405
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 19/0 : 6[6] -> 7[7] via P2P/CUMEM
406
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 16/0 : 5[5] -> 6[6] via P2P/CUMEM
407
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 12/0 : 3[3] -> 4[4] via P2P/CUMEM
408
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 10/0 : 7[7] -> 0[0] via P2P/CUMEM
409
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 05/0 : 2[2] -> 3[3] via P2P/CUMEM
410
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 20/0 : 0[0] -> 1[1] via P2P/CUMEM
411
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 13/0 : 4[4] -> 5[5] via P2P/CUMEM
412
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 19/0 : 1[1] -> 2[2] via P2P/CUMEM
413
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 20/0 : 6[6] -> 7[7] via P2P/CUMEM
414
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 17/0 : 5[5] -> 6[6] via P2P/CUMEM
415
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 13/0 : 3[3] -> 4[4] via P2P/CUMEM
416
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 11/0 : 7[7] -> 0[0] via P2P/CUMEM
417
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 06/0 : 2[2] -> 3[3] via P2P/CUMEM
418
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 21/0 : 0[0] -> 1[1] via P2P/CUMEM
419
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 14/0 : 4[4] -> 5[5] via P2P/CUMEM
420
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 20/0 : 1[1] -> 2[2] via P2P/CUMEM
421
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 21/0 : 6[6] -> 7[7] via P2P/CUMEM
422
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 18/0 : 5[5] -> 6[6] via P2P/CUMEM
423
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 14/0 : 3[3] -> 4[4] via P2P/CUMEM
424
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 12/0 : 7[7] -> 0[0] via P2P/CUMEM
425
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 07/0 : 2[2] -> 3[3] via P2P/CUMEM
426
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 22/0 : 0[0] -> 1[1] via P2P/CUMEM
427
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 15/0 : 4[4] -> 5[5] via P2P/CUMEM
428
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 21/0 : 1[1] -> 2[2] via P2P/CUMEM
429
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 22/0 : 6[6] -> 7[7] via P2P/CUMEM
430
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 19/0 : 5[5] -> 6[6] via P2P/CUMEM
431
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 15/0 : 3[3] -> 4[4] via P2P/CUMEM
432
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 13/0 : 7[7] -> 0[0] via P2P/CUMEM
433
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 08/0 : 2[2] -> 3[3] via P2P/CUMEM
434
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Channel 23/0 : 0[0] -> 1[1] via P2P/CUMEM
435
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 16/0 : 4[4] -> 5[5] via P2P/CUMEM
436
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 22/0 : 1[1] -> 2[2] via P2P/CUMEM
437
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Channel 23/0 : 6[6] -> 7[7] via P2P/CUMEM
438
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 20/0 : 5[5] -> 6[6] via P2P/CUMEM
439
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 16/0 : 3[3] -> 4[4] via P2P/CUMEM
440
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 14/0 : 7[7] -> 0[0] via P2P/CUMEM
441
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 09/0 : 2[2] -> 3[3] via P2P/CUMEM
442
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 17/0 : 4[4] -> 5[5] via P2P/CUMEM
443
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Channel 23/0 : 1[1] -> 2[2] via P2P/CUMEM
444
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 21/0 : 5[5] -> 6[6] via P2P/CUMEM
445
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 17/0 : 3[3] -> 4[4] via P2P/CUMEM
446
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 15/0 : 7[7] -> 0[0] via P2P/CUMEM
447
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 10/0 : 2[2] -> 3[3] via P2P/CUMEM
448
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 18/0 : 4[4] -> 5[5] via P2P/CUMEM
449
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 22/0 : 5[5] -> 6[6] via P2P/CUMEM
450
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 18/0 : 3[3] -> 4[4] via P2P/CUMEM
451
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 16/0 : 7[7] -> 0[0] via P2P/CUMEM
452
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 11/0 : 2[2] -> 3[3] via P2P/CUMEM
453
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 19/0 : 4[4] -> 5[5] via P2P/CUMEM
454
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Channel 23/0 : 5[5] -> 6[6] via P2P/CUMEM
455
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 19/0 : 3[3] -> 4[4] via P2P/CUMEM
456
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 17/0 : 7[7] -> 0[0] via P2P/CUMEM
457
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 12/0 : 2[2] -> 3[3] via P2P/CUMEM
458
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 20/0 : 4[4] -> 5[5] via P2P/CUMEM
459
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 20/0 : 3[3] -> 4[4] via P2P/CUMEM
460
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 18/0 : 7[7] -> 0[0] via P2P/CUMEM
461
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 13/0 : 2[2] -> 3[3] via P2P/CUMEM
462
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 21/0 : 4[4] -> 5[5] via P2P/CUMEM
463
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 21/0 : 3[3] -> 4[4] via P2P/CUMEM
464
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 19/0 : 7[7] -> 0[0] via P2P/CUMEM
465
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 14/0 : 2[2] -> 3[3] via P2P/CUMEM
466
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 22/0 : 4[4] -> 5[5] via P2P/CUMEM
467
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 22/0 : 3[3] -> 4[4] via P2P/CUMEM
468
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 20/0 : 7[7] -> 0[0] via P2P/CUMEM
469
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 15/0 : 2[2] -> 3[3] via P2P/CUMEM
470
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Channel 23/0 : 4[4] -> 5[5] via P2P/CUMEM
471
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Channel 23/0 : 3[3] -> 4[4] via P2P/CUMEM
472
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 21/0 : 7[7] -> 0[0] via P2P/CUMEM
473
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 16/0 : 2[2] -> 3[3] via P2P/CUMEM
474
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 22/0 : 7[7] -> 0[0] via P2P/CUMEM
475
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 17/0 : 2[2] -> 3[3] via P2P/CUMEM
476
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 18/0 : 2[2] -> 3[3] via P2P/CUMEM
477
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Channel 23/0 : 7[7] -> 0[0] via P2P/CUMEM
478
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 19/0 : 2[2] -> 3[3] via P2P/CUMEM
479
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 20/0 : 2[2] -> 3[3] via P2P/CUMEM
480
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 21/0 : 2[2] -> 3[3] via P2P/CUMEM
481
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 22/0 : 2[2] -> 3[3] via P2P/CUMEM
482
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Channel 23/0 : 2[2] -> 3[3] via P2P/CUMEM
483
+ t-20260516062948-lst5d-worker-0:10247:10417 [6] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
484
+ t-20260516062948-lst5d-worker-0:10243:10422 [2] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
485
+ t-20260516062948-lst5d-worker-0:10242:10419 [1] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
486
+ t-20260516062948-lst5d-worker-0:10246:10424 [5] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
487
+ t-20260516062948-lst5d-worker-0:10244:10420 [3] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
488
+ t-20260516062948-lst5d-worker-0:10248:10423 [7] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
489
+ t-20260516062948-lst5d-worker-0:10241:10418 [0] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
490
+ t-20260516062948-lst5d-worker-0:10245:10421 [4] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
491
+ {
492
+ "device": "cuda:0",
493
+ "rank": 0,
494
+ "world_size": 8,
495
+ "samples": "record_pad_truncate:pad=0:add_eos=0:add_special=1:shuffle_buffer=10000",
496
+ "vocab_size": 32100,
497
+ "tokenizer_vocab_size": 32100,
498
+ "save_dir": "runs/lta_owt_t5record_len1024_elfaligned_dditelf_muon_logitnormal_m1p5_s0p8_gbs512_8gpu_5epoch_20260515_223036",
499
+ "batch_size": 32,
500
+ "grad_accum": 2,
501
+ "effective_batch_size": 512,
502
+ "global_batch_size": 512,
503
+ "lr_schedule": "constant_warmup",
504
+ "optimizer": "muon",
505
+ "epochs": 5.0,
506
+ "steps_per_epoch": 15457,
507
+ "total_steps": 77285,
508
+ "warmup_steps": 7729,
509
+ "warmup_epochs": 0.5,
510
+ "min_lr": 0.0,
511
+ "weight_decay": 0.0,
512
+ "output_weight_decay": -1.0,
513
+ "adamw_param_groups": "nanogpt",
514
+ "adam_beta1": 0.9,
515
+ "adam_beta2": 0.999,
516
+ "adam_eps": 1e-08,
517
+ "muon_impl": "optax",
518
+ "muon_momentum": 0.95,
519
+ "muon_ns_steps": 5,
520
+ "muon_update_scale": 1.0,
521
+ "muon_nesterov": true,
522
+ "muon_width_scale": true,
523
+ "muon_effective_nesterov": true,
524
+ "muon_effective_width_scale": true,
525
+ "muon_effective_weight_decay": 0.0,
526
+ "muon_adam_fallback_nesterov": true,
527
+ "muon_adam_fallback_weight_decay": 0.0,
528
+ "ema_decay": 0.9999,
529
+ "ema_start_step": 0,
530
+ "model_type": "ddit_elf",
531
+ "elf_num_time_tokens": 4,
532
+ "elf_num_model_mode_tokens": 0,
533
+ "qk_norm": true,
534
+ "output_bias": false,
535
+ "norm_type": "rmsnorm",
536
+ "t_sampling_mode": "logit_normal",
537
+ "t_sampling_power": 1.0,
538
+ "t_sampling_eps": 0.0001,
539
+ "t_sampling_logit_mean": -1.5,
540
+ "t_sampling_logit_std": 0.8,
541
+ "dual_t": true,
542
+ "corrupt_t_mode": "same",
543
+ "corrupt_min_t": 0.0,
544
+ "corrupt_max_t": 1.0,
545
+ "prefix_block_prob": 0.0,
546
+ "prefix_block_len": 128,
547
+ "mask_ratio_floor_schedule": "none",
548
+ "dirichlet_endpoint_mode": "categorical_dual_t",
549
+ "dirichlet_semantic_t_mode": "same",
550
+ "dirichlet_semantic_t_value": 0.0,
551
+ "dirichlet_semantic_t_curve": "linear",
552
+ "dirichlet_semantic_t_power": 1.0,
553
+ "endpoint_sequence_random_prob_alpha": 0.0,
554
+ "categorical_wrong_from_full_vocab": true,
555
+ "categorical_wrong_from_batch_valid_tokens": false,
556
+ "categorical_wrong_basin_token_ids": "",
557
+ "categorical_wrong_basin_prob": 0.0,
558
+ "categorical_wrong_unigram_prob": 0.0,
559
+ "categorical_wrong_uniform_prob": 0.0,
560
+ "categorical_wrong_corpus_unigram_path": "",
561
+ "categorical_wrong_corpus_unigram_alpha": 1.0,
562
+ "categorical_wrong_basin_shared_prob": 0.0,
563
+ "categorical_wrong_unigram_shared_prob": 0.0,
564
+ "mask_mixture_original_prob": 0.0,
565
+ "mask_mixture_lowk_prob": 0.0,
566
+ "mask_mixture_lowcorrupt_prob": 0.0,
567
+ "mask_mixture_block_prob": 0.0,
568
+ "mask_mixture_all_prob": 0.0,
569
+ "mask_mixture_lowk_clean_tokens": "1,2,4,8,16,32,64",
570
+ "mask_mixture_lowcorrupt_tokens": "1,2,4,8,16,32,64",
571
+ "mask_mixture_block_tokens": "64,128",
572
+ "simplex_bridge_sampler": "dirichlet",
573
+ "logistic_normal_sigma_min": 0.18,
574
+ "logistic_normal_sigma_max": 2.2,
575
+ "logistic_normal_tau_min": 0.65,
576
+ "logistic_normal_tau_max": 1.15,
577
+ "torch_compile": false,
578
+ "compile_mode": "max-autotune",
579
+ "state_format": "prob",
580
+ "target_loss": "hard_ce",
581
+ "meanflow_weight": 0.0,
582
+ "rollout_train_prob": 0.0,
583
+ "rollout_train_steps": 1,
584
+ "rollout_train_infer_steps": 64,
585
+ "rollout_train_temp": 1.45,
586
+ "rollout_train_max_gamma": 1.0,
587
+ "rollout_train_corrupt_only": true,
588
+ "rollout_train_samplewise": false,
589
+ "rollout_train_compute_always": false,
590
+ "bridge_noise_init": "logistic_normal",
591
+ "noise_sigma": -1.0,
592
+ "allow_tf32": true,
593
+ "activation_checkpointing": true,
594
+ "activation_checkpoint_interval": 1,
595
+ "activation_checkpoint_scope": "mlp",
596
+ "ddp_static_graph": false,
597
+ "ddp_gradient_as_bucket_view": true,
598
+ "blocking_data_transfer": false,
599
+ "dataloader_prefetch_factor": 4,
600
+ "full_train_stats": false,
601
+ "record_pad_truncate": true,
602
+ "record_add_eos": false,
603
+ "record_add_special_tokens": true,
604
+ "record_pad_token": "pad",
605
+ "record_shuffle_buffer": 10000,
606
+ "wrap": false,
607
+ "wrap_mode": "stream",
608
+ "wrap_record_buffer_size": 200,
609
+ "owt_cached_chunks": false,
610
+ "owt_chunk_cache_dir": "",
611
+ "owt_chunk_cache_rebuild": false,
612
+ "owt_chunk_cache_write_batch": 4096,
613
+ "owt_exact_repeat_per_chunk": 0,
614
+ "online_chunk_shuffle": false,
615
+ "online_chunk_shuffle_buffer": 10000,
616
+ "openwebtext_split": "train_minus_100k",
617
+ "detokenizer": "auto",
618
+ "resolved_detokenizer": null,
619
+ "num_workers": 8,
620
+ "latest_every": 1000,
621
+ "resume_path": ""
622
+ }
623
+ t-20260516062948-lst5d-worker-0:10241:10814 [0] NCCL INFO NVLS comm 0x9929b80 headRank 0 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
624
+ t-20260516062948-lst5d-worker-0:10242:10870 [1] NCCL INFO NVLS comm 0xaf65240 headRank 1 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
625
+ t-20260516062948-lst5d-worker-0:10244:10960 [3] NCCL INFO NVLS comm 0xb291ad0 headRank 3 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
626
+ t-20260516062948-lst5d-worker-0:10243:10961 [2] NCCL INFO NVLS comm 0x9aad980 headRank 2 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
627
+ t-20260516062948-lst5d-worker-0:10246:10963 [5] NCCL INFO NVLS comm 0xb1ff580 headRank 5 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
628
+ t-20260516062948-lst5d-worker-0:10248:10964 [7] NCCL INFO NVLS comm 0x9f87a30 headRank 7 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
629
+ t-20260516062948-lst5d-worker-0:10247:10965 [6] NCCL INFO NVLS comm 0xaa53d10 headRank 6 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
630
+ t-20260516062948-lst5d-worker-0:10245:10966 [4] NCCL INFO NVLS comm 0x9a6d0d0 headRank 4 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
631
+ step=100 micro_steps=200 elapsed=115.3s lr=2.613533e-05 loss=10.3733 loss_recon=10.3733 loss_meanflow=0.0000 mean_model_t=0.2081 mean_corrupt_t=0.2081 mean_loss_t_weight=1.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.0454 corrupt_frac=0.5549 acc_corrupt=0.0372 loss_corrupt=10.3733 wrong_frac=0.7929 init_acc_corrupt=0.1138 acc_corrupt_t_0p0_0p2=0.0340 corrupt_frac_t_0p0_0p2=0.5679 acc_corrupt_t_0p2_0p4=0.0400 corrupt_frac_t_0p2_0p4=0.3435 out_w_norm=0.0169 out_g_norm=1.0189 acc_corrupt_t_0p4_0p6=0.0467 corrupt_frac_t_0p4_0p6=0.0860 acc_corrupt_t_0p6_0p8=0.0449 corrupt_frac_t_0p6_0p8=0.0342 acc_corrupt_t_0p8_1p0=0.0989 corrupt_frac_t_0p8_1p0=0.0095 loss_all=10.3634 init_gold_top10=0.2154 init_gold_top100=0.4564
632
+ step=200 micro_steps=400 elapsed=86.0s lr=5.201190e-05 loss=10.3446 loss_recon=10.3446 loss_meanflow=0.0000 mean_model_t=0.2102 mean_corrupt_t=0.2102 mean_loss_t_weight=1.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.0514 corrupt_frac=0.5476 acc_corrupt=0.0442 loss_corrupt=10.3446 wrong_frac=0.7891 init_acc_corrupt=0.1199 acc_corrupt_t_0p0_0p2=0.0422 corrupt_frac_t_0p0_0p2=0.5602 acc_corrupt_t_0p2_0p4=0.0456 corrupt_frac_t_0p2_0p4=0.3460 acc_corrupt_t_0p4_0p6=0.0498 corrupt_frac_t_0p4_0p6=0.0887 out_w_norm=0.0926 out_g_norm=1.6250 acc_corrupt_t_0p6_0p8=0.0561 corrupt_frac_t_0p6_0p8=0.0361 loss_all=10.3182 init_gold_top10=0.1479 init_gold_top100=0.4573
633
+ step=300 micro_steps=600 elapsed=86.1s lr=7.788847e-05 loss=10.2814 loss_recon=10.2814 loss_meanflow=0.0000 mean_model_t=0.2087 mean_corrupt_t=0.2087 mean_loss_t_weight=1.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.0550 corrupt_frac=0.5486 acc_corrupt=0.0462 loss_corrupt=10.2814 wrong_frac=0.7920 init_acc_corrupt=0.1149 acc_corrupt_t_0p0_0p2=0.0443 corrupt_frac_t_0p0_0p2=0.5626 acc_corrupt_t_0p2_0p4=0.0474 corrupt_frac_t_0p2_0p4=0.3554 acc_corrupt_t_0p4_0p6=0.0526 corrupt_frac_t_0p4_0p6=0.0764 out_w_norm=0.2117 out_g_norm=1.8348 acc_corrupt_t_0p6_0p8=0.0655 corrupt_frac_t_0p6_0p8=0.0338 acc_corrupt_t_0p8_1p0=0.0849 corrupt_frac_t_0p8_1p0=0.0410 loss_all=10.2283 init_gold_top10=0.1761 init_gold_top100=0.4584
634
+ step=400 micro_steps=800 elapsed=86.0s lr=1.037650e-04 loss=10.1819 loss_recon=10.1819 loss_meanflow=0.0000 mean_model_t=0.2101 mean_corrupt_t=0.2101 mean_loss_t_weight=1.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.0622 corrupt_frac=0.5497 acc_corrupt=0.0480 loss_corrupt=10.1819 wrong_frac=0.7920 init_acc_corrupt=0.1141 acc_corrupt_t_0p0_0p2=0.0451 corrupt_frac_t_0p0_0p2=0.5615 acc_corrupt_t_0p2_0p4=0.0497 corrupt_frac_t_0p2_0p4=0.3516 acc_corrupt_t_0p4_0p6=0.0597 corrupt_frac_t_0p4_0p6=0.0843 out_w_norm=0.3818 out_g_norm=1.8762 acc_corrupt_t_0p6_0p8=0.0649 corrupt_frac_t_0p6_0p8=0.0315 loss_all=10.0834 init_gold_top10=0.2435 init_gold_top100=0.4554
635
+ step=500 micro_steps=1000 elapsed=86.1s lr=1.296416e-04 loss=10.0376 loss_recon=10.0376 loss_meanflow=0.0000 mean_model_t=0.2087 mean_corrupt_t=0.2087 mean_loss_t_weight=1.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.0844 corrupt_frac=0.5571 acc_corrupt=0.0529 loss_corrupt=10.0376 wrong_frac=0.7934 init_acc_corrupt=0.1133 acc_corrupt_t_0p0_0p2=0.0460 corrupt_frac_t_0p0_0p2=0.5587 acc_corrupt_t_0p2_0p4=0.0575 corrupt_frac_t_0p2_0p4=0.3629 acc_corrupt_t_0p4_0p6=0.0797 corrupt_frac_t_0p4_0p6=0.0744 out_w_norm=0.6182 out_g_norm=1.8807 acc_corrupt_t_0p6_0p8=0.0944 corrupt_frac_t_0p6_0p8=0.0318 acc_corrupt_t_0p8_1p0=0.1441 corrupt_frac_t_0p8_1p0=0.0262 loss_all=9.8675 init_gold_top10=0.1701 init_gold_top100=0.4777
636
+ step=600 micro_steps=1200 elapsed=86.1s lr=1.555182e-04 loss=9.8017 loss_recon=9.8017 loss_meanflow=0.0000 mean_model_t=0.2097 mean_corrupt_t=0.2097 mean_loss_t_weight=1.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.1423 corrupt_frac=0.5498 acc_corrupt=0.0682 loss_corrupt=9.8017 wrong_frac=0.7894 init_acc_corrupt=0.1176 acc_corrupt_t_0p0_0p2=0.0488 corrupt_frac_t_0p0_0p2=0.5433 acc_corrupt_t_0p2_0p4=0.0820 corrupt_frac_t_0p2_0p4=0.3728 acc_corrupt_t_0p4_0p6=0.1288 corrupt_frac_t_0p4_0p6=0.0809 out_w_norm=0.9391 out_g_norm=1.8284 acc_corrupt_t_0p6_0p8=0.1608 corrupt_frac_t_0p6_0p8=0.0337 loss_all=9.1658 init_gold_top10=0.1670 init_gold_top100=0.4715
637
+ step=700 micro_steps=1400 elapsed=86.1s lr=1.813947e-04 loss=9.4591 loss_recon=9.4591 loss_meanflow=0.0000 mean_model_t=0.2099 mean_corrupt_t=0.2099 mean_loss_t_weight=1.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.1748 corrupt_frac=0.5479 acc_corrupt=0.0775 loss_corrupt=9.4591 wrong_frac=0.7903 init_acc_corrupt=0.1163 acc_corrupt_t_0p0_0p2=0.0524 corrupt_frac_t_0p0_0p2=0.5572 acc_corrupt_t_0p2_0p4=0.0958 corrupt_frac_t_0p2_0p4=0.3513 acc_corrupt_t_0p4_0p6=0.1564 corrupt_frac_t_0p4_0p6=0.0882 out_w_norm=1.3861 out_g_norm=1.7546 acc_corrupt_t_0p6_0p8=0.1990 corrupt_frac_t_0p6_0p8=0.0406 loss_all=8.3915 init_gold_top10=0.2100 init_gold_top100=0.4558
638
+ step=800 micro_steps=1600 elapsed=86.2s lr=2.072713e-04 loss=9.0817 loss_recon=9.0817 loss_meanflow=0.0000 mean_model_t=0.2112 mean_corrupt_t=0.2112 mean_loss_t_weight=1.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.1954 corrupt_frac=0.5501 acc_corrupt=0.0859 loss_corrupt=9.0817 wrong_frac=0.7880 init_acc_corrupt=0.1186 acc_corrupt_t_0p0_0p2=0.0551 corrupt_frac_t_0p0_0p2=0.5469 acc_corrupt_t_0p2_0p4=0.1087 corrupt_frac_t_0p2_0p4=0.3664 acc_corrupt_t_0p4_0p6=0.1770 corrupt_frac_t_0p4_0p6=0.0846 acc_corrupt_t_0p6_0p8=0.2349 corrupt_frac_t_0p6_0p8=0.0401 out_w_norm=1.9573 out_g_norm=1.6633 acc_corrupt_t_0p8_1p0=0.3462 corrupt_frac_t_0p8_1p0=0.0142 loss_all=7.7385 init_gold_top10=0.1907 init_gold_top100=0.4702
639
+ step=900 micro_steps=1800 elapsed=86.1s lr=2.331479e-04 loss=8.7010 loss_recon=8.7010 loss_meanflow=0.0000 mean_model_t=0.2089 mean_corrupt_t=0.2089 mean_loss_t_weight=1.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.2202 corrupt_frac=0.5522 acc_corrupt=0.1017 loss_corrupt=8.7010 wrong_frac=0.7910 init_acc_corrupt=0.1161 acc_corrupt_t_0p0_0p2=0.0671 corrupt_frac_t_0p0_0p2=0.5570 acc_corrupt_t_0p2_0p4=0.1276 corrupt_frac_t_0p2_0p4=0.3541 acc_corrupt_t_0p4_0p6=0.2083 corrupt_frac_t_0p4_0p6=0.0843 out_w_norm=2.6437 out_g_norm=1.5171 acc_corrupt_t_0p6_0p8=0.2671 corrupt_frac_t_0p6_0p8=0.0450 acc_corrupt_t_0p8_1p0=0.3024 corrupt_frac_t_0p8_1p0=0.0342 loss_all=7.6141 init_gold_top10=0.2222 init_gold_top100=0.4160
640
+ step=1000 micro_steps=2000 elapsed=86.2s lr=2.590245e-04 loss=8.3033 loss_recon=8.3033 loss_meanflow=0.0000 mean_model_t=0.2076 mean_corrupt_t=0.2076 mean_loss_t_weight=1.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.2471 corrupt_frac=0.5472 acc_corrupt=0.1205 loss_corrupt=8.3033 wrong_frac=0.7925 init_acc_corrupt=0.1137 acc_corrupt_t_0p0_0p2=0.0828 corrupt_frac_t_0p0_0p2=0.5614 acc_corrupt_t_0p2_0p4=0.1514 corrupt_frac_t_0p2_0p4=0.3565 acc_corrupt_t_0p4_0p6=0.2364 corrupt_frac_t_0p4_0p6=0.0787 acc_corrupt_t_0p6_0p8=0.3057 corrupt_frac_t_0p6_0p8=0.0401 out_w_norm=3.4166 out_g_norm=1.2460 loss_all=7.1860 init_gold_top10=0.2101 init_gold_top100=0.4660
641
+ step=1100 micro_steps=2200 elapsed=87.7s lr=2.849010e-04 loss=7.9125 loss_recon=7.9125 loss_meanflow=0.0000 mean_model_t=0.2096 mean_corrupt_t=0.2096 mean_loss_t_weight=1.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.2694 corrupt_frac=0.5487 acc_corrupt=0.1387 loss_corrupt=7.9125 wrong_frac=0.7917 init_acc_corrupt=0.1154 acc_corrupt_t_0p0_0p2=0.0965 corrupt_frac_t_0p0_0p2=0.5529 acc_corrupt_t_0p2_0p4=0.1725 corrupt_frac_t_0p2_0p4=0.3606 acc_corrupt_t_0p4_0p6=0.2619 corrupt_frac_t_0p4_0p6=0.0866 out_w_norm=4.2495 out_g_norm=0.9327 acc_corrupt_t_0p6_0p8=0.3224 corrupt_frac_t_0p6_0p8=0.0308 loss_all=6.9095 init_gold_top10=0.1427 init_gold_top100=0.4703
642
+ step=1200 micro_steps=2400 elapsed=86.4s lr=3.107776e-04 loss=7.5735 loss_recon=7.5735 loss_meanflow=0.0000 mean_model_t=0.2071 mean_corrupt_t=0.2071 mean_loss_t_weight=1.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.2900 corrupt_frac=0.5535 acc_corrupt=0.1525 loss_corrupt=7.5735 wrong_frac=0.7916 init_acc_corrupt=0.1151 acc_corrupt_t_0p0_0p2=0.1077 corrupt_frac_t_0p0_0p2=0.5606 acc_corrupt_t_0p2_0p4=0.1906 corrupt_frac_t_0p2_0p4=0.3546 acc_corrupt_t_0p4_0p6=0.2821 corrupt_frac_t_0p4_0p6=0.0834 out_w_norm=5.1992 out_g_norm=0.6850 acc_corrupt_t_0p6_0p8=0.3532 corrupt_frac_t_0p6_0p8=0.0354 acc_corrupt_t_0p8_1p0=0.4220 corrupt_frac_t_0p8_1p0=0.0291 loss_all=6.4896 init_gold_top10=0.1752 init_gold_top100=0.4720
LTA_openwebtext_dualt/logs/elfaligned_t5record_8gpu/lta_owt_t5record_len1024_elfaligned_dditelf_muon_logitnormal_m1p5_s0p8_none_floor0p0_gbs512_8gpu_5epoch_20260516_000824.log ADDED
@@ -0,0 +1,636 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ t-20260516080640-ks2k6-worker-0:10250:10250 [0] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
2
+ t-20260516080640-ks2k6-worker-0:10250:10250 [0] NCCL INFO Bootstrap: Using eth1:10.82.32.15<0>
3
+ t-20260516080640-ks2k6-worker-0:10250:10250 [0] NCCL INFO cudaDriverVersion 12080
4
+ t-20260516080640-ks2k6-worker-0:10250:10250 [0] NCCL INFO NCCL version 2.25.1+cuda12.8
5
+ t-20260516080640-ks2k6-worker-0:10250:10250 [0] NCCL INFO Comm config Blocking set to 1
6
+ t-20260516080640-ks2k6-worker-0:10256:10256 [6] NCCL INFO cudaDriverVersion 12080
7
+ t-20260516080640-ks2k6-worker-0:10256:10256 [6] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
8
+ t-20260516080640-ks2k6-worker-0:10251:10251 [1] NCCL INFO cudaDriverVersion 12080
9
+ t-20260516080640-ks2k6-worker-0:10251:10251 [1] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
10
+ t-20260516080640-ks2k6-worker-0:10254:10254 [4] NCCL INFO cudaDriverVersion 12080
11
+ t-20260516080640-ks2k6-worker-0:10254:10254 [4] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
12
+ t-20260516080640-ks2k6-worker-0:10256:10256 [6] NCCL INFO Bootstrap: Using eth1:10.82.32.15<0>
13
+ t-20260516080640-ks2k6-worker-0:10256:10256 [6] NCCL INFO NCCL version 2.25.1+cuda12.8
14
+ t-20260516080640-ks2k6-worker-0:10251:10251 [1] NCCL INFO Bootstrap: Using eth1:10.82.32.15<0>
15
+ t-20260516080640-ks2k6-worker-0:10254:10254 [4] NCCL INFO Bootstrap: Using eth1:10.82.32.15<0>
16
+ t-20260516080640-ks2k6-worker-0:10251:10251 [1] NCCL INFO NCCL version 2.25.1+cuda12.8
17
+ t-20260516080640-ks2k6-worker-0:10254:10254 [4] NCCL INFO NCCL version 2.25.1+cuda12.8
18
+ t-20260516080640-ks2k6-worker-0:10256:10256 [6] NCCL INFO Comm config Blocking set to 1
19
+ t-20260516080640-ks2k6-worker-0:10254:10254 [4] NCCL INFO Comm config Blocking set to 1
20
+ t-20260516080640-ks2k6-worker-0:10251:10251 [1] NCCL INFO Comm config Blocking set to 1
21
+ t-20260516080640-ks2k6-worker-0:10252:10252 [2] NCCL INFO cudaDriverVersion 12080
22
+ t-20260516080640-ks2k6-worker-0:10252:10252 [2] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
23
+ t-20260516080640-ks2k6-worker-0:10252:10252 [2] NCCL INFO Bootstrap: Using eth1:10.82.32.15<0>
24
+ t-20260516080640-ks2k6-worker-0:10252:10252 [2] NCCL INFO NCCL version 2.25.1+cuda12.8
25
+ t-20260516080640-ks2k6-worker-0:10252:10252 [2] NCCL INFO Comm config Blocking set to 1
26
+ t-20260516080640-ks2k6-worker-0:10253:10253 [3] NCCL INFO cudaDriverVersion 12080
27
+ t-20260516080640-ks2k6-worker-0:10253:10253 [3] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
28
+ t-20260516080640-ks2k6-worker-0:10253:10253 [3] NCCL INFO Bootstrap: Using eth1:10.82.32.15<0>
29
+ t-20260516080640-ks2k6-worker-0:10253:10253 [3] NCCL INFO NCCL version 2.25.1+cuda12.8
30
+ t-20260516080640-ks2k6-worker-0:10253:10253 [3] NCCL INFO Comm config Blocking set to 1
31
+ t-20260516080640-ks2k6-worker-0:10255:10255 [5] NCCL INFO cudaDriverVersion 12080
32
+ t-20260516080640-ks2k6-worker-0:10255:10255 [5] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
33
+ t-20260516080640-ks2k6-worker-0:10255:10255 [5] NCCL INFO Bootstrap: Using eth1:10.82.32.15<0>
34
+ t-20260516080640-ks2k6-worker-0:10255:10255 [5] NCCL INFO NCCL version 2.25.1+cuda12.8
35
+ t-20260516080640-ks2k6-worker-0:10255:10255 [5] NCCL INFO Comm config Blocking set to 1
36
+ t-20260516080640-ks2k6-worker-0:10257:10257 [7] NCCL INFO cudaDriverVersion 12080
37
+ t-20260516080640-ks2k6-worker-0:10257:10257 [7] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
38
+ t-20260516080640-ks2k6-worker-0:10257:10257 [7] NCCL INFO Bootstrap: Using eth1:10.82.32.15<0>
39
+ t-20260516080640-ks2k6-worker-0:10257:10257 [7] NCCL INFO NCCL version 2.25.1+cuda12.8
40
+ t-20260516080640-ks2k6-worker-0:10257:10257 [7] NCCL INFO Comm config Blocking set to 1
41
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
42
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
43
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
44
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO P2P plugin v9 IBext_v9
45
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
46
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
47
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
48
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
49
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO P2P plugin v9 IBext_v9
50
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
51
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
52
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
53
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
54
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO P2P plugin v9 IBext_v9
55
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
56
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
57
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
58
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
59
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO P2P plugin v9 IBext_v9
60
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
61
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
62
+ t-20260516080640-ks2k6-worker-0:10250:10330 [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.32.15<0>
63
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
64
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Using network IBext_v9
65
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
66
+ t-20260516080640-ks2k6-worker-0:10251:10333 [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.32.15<0>
67
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
68
+ t-20260516080640-ks2k6-worker-0:10254:10332 [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.32.15<0>
69
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
70
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO Using network IBext_v9
71
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
72
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO Using network IBext_v9
73
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
74
+ t-20260516080640-ks2k6-worker-0:10256:10331 [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.32.15<0>
75
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
76
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO Using network IBext_v9
77
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
78
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
79
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
80
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO P2P plugin v9 IBext_v9
81
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
82
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
83
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
84
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
85
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO P2P plugin v9 IBext_v9
86
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
87
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
88
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
89
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
90
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO P2P plugin v9 IBext_v9
91
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
92
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
93
+ t-20260516080640-ks2k6-worker-0:10252:10334 [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.32.15<0>
94
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
95
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO Using network IBext_v9
96
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
97
+ t-20260516080640-ks2k6-worker-0:10253:10335 [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.32.15<0>
98
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
99
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO Using network IBext_v9
100
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
101
+ t-20260516080640-ks2k6-worker-0:10255:10336 [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.32.15<0>
102
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
103
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO Using network IBext_v9
104
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO NET/Plugin: Loaded net plugin NCCL RDMA Plugin v9 (v9)
105
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO NET/Plugin: Loaded collnet plugin SHARP (v9)
106
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO Plugin Path : /opt/hpcx/nccl_rdma_sharp_plugin/lib/libnccl-net.so
107
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO P2P plugin v9 IBext_v9
108
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO NCCL_SOCKET_IFNAME set by environment to eth1
109
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO ncclCommInitRankConfig comm 0x9f91be0 rank 0 nranks 8 cudaDev 0 nvmlDev 0 busId 65040 commId 0x888384a9cc51f1d4 - Init START
110
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO NCCL_IB_PCI_RELAXED_ORDERING set by environment to 1.
111
+ t-20260516080640-ks2k6-worker-0:10257:10337 [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.32.15<0>
112
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO PROFILER/Plugin: Could not find: libnccl-profiler.so.
113
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO Using network IBext_v9
114
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO ncclCommInitRankConfig comm 0xb506970 rank 4 nranks 8 cudaDev 4 nvmlDev 4 busId 6f020 commId 0x888384a9cc51f1d4 - Init START
115
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO ncclCommInitRankConfig comm 0x9a45db0 rank 1 nranks 8 cudaDev 1 nvmlDev 1 busId 67020 commId 0x888384a9cc51f1d4 - Init START
116
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO ncclCommInitRankConfig comm 0xb812680 rank 6 nranks 8 cudaDev 6 nvmlDev 6 busId 73020 commId 0x888384a9cc51f1d4 - Init START
117
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO ncclCommInitRankConfig comm 0xb2c0700 rank 2 nranks 8 cudaDev 2 nvmlDev 2 busId 69020 commId 0x888384a9cc51f1d4 - Init START
118
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO RAS client listening socket at ::1<28028>
119
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO ncclCommInitRankConfig comm 0xa06a9c0 rank 3 nranks 8 cudaDev 3 nvmlDev 3 busId 6b020 commId 0x888384a9cc51f1d4 - Init START
120
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO RAS client listening socket at ::1<28028>
121
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO RAS client listening socket at ::1<28028>
122
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO ncclCommInitRankConfig comm 0xa632cd0 rank 5 nranks 8 cudaDev 5 nvmlDev 5 busId 71020 commId 0x888384a9cc51f1d4 - Init START
123
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO RAS client listening socket at ::1<28028>
124
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO RAS client listening socket at ::1<28028>
125
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO ncclCommInitRankConfig comm 0xa6619b0 rank 7 nranks 8 cudaDev 7 nvmlDev 7 busId 75020 commId 0x888384a9cc51f1d4 - Init START
126
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO RAS client listening socket at ::1<28028>
127
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO RAS client listening socket at ::1<28028>
128
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO RAS client listening socket at ::1<28028>
129
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO Bootstrap timings total 0.035510 (create 0.000022, send 0.000069, recv 0.000083, ring 0.035078, delay 0.000001)
130
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Bootstrap timings total 0.429759 (create 0.000025, send 0.000071, recv 0.033914, ring 0.000166, delay 0.000001)
131
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO Bootstrap timings total 0.042301 (create 0.000021, send 0.000068, recv 0.006856, ring 0.035065, delay 0.000001)
132
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO Bootstrap timings total 0.000623 (create 0.000021, send 0.000070, recv 0.000073, ring 0.000163, delay 0.000001)
133
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO Bootstrap timings total 0.024796 (create 0.000020, send 0.000065, recv 0.000077, ring 0.024312, delay 0.000001)
134
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO Bootstrap timings total 0.387672 (create 0.000020, send 0.000068, recv 0.387128, ring 0.000126, delay 0.000001)
135
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO Bootstrap timings total 0.398382 (create 0.000022, send 0.000066, recv 0.373675, ring 0.024179, delay 0.000001)
136
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO Bootstrap timings total 0.395926 (create 0.000021, send 0.000082, recv 0.353710, ring 0.041723, delay 0.000001)
137
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO MNNVL busId 0x69020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
138
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO MNNVL busId 0x71020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
139
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO MNNVL busId 0x65040 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
140
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO MNNVL busId 0x6b020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
141
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO MNNVL busId 0x75020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
142
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO MNNVL busId 0x73020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
143
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO MNNVL busId 0x67020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
144
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO MNNVL busId 0x6f020 fabric UUID 0.0 cliqueId 0x0 state 3 healthMask 0x0
145
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
146
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
147
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
148
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
149
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
150
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
151
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
152
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO NCCL_TOPO_FILE set by environment to /var/run/nvidia-topologyd/virtualTopology.xml
153
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO Setting affinity for GPU 3 to 03ffffff,ffffffff,ffffffff
154
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO NVLS multicast support is available on dev 3
155
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO Setting affinity for GPU 1 to 03ffffff,ffffffff,ffffffff
156
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO Setting affinity for GPU 6 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
157
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO NVLS multicast support is available on dev 6
158
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO NVLS multicast support is available on dev 1
159
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Setting affinity for GPU 0 to 03ffffff,ffffffff,ffffffff
160
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO Setting affinity for GPU 7 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
161
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO NVLS multicast support is available on dev 7
162
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO Setting affinity for GPU 2 to 03ffffff,ffffffff,ffffffff
163
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO Setting affinity for GPU 4 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
164
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO Setting affinity for GPU 5 to 0fffff,ffffffff,ffffffff,fc000000,00000000,00000000
165
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO NVLS multicast support is available on dev 5
166
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO NVLS multicast support is available on dev 4
167
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO NVLS multicast support is available on dev 0
168
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO NVLS multicast support is available on dev 2
169
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO comm 0xb2c0700 rank 2 nRanks 8 nNodes 1 localRanks 8 localRank 2 MNNVL 0
170
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO comm 0x9a45db0 rank 1 nRanks 8 nNodes 1 localRanks 8 localRank 1 MNNVL 0
171
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO comm 0xb812680 rank 6 nRanks 8 nNodes 1 localRanks 8 localRank 6 MNNVL 0
172
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO comm 0x9f91be0 rank 0 nRanks 8 nNodes 1 localRanks 8 localRank 0 MNNVL 0
173
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO comm 0xa6619b0 rank 7 nRanks 8 nNodes 1 localRanks 8 localRank 7 MNNVL 0
174
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO comm 0xa632cd0 rank 5 nRanks 8 nNodes 1 localRanks 8 localRank 5 MNNVL 0
175
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO comm 0xb506970 rank 4 nRanks 8 nNodes 1 localRanks 8 localRank 4 MNNVL 0
176
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO comm 0xa06a9c0 rank 3 nRanks 8 nNodes 1 localRanks 8 localRank 3 MNNVL 0
177
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 00/24 : 0 1 2 3 4 5 6 7
178
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 01/24 : 0 1 2 3 4 5 6 7
179
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 02/24 : 0 1 2 3 4 5 6 7
180
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 03/24 : 0 1 2 3 4 5 6 7
181
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 04/24 : 0 1 2 3 4 5 6 7
182
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 05/24 : 0 1 2 3 4 5 6 7
183
+ t-20260516080640-ks2k6-worker-0:10256:10331 [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
184
+ t-20260516080640-ks2k6-worker-0:10257:10337 [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
185
+ t-20260516080640-ks2k6-worker-0:10254:10332 [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
186
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 06/24 : 0 1 2 3 4 5 6 7
187
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO P2P Chunksize set to 524288
188
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO P2P Chunksize set to 524288
189
+ t-20260516080640-ks2k6-worker-0:10251:10333 [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
190
+ t-20260516080640-ks2k6-worker-0:10255:10336 [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
191
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO P2P Chunksize set to 524288
192
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 07/24 : 0 1 2 3 4 5 6 7
193
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO P2P Chunksize set to 524288
194
+ t-20260516080640-ks2k6-worker-0:10252:10334 [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
195
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO P2P Chunksize set to 524288
196
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 08/24 : 0 1 2 3 4 5 6 7
197
+ t-20260516080640-ks2k6-worker-0:10253:10335 [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
198
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 09/24 : 0 1 2 3 4 5 6 7
199
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO P2P Chunksize set to 524288
200
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 10/24 : 0 1 2 3 4 5 6 7
201
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO P2P Chunksize set to 524288
202
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 11/24 : 0 1 2 3 4 5 6 7
203
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 12/24 : 0 1 2 3 4 5 6 7
204
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 13/24 : 0 1 2 3 4 5 6 7
205
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 14/24 : 0 1 2 3 4 5 6 7
206
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 15/24 : 0 1 2 3 4 5 6 7
207
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 16/24 : 0 1 2 3 4 5 6 7
208
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 17/24 : 0 1 2 3 4 5 6 7
209
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 18/24 : 0 1 2 3 4 5 6 7
210
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 19/24 : 0 1 2 3 4 5 6 7
211
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 20/24 : 0 1 2 3 4 5 6 7
212
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 21/24 : 0 1 2 3 4 5 6 7
213
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 22/24 : 0 1 2 3 4 5 6 7
214
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Channel 23/24 : 0 1 2 3 4 5 6 7
215
+ t-20260516080640-ks2k6-worker-0:10250:10330 [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
216
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO P2P Chunksize set to 524288
217
+ t-20260516080640-ks2k6-worker-0:10257:10411 [7] NCCL INFO [Proxy Service] Device 7 CPU core 123
218
+ t-20260516080640-ks2k6-worker-0:10254:10410 [4] NCCL INFO [Proxy Service] Device 4 CPU core 160
219
+ t-20260516080640-ks2k6-worker-0:10256:10414 [6] NCCL INFO [Proxy Service] Device 6 CPU core 92
220
+ t-20260516080640-ks2k6-worker-0:10255:10415 [5] NCCL INFO [Proxy Service] Device 5 CPU core 114
221
+ t-20260516080640-ks2k6-worker-0:10251:10418 [1] NCCL INFO [Proxy Service] Device 1 CPU core 68
222
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Check P2P Type intraNodeP2pSupport 1 directMode 0
223
+ t-20260516080640-ks2k6-worker-0:10253:10421 [3] NCCL INFO [Proxy Service] Device 3 CPU core 2
224
+ t-20260516080640-ks2k6-worker-0:10252:10422 [2] NCCL INFO [Proxy Service UDS] Device 2 CPU core 8
225
+ t-20260516080640-ks2k6-worker-0:10250:10423 [0] NCCL INFO [Proxy Service] Device 0 CPU core 84
226
+ t-20260516080640-ks2k6-worker-0:10251:10419 [1] NCCL INFO [Proxy Service UDS] Device 1 CPU core 72
227
+ t-20260516080640-ks2k6-worker-0:10255:10417 [5] NCCL INFO [Proxy Service UDS] Device 5 CPU core 116
228
+ t-20260516080640-ks2k6-worker-0:10257:10413 [7] NCCL INFO [Proxy Service UDS] Device 7 CPU core 124
229
+ t-20260516080640-ks2k6-worker-0:10253:10424 [3] NCCL INFO [Proxy Service UDS] Device 3 CPU core 19
230
+ t-20260516080640-ks2k6-worker-0:10252:10420 [2] NCCL INFO [Proxy Service] Device 2 CPU core 2
231
+ t-20260516080640-ks2k6-worker-0:10254:10412 [4] NCCL INFO [Proxy Service UDS] Device 4 CPU core 164
232
+ t-20260516080640-ks2k6-worker-0:10256:10416 [6] NCCL INFO [Proxy Service UDS] Device 6 CPU core 94
233
+ t-20260516080640-ks2k6-worker-0:10250:10425 [0] NCCL INFO [Proxy Service UDS] Device 0 CPU core 87
234
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
235
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
236
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
237
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
238
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
239
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
240
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
241
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
242
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
243
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
244
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
245
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
246
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
247
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO threadThresholds 8/8/64 | 64/8/64 | 512 | 512
248
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
249
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO 24 coll channels, 24 collnet channels, 16 nvls channels, 32 p2p channels, 32 p2p channels per peer
250
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO CC Off, workFifoBytes 1048576
251
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
252
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
253
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
254
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
255
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
256
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
257
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
258
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
259
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
260
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
261
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
262
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
263
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
264
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
265
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
266
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO ncclCommInitRankConfig comm 0xb2c0700 rank 2 nranks 8 cudaDev 2 nvmlDev 2 busId 69020 commId 0x888384a9cc51f1d4 - Init COMPLETE
267
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
268
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO ncclCommInitRankConfig comm 0xa06a9c0 rank 3 nranks 8 cudaDev 3 nvmlDev 3 busId 6b020 commId 0x888384a9cc51f1d4 - Init COMPLETE
269
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
270
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
271
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO ncclCommInitRankConfig comm 0xa632cd0 rank 5 nranks 8 cudaDev 5 nvmlDev 5 busId 71020 commId 0x888384a9cc51f1d4 - Init COMPLETE
272
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
273
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v4 symbol.
274
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO ncclCommInitRankConfig comm 0xb506970 rank 4 nranks 8 cudaDev 4 nvmlDev 4 busId 6f020 commId 0x888384a9cc51f1d4 - Init COMPLETE
275
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO ncclCommInitRankConfig comm 0x9a45db0 rank 1 nranks 8 cudaDev 1 nvmlDev 1 busId 67020 commId 0x888384a9cc51f1d4 - Init COMPLETE
276
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
277
+ t-20260516080640-ks2k6-worker-0:10253:10335 [3] NCCL INFO Init timings - ncclCommInitRankConfig: rank 3 nranks 8 total 2.14 (kernels 0.46, alloc 0.65, bootstrap 0.04, allgathers 0.01, topo 0.55, graphs 0.01, connections 0.40, rest 0.02)
278
+ t-20260516080640-ks2k6-worker-0:10252:10334 [2] NCCL INFO Init timings - ncclCommInitRankConfig: rank 2 nranks 8 total 2.15 (kernels 0.45, alloc 0.66, bootstrap 0.04, allgathers 0.00, topo 0.55, graphs 0.01, connections 0.40, rest 0.03)
279
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO ncclCommInitRankConfig comm 0xa6619b0 rank 7 nranks 8 cudaDev 7 nvmlDev 7 busId 75020 commId 0x888384a9cc51f1d4 - Init COMPLETE
280
+ t-20260516080640-ks2k6-worker-0:10255:10336 [5] NCCL INFO Init timings - ncclCommInitRankConfig: rank 5 nranks 8 total 2.14 (kernels 0.50, alloc 0.63, bootstrap 0.02, allgathers 0.00, topo 0.55, graphs 0.01, connections 0.40, rest 0.02)
281
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v3 symbol.
282
+ t-20260516080640-ks2k6-worker-0:10251:10333 [1] NCCL INFO Init timings - ncclCommInitRankConfig: rank 1 nranks 8 total 2.26 (kernels 0.19, alloc 0.68, bootstrap 0.40, allgathers 0.01, topo 0.55, graphs 0.01, connections 0.40, rest 0.02)
283
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
284
+ t-20260516080640-ks2k6-worker-0:10254:10332 [4] NCCL INFO Init timings - ncclCommInitRankConfig: rank 4 nranks 8 total 2.26 (kernels 0.19, alloc 0.68, bootstrap 0.40, allgathers 0.01, topo 0.55, graphs 0.01, connections 0.40, rest 0.02)
285
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO TUNER/Plugin: Failed to find ncclTunerPlugin_v2 symbol, using internal tuner instead.
286
+ t-20260516080640-ks2k6-worker-0:10257:10337 [7] NCCL INFO Init timings - ncclCommInitRankConfig: rank 7 nranks 8 total 2.13 (kernels 0.66, alloc 0.48, bootstrap 0.00, allgathers 0.01, topo 0.55, graphs 0.01, connections 0.40, rest 0.02)
287
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO ncclCommInitRankConfig comm 0xb812680 rank 6 nranks 8 cudaDev 6 nvmlDev 6 busId 73020 commId 0x888384a9cc51f1d4 - Init COMPLETE
288
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO ncclCommInitRankConfig comm 0x9f91be0 rank 0 nranks 8 cudaDev 0 nvmlDev 0 busId 65040 commId 0x888384a9cc51f1d4 - Init COMPLETE
289
+ t-20260516080640-ks2k6-worker-0:10256:10331 [6] NCCL INFO Init timings - ncclCommInitRankConfig: rank 6 nranks 8 total 2.26 (kernels 0.20, alloc 0.69, bootstrap 0.39, allgathers 0.01, topo 0.55, graphs 0.01, connections 0.40, rest 0.02)
290
+ t-20260516080640-ks2k6-worker-0:10250:10330 [0] NCCL INFO Init timings - ncclCommInitRankConfig: rank 0 nranks 8 total 2.27 (kernels 0.19, alloc 0.65, bootstrap 0.43, allgathers 0.01, topo 0.55, graphs 0.01, connections 0.40, rest 0.02)
291
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 00/0 : 2[2] -> 3[3] via P2P/CUMEM
292
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 01/0 : 2[2] -> 3[3] via P2P/CUMEM
293
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 02/0 : 2[2] -> 3[3] via P2P/CUMEM
294
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 03/0 : 2[2] -> 3[3] via P2P/CUMEM
295
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 04/0 : 2[2] -> 3[3] via P2P/CUMEM
296
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 05/0 : 2[2] -> 3[3] via P2P/CUMEM
297
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 06/0 : 2[2] -> 3[3] via P2P/CUMEM
298
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 07/0 : 2[2] -> 3[3] via P2P/CUMEM
299
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 08/0 : 2[2] -> 3[3] via P2P/CUMEM
300
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 09/0 : 2[2] -> 3[3] via P2P/CUMEM
301
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 10/0 : 2[2] -> 3[3] via P2P/CUMEM
302
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 11/0 : 2[2] -> 3[3] via P2P/CUMEM
303
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 12/0 : 2[2] -> 3[3] via P2P/CUMEM
304
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 13/0 : 2[2] -> 3[3] via P2P/CUMEM
305
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 14/0 : 2[2] -> 3[3] via P2P/CUMEM
306
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 15/0 : 2[2] -> 3[3] via P2P/CUMEM
307
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 00/0 : 6[6] -> 7[7] via P2P/CUMEM
308
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 16/0 : 2[2] -> 3[3] via P2P/CUMEM
309
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 01/0 : 6[6] -> 7[7] via P2P/CUMEM
310
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 17/0 : 2[2] -> 3[3] via P2P/CUMEM
311
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 00/0 : 3[3] -> 4[4] via P2P/CUMEM
312
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 00/0 : 4[4] -> 5[5] via P2P/CUMEM
313
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 18/0 : 2[2] -> 3[3] via P2P/CUMEM
314
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 01/0 : 3[3] -> 4[4] via P2P/CUMEM
315
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 01/0 : 4[4] -> 5[5] via P2P/CUMEM
316
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 19/0 : 2[2] -> 3[3] via P2P/CUMEM
317
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 02/0 : 3[3] -> 4[4] via P2P/CUMEM
318
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 02/0 : 4[4] -> 5[5] via P2P/CUMEM
319
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 20/0 : 2[2] -> 3[3] via P2P/CUMEM
320
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 02/0 : 6[6] -> 7[7] via P2P/CUMEM
321
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 21/0 : 2[2] -> 3[3] via P2P/CUMEM
322
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 00/0 : 7[7] -> 0[0] via P2P/CUMEM
323
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 03/0 : 6[6] -> 7[7] via P2P/CUMEM
324
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 03/0 : 3[3] -> 4[4] via P2P/CUMEM
325
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 03/0 : 4[4] -> 5[5] via P2P/CUMEM
326
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 04/0 : 6[6] -> 7[7] via P2P/CUMEM
327
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 04/0 : 3[3] -> 4[4] via P2P/CUMEM
328
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 04/0 : 4[4] -> 5[5] via P2P/CUMEM
329
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 05/0 : 6[6] -> 7[7] via P2P/CUMEM
330
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 05/0 : 3[3] -> 4[4] via P2P/CUMEM
331
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 06/0 : 6[6] -> 7[7] via P2P/CUMEM
332
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 05/0 : 4[4] -> 5[5] via P2P/CUMEM
333
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 06/0 : 3[3] -> 4[4] via P2P/CUMEM
334
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 07/0 : 6[6] -> 7[7] via P2P/CUMEM
335
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 06/0 : 4[4] -> 5[5] via P2P/CUMEM
336
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 07/0 : 3[3] -> 4[4] via P2P/CUMEM
337
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 08/0 : 6[6] -> 7[7] via P2P/CUMEM
338
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 07/0 : 4[4] -> 5[5] via P2P/CUMEM
339
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 08/0 : 3[3] -> 4[4] via P2P/CUMEM
340
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 09/0 : 6[6] -> 7[7] via P2P/CUMEM
341
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 08/0 : 4[4] -> 5[5] via P2P/CUMEM
342
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 09/0 : 3[3] -> 4[4] via P2P/CUMEM
343
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 00/0 : 5[5] -> 6[6] via P2P/CUMEM
344
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 10/0 : 6[6] -> 7[7] via P2P/CUMEM
345
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 09/0 : 4[4] -> 5[5] via P2P/CUMEM
346
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 10/0 : 3[3] -> 4[4] via P2P/CUMEM
347
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 01/0 : 5[5] -> 6[6] via P2P/CUMEM
348
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 11/0 : 6[6] -> 7[7] via P2P/CUMEM
349
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 00/0 : 1[1] -> 2[2] via P2P/CUMEM
350
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 10/0 : 4[4] -> 5[5] via P2P/CUMEM
351
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 11/0 : 3[3] -> 4[4] via P2P/CUMEM
352
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 02/0 : 5[5] -> 6[6] via P2P/CUMEM
353
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 12/0 : 6[6] -> 7[7] via P2P/CUMEM
354
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 22/0 : 2[2] -> 3[3] via P2P/CUMEM
355
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 01/0 : 1[1] -> 2[2] via P2P/CUMEM
356
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 11/0 : 4[4] -> 5[5] via P2P/CUMEM
357
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 00/0 : 0[0] -> 1[1] via P2P/CUMEM
358
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 12/0 : 3[3] -> 4[4] via P2P/CUMEM
359
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 01/0 : 7[7] -> 0[0] via P2P/CUMEM
360
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 03/0 : 5[5] -> 6[6] via P2P/CUMEM
361
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 13/0 : 6[6] -> 7[7] via P2P/CUMEM
362
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Channel 23/0 : 2[2] -> 3[3] via P2P/CUMEM
363
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 02/0 : 1[1] -> 2[2] via P2P/CUMEM
364
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 12/0 : 4[4] -> 5[5] via P2P/CUMEM
365
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 01/0 : 0[0] -> 1[1] via P2P/CUMEM
366
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 13/0 : 3[3] -> 4[4] via P2P/CUMEM
367
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 02/0 : 7[7] -> 0[0] via P2P/CUMEM
368
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 04/0 : 5[5] -> 6[6] via P2P/CUMEM
369
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 14/0 : 6[6] -> 7[7] via P2P/CUMEM
370
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 03/0 : 7[7] -> 0[0] via P2P/CUMEM
371
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 13/0 : 4[4] -> 5[5] via P2P/CUMEM
372
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 05/0 : 5[5] -> 6[6] via P2P/CUMEM
373
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 04/0 : 7[7] -> 0[0] via P2P/CUMEM
374
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 14/0 : 4[4] -> 5[5] via P2P/CUMEM
375
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 06/0 : 5[5] -> 6[6] via P2P/CUMEM
376
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 05/0 : 7[7] -> 0[0] via P2P/CUMEM
377
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 15/0 : 4[4] -> 5[5] via P2P/CUMEM
378
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 07/0 : 5[5] -> 6[6] via P2P/CUMEM
379
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 06/0 : 7[7] -> 0[0] via P2P/CUMEM
380
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 16/0 : 4[4] -> 5[5] via P2P/CUMEM
381
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 08/0 : 5[5] -> 6[6] via P2P/CUMEM
382
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 07/0 : 7[7] -> 0[0] via P2P/CUMEM
383
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 17/0 : 4[4] -> 5[5] via P2P/CUMEM
384
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 09/0 : 5[5] -> 6[6] via P2P/CUMEM
385
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 08/0 : 7[7] -> 0[0] via P2P/CUMEM
386
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 18/0 : 4[4] -> 5[5] via P2P/CUMEM
387
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 10/0 : 5[5] -> 6[6] via P2P/CUMEM
388
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 09/0 : 7[7] -> 0[0] via P2P/CUMEM
389
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 19/0 : 4[4] -> 5[5] via P2P/CUMEM
390
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 11/0 : 5[5] -> 6[6] via P2P/CUMEM
391
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 10/0 : 7[7] -> 0[0] via P2P/CUMEM
392
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 20/0 : 4[4] -> 5[5] via P2P/CUMEM
393
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 12/0 : 5[5] -> 6[6] via P2P/CUMEM
394
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 11/0 : 7[7] -> 0[0] via P2P/CUMEM
395
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 21/0 : 4[4] -> 5[5] via P2P/CUMEM
396
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 13/0 : 5[5] -> 6[6] via P2P/CUMEM
397
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 12/0 : 7[7] -> 0[0] via P2P/CUMEM
398
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 22/0 : 4[4] -> 5[5] via P2P/CUMEM
399
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 14/0 : 5[5] -> 6[6] via P2P/CUMEM
400
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 13/0 : 7[7] -> 0[0] via P2P/CUMEM
401
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Channel 23/0 : 4[4] -> 5[5] via P2P/CUMEM
402
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 15/0 : 5[5] -> 6[6] via P2P/CUMEM
403
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 03/0 : 1[1] -> 2[2] via P2P/CUMEM
404
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 02/0 : 0[0] -> 1[1] via P2P/CUMEM
405
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 14/0 : 7[7] -> 0[0] via P2P/CUMEM
406
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 14/0 : 3[3] -> 4[4] via P2P/CUMEM
407
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 15/0 : 6[6] -> 7[7] via P2P/CUMEM
408
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 16/0 : 5[5] -> 6[6] via P2P/CUMEM
409
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 04/0 : 1[1] -> 2[2] via P2P/CUMEM
410
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 03/0 : 0[0] -> 1[1] via P2P/CUMEM
411
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 15/0 : 7[7] -> 0[0] via P2P/CUMEM
412
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 15/0 : 3[3] -> 4[4] via P2P/CUMEM
413
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 16/0 : 6[6] -> 7[7] via P2P/CUMEM
414
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 17/0 : 5[5] -> 6[6] via P2P/CUMEM
415
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 05/0 : 1[1] -> 2[2] via P2P/CUMEM
416
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 04/0 : 0[0] -> 1[1] via P2P/CUMEM
417
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 16/0 : 7[7] -> 0[0] via P2P/CUMEM
418
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 16/0 : 3[3] -> 4[4] via P2P/CUMEM
419
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 17/0 : 6[6] -> 7[7] via P2P/CUMEM
420
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 18/0 : 5[5] -> 6[6] via P2P/CUMEM
421
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 06/0 : 1[1] -> 2[2] via P2P/CUMEM
422
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 05/0 : 0[0] -> 1[1] via P2P/CUMEM
423
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 17/0 : 7[7] -> 0[0] via P2P/CUMEM
424
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 17/0 : 3[3] -> 4[4] via P2P/CUMEM
425
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 18/0 : 6[6] -> 7[7] via P2P/CUMEM
426
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 19/0 : 5[5] -> 6[6] via P2P/CUMEM
427
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 07/0 : 1[1] -> 2[2] via P2P/CUMEM
428
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 06/0 : 0[0] -> 1[1] via P2P/CUMEM
429
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 18/0 : 7[7] -> 0[0] via P2P/CUMEM
430
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 18/0 : 3[3] -> 4[4] via P2P/CUMEM
431
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 19/0 : 6[6] -> 7[7] via P2P/CUMEM
432
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 20/0 : 5[5] -> 6[6] via P2P/CUMEM
433
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 08/0 : 1[1] -> 2[2] via P2P/CUMEM
434
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 07/0 : 0[0] -> 1[1] via P2P/CUMEM
435
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 19/0 : 7[7] -> 0[0] via P2P/CUMEM
436
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 19/0 : 3[3] -> 4[4] via P2P/CUMEM
437
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 20/0 : 6[6] -> 7[7] via P2P/CUMEM
438
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 21/0 : 5[5] -> 6[6] via P2P/CUMEM
439
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 09/0 : 1[1] -> 2[2] via P2P/CUMEM
440
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 08/0 : 0[0] -> 1[1] via P2P/CUMEM
441
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 20/0 : 7[7] -> 0[0] via P2P/CUMEM
442
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 20/0 : 3[3] -> 4[4] via P2P/CUMEM
443
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 21/0 : 6[6] -> 7[7] via P2P/CUMEM
444
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 22/0 : 5[5] -> 6[6] via P2P/CUMEM
445
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 10/0 : 1[1] -> 2[2] via P2P/CUMEM
446
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 09/0 : 0[0] -> 1[1] via P2P/CUMEM
447
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 21/0 : 7[7] -> 0[0] via P2P/CUMEM
448
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 21/0 : 3[3] -> 4[4] via P2P/CUMEM
449
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 22/0 : 6[6] -> 7[7] via P2P/CUMEM
450
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Channel 23/0 : 5[5] -> 6[6] via P2P/CUMEM
451
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 11/0 : 1[1] -> 2[2] via P2P/CUMEM
452
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 10/0 : 0[0] -> 1[1] via P2P/CUMEM
453
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 22/0 : 7[7] -> 0[0] via P2P/CUMEM
454
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 22/0 : 3[3] -> 4[4] via P2P/CUMEM
455
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Channel 23/0 : 6[6] -> 7[7] via P2P/CUMEM
456
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 12/0 : 1[1] -> 2[2] via P2P/CUMEM
457
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 11/0 : 0[0] -> 1[1] via P2P/CUMEM
458
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Channel 23/0 : 7[7] -> 0[0] via P2P/CUMEM
459
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Channel 23/0 : 3[3] -> 4[4] via P2P/CUMEM
460
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 13/0 : 1[1] -> 2[2] via P2P/CUMEM
461
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 12/0 : 0[0] -> 1[1] via P2P/CUMEM
462
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 14/0 : 1[1] -> 2[2] via P2P/CUMEM
463
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 13/0 : 0[0] -> 1[1] via P2P/CUMEM
464
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 15/0 : 1[1] -> 2[2] via P2P/CUMEM
465
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 14/0 : 0[0] -> 1[1] via P2P/CUMEM
466
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 16/0 : 1[1] -> 2[2] via P2P/CUMEM
467
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 17/0 : 1[1] -> 2[2] via P2P/CUMEM
468
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 15/0 : 0[0] -> 1[1] via P2P/CUMEM
469
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 16/0 : 0[0] -> 1[1] via P2P/CUMEM
470
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 18/0 : 1[1] -> 2[2] via P2P/CUMEM
471
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 17/0 : 0[0] -> 1[1] via P2P/CUMEM
472
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 19/0 : 1[1] -> 2[2] via P2P/CUMEM
473
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 18/0 : 0[0] -> 1[1] via P2P/CUMEM
474
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 20/0 : 1[1] -> 2[2] via P2P/CUMEM
475
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 19/0 : 0[0] -> 1[1] via P2P/CUMEM
476
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 21/0 : 1[1] -> 2[2] via P2P/CUMEM
477
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 20/0 : 0[0] -> 1[1] via P2P/CUMEM
478
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 22/0 : 1[1] -> 2[2] via P2P/CUMEM
479
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 21/0 : 0[0] -> 1[1] via P2P/CUMEM
480
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Channel 23/0 : 1[1] -> 2[2] via P2P/CUMEM
481
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 22/0 : 0[0] -> 1[1] via P2P/CUMEM
482
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Channel 23/0 : 0[0] -> 1[1] via P2P/CUMEM
483
+ t-20260516080640-ks2k6-worker-0:10256:10427 [6] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
484
+ t-20260516080640-ks2k6-worker-0:10257:10430 [7] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
485
+ t-20260516080640-ks2k6-worker-0:10252:10426 [2] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
486
+ t-20260516080640-ks2k6-worker-0:10251:10431 [1] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
487
+ t-20260516080640-ks2k6-worker-0:10255:10433 [5] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
488
+ t-20260516080640-ks2k6-worker-0:10254:10432 [4] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
489
+ t-20260516080640-ks2k6-worker-0:10250:10428 [0] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
490
+ t-20260516080640-ks2k6-worker-0:10253:10429 [3] NCCL INFO Connected all rings, use ring PXN 0 GDR 1
491
+ {
492
+ "device": "cuda:0",
493
+ "rank": 0,
494
+ "world_size": 8,
495
+ "samples": "record_pad_truncate:pad=0:add_eos=0:add_special=0:shuffle_buffer=10000",
496
+ "vocab_size": 32100,
497
+ "tokenizer_vocab_size": 32100,
498
+ "save_dir": "runs/lta_owt_t5record_len1024_elfaligned_dditelf_muon_logitnormal_m1p5_s0p8_none_floor0p0_gbs512_8gpu_5epoch_20260516_000824",
499
+ "batch_size": 32,
500
+ "grad_accum": 2,
501
+ "effective_batch_size": 512,
502
+ "global_batch_size": 512,
503
+ "lr_schedule": "constant_warmup",
504
+ "optimizer": "muon",
505
+ "epochs": 5.0,
506
+ "steps_per_epoch": 15457,
507
+ "total_steps": 77285,
508
+ "warmup_steps": 7729,
509
+ "warmup_epochs": 0.5,
510
+ "min_lr": 0.0,
511
+ "weight_decay": 0.0,
512
+ "output_weight_decay": -1.0,
513
+ "adamw_param_groups": "nanogpt",
514
+ "adam_beta1": 0.9,
515
+ "adam_beta2": 0.999,
516
+ "adam_eps": 1e-08,
517
+ "muon_impl": "optax",
518
+ "muon_momentum": 0.95,
519
+ "muon_ns_steps": 5,
520
+ "muon_update_scale": 1.0,
521
+ "muon_nesterov": true,
522
+ "muon_width_scale": true,
523
+ "muon_effective_nesterov": true,
524
+ "muon_effective_width_scale": true,
525
+ "muon_effective_weight_decay": 0.0,
526
+ "muon_adam_fallback_nesterov": true,
527
+ "muon_adam_fallback_weight_decay": 0.0,
528
+ "ema_decay": 0.9999,
529
+ "ema_start_step": 0,
530
+ "model_type": "ddit_elf",
531
+ "elf_num_time_tokens": 4,
532
+ "elf_num_model_mode_tokens": 0,
533
+ "qk_norm": true,
534
+ "output_bias": false,
535
+ "output_init_std": 0.02,
536
+ "norm_type": "rmsnorm",
537
+ "t_sampling_mode": "logit_normal",
538
+ "t_sampling_power": 1.0,
539
+ "t_sampling_eps": 0.0001,
540
+ "t_sampling_logit_mean": -1.5,
541
+ "t_sampling_logit_std": 0.8,
542
+ "dual_t": true,
543
+ "corrupt_t_mode": "same",
544
+ "corrupt_min_t": 0.0,
545
+ "corrupt_max_t": 1.0,
546
+ "prefix_block_prob": 0.0,
547
+ "prefix_block_len": 128,
548
+ "mask_ratio_floor_schedule": "none",
549
+ "dirichlet_endpoint_mode": "categorical_dual_t",
550
+ "dirichlet_semantic_t_mode": "same",
551
+ "dirichlet_semantic_t_value": 0.0,
552
+ "dirichlet_semantic_t_curve": "linear",
553
+ "dirichlet_semantic_t_power": 1.0,
554
+ "endpoint_sequence_random_prob_alpha": 0.0,
555
+ "categorical_wrong_from_full_vocab": true,
556
+ "categorical_wrong_from_batch_valid_tokens": false,
557
+ "categorical_wrong_basin_token_ids": "",
558
+ "categorical_wrong_basin_prob": 0.0,
559
+ "categorical_wrong_unigram_prob": 0.0,
560
+ "categorical_wrong_uniform_prob": 0.0,
561
+ "categorical_wrong_corpus_unigram_path": "",
562
+ "categorical_wrong_corpus_unigram_alpha": 1.0,
563
+ "categorical_wrong_basin_shared_prob": 0.0,
564
+ "categorical_wrong_unigram_shared_prob": 0.0,
565
+ "mask_mixture_original_prob": 0.0,
566
+ "mask_mixture_lowk_prob": 0.0,
567
+ "mask_mixture_lowcorrupt_prob": 0.0,
568
+ "mask_mixture_block_prob": 0.0,
569
+ "mask_mixture_all_prob": 0.0,
570
+ "mask_mixture_lowk_clean_tokens": "1,2,4,8,16,32,64",
571
+ "mask_mixture_lowcorrupt_tokens": "1,2,4,8,16,32,64",
572
+ "mask_mixture_block_tokens": "64,128",
573
+ "simplex_bridge_sampler": "dirichlet",
574
+ "logistic_normal_sigma_min": 0.18,
575
+ "logistic_normal_sigma_max": 2.2,
576
+ "logistic_normal_tau_min": 0.65,
577
+ "logistic_normal_tau_max": 1.15,
578
+ "torch_compile": false,
579
+ "compile_mode": "max-autotune",
580
+ "state_format": "prob",
581
+ "target_loss": "hard_ce",
582
+ "meanflow_weight": 0.0,
583
+ "rollout_train_prob": 0.0,
584
+ "rollout_train_steps": 1,
585
+ "rollout_train_infer_steps": 64,
586
+ "rollout_train_temp": 1.45,
587
+ "rollout_train_max_gamma": 1.0,
588
+ "rollout_train_corrupt_only": true,
589
+ "rollout_train_samplewise": false,
590
+ "rollout_train_compute_always": false,
591
+ "bridge_noise_init": "logistic_normal",
592
+ "noise_sigma": -1.0,
593
+ "allow_tf32": false,
594
+ "activation_checkpointing": true,
595
+ "activation_checkpoint_interval": 1,
596
+ "activation_checkpoint_scope": "mlp",
597
+ "ddp_static_graph": false,
598
+ "ddp_gradient_as_bucket_view": true,
599
+ "blocking_data_transfer": false,
600
+ "dataloader_prefetch_factor": 4,
601
+ "full_train_stats": false,
602
+ "record_pad_truncate": true,
603
+ "record_add_eos": false,
604
+ "record_add_special_tokens": false,
605
+ "record_pad_token": "pad",
606
+ "record_shuffle_buffer": 10000,
607
+ "wrap": false,
608
+ "wrap_mode": "stream",
609
+ "wrap_record_buffer_size": 200,
610
+ "owt_cached_chunks": false,
611
+ "owt_chunk_cache_dir": "",
612
+ "owt_chunk_cache_rebuild": false,
613
+ "owt_chunk_cache_write_batch": 4096,
614
+ "owt_exact_repeat_per_chunk": 0,
615
+ "online_chunk_shuffle": false,
616
+ "online_chunk_shuffle_buffer": 10000,
617
+ "openwebtext_split": "train_minus_100k",
618
+ "detokenizer": "auto",
619
+ "resolved_detokenizer": null,
620
+ "num_workers": 8,
621
+ "latest_every": 1000,
622
+ "resume_path": ""
623
+ }
624
+ t-20260516080640-ks2k6-worker-0:10250:10958 [0] NCCL INFO NVLS comm 0x9f91be0 headRank 0 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
625
+ t-20260516080640-ks2k6-worker-0:10251:10960 [1] NCCL INFO NVLS comm 0x9a45db0 headRank 1 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
626
+ t-20260516080640-ks2k6-worker-0:10253:10963 [3] NCCL INFO NVLS comm 0xa06a9c0 headRank 3 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
627
+ t-20260516080640-ks2k6-worker-0:10252:10964 [2] NCCL INFO NVLS comm 0xb2c0700 headRank 2 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
628
+ t-20260516080640-ks2k6-worker-0:10256:10965 [6] NCCL INFO NVLS comm 0xb812680 headRank 6 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
629
+ t-20260516080640-ks2k6-worker-0:10255:10966 [5] NCCL INFO NVLS comm 0xa632cd0 headRank 5 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
630
+ t-20260516080640-ks2k6-worker-0:10254:10967 [4] NCCL INFO NVLS comm 0xb506970 headRank 4 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
631
+ t-20260516080640-ks2k6-worker-0:10257:10998 [7] NCCL INFO NVLS comm 0xa6619b0 headRank 7 nHeads 8 buffSize 1048576 nvlsPerRankSize 33554432 nvlsTotalSize 268435456
632
+ step=100 epoch=1/5 epoch_step=100/15457 micro_steps=200 elapsed=209.7s lr=2.613533e-05 loss=10.4988 loss_recon=10.4988 loss_meanflow=0.0000 mean_model_t=0.2081 mean_corrupt_t=0.2081 mean_loss_t_weight=1.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.0001 corrupt_frac=0.5549 acc_corrupt=0.0001 loss_corrupt=10.4988 wrong_frac=0.7929 init_acc_corrupt=0.1138 acc_corrupt_t_0p0_0p2=0.0001 corrupt_frac_t_0p0_0p2=0.5679 acc_corrupt_t_0p2_0p4=0.0001 corrupt_frac_t_0p2_0p4=0.3435 out_w_norm=99.2788 out_g_norm=0.8302 acc_corrupt_t_0p4_0p6=0.0000 corrupt_frac_t_0p4_0p6=0.0860 acc_corrupt_t_0p6_0p8=0.0000 corrupt_frac_t_0p6_0p8=0.0342 acc_corrupt_t_0p8_1p0=0.0000 corrupt_frac_t_0p8_1p0=0.0095 loss_all=10.3770 init_gold_top10=0.2156 init_gold_top100=0.4562
633
+ step=200 epoch=1/5 epoch_step=200/15457 micro_steps=400 elapsed=179.4s lr=5.201190e-05 loss=10.1387 loss_recon=10.1387 loss_meanflow=0.0000 mean_model_t=0.2102 mean_corrupt_t=0.2102 mean_loss_t_weight=1.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.0249 corrupt_frac=0.5476 acc_corrupt=0.0248 loss_corrupt=10.1387 wrong_frac=0.7891 init_acc_corrupt=0.1199 acc_corrupt_t_0p0_0p2=0.0244 corrupt_frac_t_0p0_0p2=0.5602 acc_corrupt_t_0p2_0p4=0.0252 corrupt_frac_t_0p2_0p4=0.3460 acc_corrupt_t_0p4_0p6=0.0264 corrupt_frac_t_0p4_0p6=0.0887 out_w_norm=99.2659 out_g_norm=1.1446 acc_corrupt_t_0p6_0p8=0.0224 corrupt_frac_t_0p6_0p8=0.0361 loss_all=9.9286 init_gold_top10=0.1478 init_gold_top100=0.4570
634
+ step=300 epoch=1/5 epoch_step=300/15457 micro_steps=600 elapsed=179.5s lr=7.788847e-05 loss=9.6553 loss_recon=9.6553 loss_meanflow=0.0000 mean_model_t=0.2087 mean_corrupt_t=0.2087 mean_loss_t_weight=1.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.0436 corrupt_frac=0.5486 acc_corrupt=0.0428 loss_corrupt=9.6553 wrong_frac=0.7920 init_acc_corrupt=0.1149 acc_corrupt_t_0p0_0p2=0.0427 corrupt_frac_t_0p0_0p2=0.5626 acc_corrupt_t_0p2_0p4=0.0429 corrupt_frac_t_0p2_0p4=0.3554 acc_corrupt_t_0p4_0p6=0.0419 corrupt_frac_t_0p4_0p6=0.0764 out_w_norm=99.2536 out_g_norm=1.5325 acc_corrupt_t_0p6_0p8=0.0511 corrupt_frac_t_0p6_0p8=0.0338 acc_corrupt_t_0p8_1p0=0.0702 corrupt_frac_t_0p8_1p0=0.0410 loss_all=9.4007 init_gold_top10=0.1763 init_gold_top100=0.4579
635
+ step=400 epoch=1/5 epoch_step=400/15457 micro_steps=800 elapsed=179.5s lr=1.037650e-04 loss=9.2582 loss_recon=9.2582 loss_meanflow=0.0000 mean_model_t=0.2101 mean_corrupt_t=0.2101 mean_loss_t_weight=1.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.0497 corrupt_frac=0.5498 acc_corrupt=0.0446 loss_corrupt=9.2582 wrong_frac=0.7920 init_acc_corrupt=0.1141 acc_corrupt_t_0p0_0p2=0.0438 corrupt_frac_t_0p0_0p2=0.5615 acc_corrupt_t_0p2_0p4=0.0449 corrupt_frac_t_0p2_0p4=0.3516 acc_corrupt_t_0p4_0p6=0.0475 corrupt_frac_t_0p4_0p6=0.0843 out_w_norm=99.2475 out_g_norm=1.5639 acc_corrupt_t_0p6_0p8=0.0543 corrupt_frac_t_0p6_0p8=0.0315 loss_all=9.0300 init_gold_top10=0.2436 init_gold_top100=0.4551
636
+ step=500 epoch=1/5 epoch_step=500/15457 micro_steps=1000 elapsed=179.3s lr=1.296416e-04 loss=8.9755 loss_recon=8.9755 loss_meanflow=0.0000 mean_model_t=0.2087 mean_corrupt_t=0.2087 mean_loss_t_weight=1.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.0741 corrupt_frac=0.5571 acc_corrupt=0.0502 loss_corrupt=8.9755 wrong_frac=0.7934 init_acc_corrupt=0.1133 acc_corrupt_t_0p0_0p2=0.0456 corrupt_frac_t_0p0_0p2=0.5588 acc_corrupt_t_0p2_0p4=0.0524 corrupt_frac_t_0p2_0p4=0.3629 acc_corrupt_t_0p4_0p6=0.0708 corrupt_frac_t_0p4_0p6=0.0744 out_w_norm=99.2468 out_g_norm=1.4180 acc_corrupt_t_0p6_0p8=0.0897 corrupt_frac_t_0p6_0p8=0.0318 acc_corrupt_t_0p8_1p0=0.1306 corrupt_frac_t_0p8_1p0=0.0262 loss_all=8.7811 init_gold_top10=0.1701 init_gold_top100=0.4774
LTA_openwebtext_dualt/logs/elfaligned_t5record_8gpu/lta_owt_t5record_len1024_elfaligned_dditelf_muon_logitnormal_m1p5_s0p8_none_floor0p0_gbs512_8gpu_5epoch_20260516_011453.log ADDED
The diff for this file is too large to render. See raw diff
 
LTA_openwebtext_dualt/logs/lta_lm1b_classic_dirichlet_len256_gbs512_4gpu_10k_save1k_20260523.watch.pid ADDED
@@ -0,0 +1 @@
 
 
1
+ 994420
LTA_openwebtext_dualt/logs/train_lta_owt_cached_fast10k_4gpu_500step.log ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [launch] method=owt_categorical_fullvocab_c1024_fullycoupled host=di-20260411014000-djqhq time=2026-05-12T16:34:51+00:00
2
+ [launch] cwd=/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt
3
+ [launch] run_name=lta_owt_c1024_gpt2_cached_chunks_len1024_fast10k_4gpu_500step
4
+ [launch] save_dir=runs/lta_owt_c1024_gpt2_cached_chunks_len1024_fast10k_4gpu_500step
5
+ [launch] log_file=logs/lta_owt_c1024_gpt2_cached_chunks_len1024_fast10k_4gpu_500step.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] owt_cached_chunks=1 cache_dir=/e2e-data/evad-tech-vla/wanghan58/data/small_benchmarks/langflow_2604_11748/openwebtext_lta_cached_chunks/gpt2_len1024_train_minus_100k_fast10k
10
+ [launch] nproc_per_node=4 global_batch_size=512 per_gpu_batch_size=32
11
+
12
+ *****************************************
13
+ 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.
14
+ *****************************************
15
+ [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.
16
+ NCCL version 2.25.1+cuda12.8
17
+ [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.
18
+ [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.
19
+ [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.
20
+ {
21
+ "device": "cuda:0",
22
+ "rank": 0,
23
+ "world_size": 4,
24
+ "samples": "owt_cached_chunks:10904",
25
+ "vocab_size": 50257,
26
+ "save_dir": "runs/lta_owt_c1024_gpt2_cached_chunks_len1024_fast10k_4gpu_500step",
27
+ "batch_size": 32,
28
+ "grad_accum": 4,
29
+ "effective_batch_size": 512,
30
+ "global_batch_size": 512,
31
+ "lr_schedule": "constant_warmup",
32
+ "warmup_steps": 50,
33
+ "adam_beta1": 0.9,
34
+ "adam_beta2": 0.999,
35
+ "adam_eps": 1e-08,
36
+ "model_type": "ddit",
37
+ "dual_t": true,
38
+ "corrupt_t_mode": "same",
39
+ "corrupt_min_t": 0.0,
40
+ "corrupt_max_t": 1.0,
41
+ "dirichlet_endpoint_mode": "categorical_dual_t",
42
+ "dirichlet_semantic_t_mode": "same",
43
+ "dirichlet_semantic_t_value": 0.0,
44
+ "categorical_wrong_from_full_vocab": true,
45
+ "simplex_bridge_sampler": "dirichlet",
46
+ "logistic_normal_sigma_min": 0.18,
47
+ "logistic_normal_sigma_max": 2.2,
48
+ "logistic_normal_tau_min": 0.65,
49
+ "logistic_normal_tau_max": 1.15,
50
+ "torch_compile": false,
51
+ "compile_mode": "max-autotune",
52
+ "state_format": "prob",
53
+ "target_loss": "hard_ce",
54
+ "meanflow_weight": 0.0,
55
+ "bridge_noise_init": "logistic_normal",
56
+ "noise_sigma": -1.0,
57
+ "wrap": true,
58
+ "wrap_mode": "stream",
59
+ "wrap_record_buffer_size": 200,
60
+ "owt_cached_chunks": true,
61
+ "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",
62
+ "owt_chunk_cache_rebuild": false,
63
+ "owt_chunk_cache_write_batch": 4096,
64
+ "online_chunk_shuffle": false,
65
+ "online_chunk_shuffle_buffer": 10000,
66
+ "openwebtext_split": "train_minus_100k",
67
+ "detokenizer": "auto",
68
+ "resolved_detokenizer": null,
69
+ "num_workers": 2,
70
+ "latest_every": 50,
71
+ "resume_path": ""
72
+ }
73
+ 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
74
+ 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
75
+ 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
76
+ 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
77
+ [rank0]: Traceback (most recent call last):
78
+ [rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 797, in <module>
79
+ [rank0]: main()
80
+ [rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 693, in main
81
+ [rank0]: bridge = make_bridge(
82
+ [rank0]: ^^^^^^^^^^^^
83
+ [rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 313, in make_bridge
84
+ [rank0]: return make_dirichlet_bridge_batch(
85
+ [rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
86
+ [rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 529, in make_dirichlet_bridge_batch
87
+ [rank0]: state_probs = sample_dirichlet_bridge_simplex(
88
+ [rank0]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
89
+ [rank0]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 263, in sample_dirichlet_bridge_simplex
90
+ [rank0]: sample = sample.clamp_min(eps)
91
+ [rank0]: ^^^^^^^^^^^^^^^^^^^^^
92
+ [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)
93
+ [rank1]: Traceback (most recent call last):
94
+ [rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 797, in <module>
95
+ [rank1]: main()
96
+ [rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 693, in main
97
+ [rank1]: bridge = make_bridge(
98
+ [rank1]: ^^^^^^^^^^^^
99
+ [rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 313, in make_bridge
100
+ [rank1]: return make_dirichlet_bridge_batch(
101
+ [rank1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
102
+ [rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 529, in make_dirichlet_bridge_batch
103
+ [rank1]: state_probs = sample_dirichlet_bridge_simplex(
104
+ [rank1]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
105
+ [rank1]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 263, in sample_dirichlet_bridge_simplex
106
+ [rank1]: sample = sample.clamp_min(eps)
107
+ [rank1]: ^^^^^^^^^^^^^^^^^^^^^
108
+ [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)
109
+ [rank3]: Traceback (most recent call last):
110
+ [rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 797, in <module>
111
+ [rank3]: main()
112
+ [rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 693, in main
113
+ [rank3]: bridge = make_bridge(
114
+ [rank3]: ^^^^^^^^^^^^
115
+ [rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 313, in make_bridge
116
+ [rank3]: return make_dirichlet_bridge_batch(
117
+ [rank3]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
118
+ [rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 529, in make_dirichlet_bridge_batch
119
+ [rank3]: state_probs = sample_dirichlet_bridge_simplex(
120
+ [rank3]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
121
+ [rank3]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 263, in sample_dirichlet_bridge_simplex
122
+ [rank3]: sample = sample.clamp_min(eps)
123
+ [rank3]: ^^^^^^^^^^^^^^^^^^^^^
124
+ [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)
125
+ [rank2]: Traceback (most recent call last):
126
+ [rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 797, in <module>
127
+ [rank2]: main()
128
+ [rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 693, in main
129
+ [rank2]: bridge = make_bridge(
130
+ [rank2]: ^^^^^^^^^^^^
131
+ [rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/train.py", line 313, in make_bridge
132
+ [rank2]: return make_dirichlet_bridge_batch(
133
+ [rank2]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
134
+ [rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 529, in make_dirichlet_bridge_batch
135
+ [rank2]: state_probs = sample_dirichlet_bridge_simplex(
136
+ [rank2]: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
137
+ [rank2]: File "/e2e-data/evad-tech-vla/wanghan58/workspace/LTA_openwebtext_dualt/flowtext_lab/bridges.py", line 263, in sample_dirichlet_bridge_simplex
138
+ [rank2]: sample = sample.clamp_min(eps)
139
+ [rank2]: ^^^^^^^^^^^^^^^^^^^^^
140
+ [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)
141
+ [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())
142
+ W0512 16:40:21.089000 208015 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 208083 closing signal SIGTERM
143
+ W0512 16:40:21.090000 208015 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 208084 closing signal SIGTERM
144
+ W0512 16:40:21.090000 208015 torch/distributed/elastic/multiprocessing/api.py:898] Sending process 208085 closing signal SIGTERM
145
+ 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
146
+ Traceback (most recent call last):
147
+ File "<frozen runpy>", line 198, in _run_module_as_main
148
+ File "<frozen runpy>", line 88, in _run_code
149
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 922, in <module>
150
+ main()
151
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/elastic/multiprocessing/errors/__init__.py", line 355, in wrapper
152
+ return f(*args, **kwargs)
153
+ ^^^^^^^^^^^^^^^^^^
154
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 918, in main
155
+ run(args)
156
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/run.py", line 909, in run
157
+ elastic_launch(
158
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/launcher/api.py", line 139, in __call__
159
+ return launch_agent(self._config, self._entrypoint, list(args))
160
+ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
161
+ File "/usr/local/lib/python3.12/dist-packages/torch/distributed/launcher/api.py", line 270, in launch_agent
162
+ raise ChildFailedError(
163
+ torch.distributed.elastic.multiprocessing.errors.ChildFailedError:
164
+ ============================================================
165
+ train.py FAILED
166
+ ------------------------------------------------------------
167
+ Failures:
168
+ <NO_OTHER_FAILURES>
169
+ ------------------------------------------------------------
170
+ Root Cause (first observed failure):
171
+ [0]:
172
+ time : 2026-05-12_16:40:21
173
+ host : localhost
174
+ rank : 0 (local_rank: 0)
175
+ exitcode : 1 (pid: 208082)
176
+ error_file: <N/A>
177
+ traceback : To enable traceback see: https://pytorch.org/docs/stable/elastic/errors.html
178
+ ============================================================
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/fsspec/implementations/http.py ADDED
@@ -0,0 +1,902 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import asyncio
2
+ import io
3
+ import logging
4
+ import re
5
+ import weakref
6
+ from copy import copy
7
+ from urllib.parse import urlparse
8
+
9
+ import aiohttp
10
+ import yarl
11
+
12
+ from fsspec.asyn import AbstractAsyncStreamedFile, AsyncFileSystem, sync, sync_wrapper
13
+ from fsspec.callbacks import DEFAULT_CALLBACK
14
+ from fsspec.exceptions import FSTimeoutError
15
+ from fsspec.spec import AbstractBufferedFile
16
+ from fsspec.utils import (
17
+ DEFAULT_BLOCK_SIZE,
18
+ glob_translate,
19
+ isfilelike,
20
+ nullcontext,
21
+ tokenize,
22
+ )
23
+
24
+ from ..caching import AllBytes
25
+
26
+ # https://stackoverflow.com/a/15926317/3821154
27
+ ex = re.compile(r"""<(a|A)\s+(?:[^>]*?\s+)?(href|HREF)=["'](?P<url>[^"']+)""")
28
+ ex2 = re.compile(r"""(?P<url>http[s]?://[-a-zA-Z0-9@:%_+.~#?&/=]+)""")
29
+ logger = logging.getLogger("fsspec.http")
30
+
31
+
32
+ async def get_client(**kwargs):
33
+ return aiohttp.ClientSession(**kwargs)
34
+
35
+
36
+ class HTTPFileSystem(AsyncFileSystem):
37
+ """
38
+ Simple File-System for fetching data via HTTP(S)
39
+
40
+ ``ls()`` is implemented by loading the parent page and doing a regex
41
+ match on the result. If simple_link=True, anything of the form
42
+ "http(s)://server.com/stuff?thing=other"; otherwise only links within
43
+ HTML href tags will be used.
44
+
45
+ URLs are passed unfiltered to aiohttp, so all addresses are accessible. Where URLs are
46
+ supplied by a user, the calling application may wish to filter to prevent scanning.
47
+ """
48
+
49
+ protocol = ("http", "https")
50
+ sep = "/"
51
+
52
+ def __init__(
53
+ self,
54
+ simple_links=True,
55
+ block_size=None,
56
+ same_scheme=True,
57
+ size_policy=None,
58
+ cache_type="bytes",
59
+ cache_options=None,
60
+ asynchronous=False,
61
+ loop=None,
62
+ client_kwargs=None,
63
+ get_client=get_client,
64
+ encoded=False,
65
+ **storage_options,
66
+ ):
67
+ """
68
+ NB: if this is called async, you must await set_client
69
+
70
+ Parameters
71
+ ----------
72
+ block_size: int
73
+ Blocks to read bytes; if 0, will default to raw requests file-like
74
+ objects instead of HTTPFile instances
75
+ simple_links: bool
76
+ If True, will consider both HTML <a> tags and anything that looks
77
+ like a URL; if False, will consider only the former.
78
+ same_scheme: True
79
+ When doing ls/glob, if this is True, only consider paths that have
80
+ http/https matching the input URLs.
81
+ size_policy: this argument is deprecated
82
+ client_kwargs: dict
83
+ Passed to aiohttp.ClientSession, see
84
+ https://docs.aiohttp.org/en/stable/client_reference.html
85
+ For example, ``{'auth': aiohttp.BasicAuth('user', 'pass')}``
86
+ get_client: Callable[..., aiohttp.ClientSession]
87
+ A callable, which takes keyword arguments and constructs
88
+ an aiohttp.ClientSession. Its state will be managed by
89
+ the HTTPFileSystem class.
90
+ storage_options: key-value
91
+ Any other parameters passed on to requests
92
+ cache_type, cache_options: defaults used in open()
93
+ """
94
+ super().__init__(self, asynchronous=asynchronous, loop=loop, **storage_options)
95
+ self.block_size = block_size if block_size is not None else DEFAULT_BLOCK_SIZE
96
+ self.simple_links = simple_links
97
+ self.same_schema = same_scheme
98
+ self.cache_type = cache_type
99
+ self.cache_options = cache_options
100
+ self.client_kwargs = client_kwargs or {}
101
+ self.get_client = get_client
102
+ self.encoded = encoded
103
+ self.kwargs = storage_options
104
+ self._session = None
105
+
106
+ # Clean caching-related parameters from `storage_options`
107
+ # before propagating them as `request_options` through `self.kwargs`.
108
+ # TODO: Maybe rename `self.kwargs` to `self.request_options` to make
109
+ # it clearer.
110
+ request_options = copy(storage_options)
111
+ self.use_listings_cache = request_options.pop("use_listings_cache", False)
112
+ request_options.pop("listings_expiry_time", None)
113
+ request_options.pop("max_paths", None)
114
+ request_options.pop("skip_instance_cache", None)
115
+ self.kwargs = request_options
116
+
117
+ @property
118
+ def fsid(self):
119
+ return "http"
120
+
121
+ def encode_url(self, url):
122
+ return yarl.URL(url, encoded=self.encoded)
123
+
124
+ @staticmethod
125
+ def close_session(loop, session):
126
+ if loop is not None and loop.is_running():
127
+ try:
128
+ sync(loop, session.close, timeout=0.1)
129
+ return
130
+ except (TimeoutError, FSTimeoutError, NotImplementedError):
131
+ pass
132
+ connector = getattr(session, "_connector", None)
133
+ if connector is not None:
134
+ # close after loop is dead
135
+ connector._close()
136
+
137
+ async def set_session(self):
138
+ if self._session is None:
139
+ self._session = await self.get_client(loop=self.loop, **self.client_kwargs)
140
+ if not self.asynchronous:
141
+ weakref.finalize(self, self.close_session, self.loop, self._session)
142
+ return self._session
143
+
144
+ @classmethod
145
+ def _strip_protocol(cls, path):
146
+ """For HTTP, we always want to keep the full URL"""
147
+ return path
148
+
149
+ @classmethod
150
+ def _parent(cls, path):
151
+ # override, since _strip_protocol is different for URLs
152
+ par = super()._parent(path)
153
+ if len(par) > 7: # "http://..."
154
+ return par
155
+ return ""
156
+
157
+ async def _ls_real(self, url, detail=True, **kwargs):
158
+ # ignoring URL-encoded arguments
159
+ kw = self.kwargs.copy()
160
+ kw.update(kwargs)
161
+ logger.debug(url)
162
+ session = await self.set_session()
163
+ async with session.get(self.encode_url(url), **self.kwargs) as r:
164
+ self._raise_not_found_for_status(r, url)
165
+
166
+ if "Content-Type" in r.headers:
167
+ mimetype = r.headers["Content-Type"].partition(";")[0]
168
+ else:
169
+ mimetype = None
170
+
171
+ if mimetype in ("text/html", None):
172
+ try:
173
+ text = await r.text(errors="ignore")
174
+ if self.simple_links:
175
+ links = ex2.findall(text) + [u[2] for u in ex.findall(text)]
176
+ else:
177
+ links = [u[2] for u in ex.findall(text)]
178
+ except UnicodeDecodeError:
179
+ links = [] # binary, not HTML
180
+ else:
181
+ links = []
182
+
183
+ out = set()
184
+ parts = urlparse(url)
185
+ for l in links:
186
+ if isinstance(l, tuple):
187
+ l = l[1]
188
+ if l.startswith("/") and len(l) > 1:
189
+ # absolute URL on this server
190
+ l = f"{parts.scheme}://{parts.netloc}{l}"
191
+ if l.startswith("http"):
192
+ if self.same_schema and l.startswith(url.rstrip("/") + "/"):
193
+ out.add(l)
194
+ elif l.replace("https", "http").startswith(
195
+ url.replace("https", "http").rstrip("/") + "/"
196
+ ):
197
+ # allowed to cross http <-> https
198
+ out.add(l)
199
+ else:
200
+ if l not in ["..", "../"]:
201
+ # Ignore FTP-like "parent"
202
+ out.add("/".join([url.rstrip("/"), l.lstrip("/")]))
203
+ if not out and url.endswith("/"):
204
+ out = await self._ls_real(url.rstrip("/"), detail=False)
205
+ if detail:
206
+ return [
207
+ {
208
+ "name": u,
209
+ "size": None,
210
+ "type": "directory" if u.endswith("/") else "file",
211
+ }
212
+ for u in out
213
+ ]
214
+ else:
215
+ return sorted(out)
216
+
217
+ async def _ls(self, url, detail=True, **kwargs):
218
+ if self.use_listings_cache and url in self.dircache:
219
+ out = self.dircache[url]
220
+ else:
221
+ out = await self._ls_real(url, detail=detail, **kwargs)
222
+ self.dircache[url] = out
223
+ return out
224
+
225
+ ls = sync_wrapper(_ls)
226
+
227
+ def _raise_not_found_for_status(self, response, url):
228
+ """
229
+ Raises FileNotFoundError for 404s, otherwise uses raise_for_status.
230
+ """
231
+ if response.status == 404:
232
+ raise FileNotFoundError(url)
233
+ response.raise_for_status()
234
+
235
+ async def _cat_file(self, url, start=None, end=None, **kwargs):
236
+ kw = self.kwargs.copy()
237
+ kw.update(kwargs)
238
+ logger.debug(url)
239
+
240
+ if start is not None or end is not None:
241
+ if start == end:
242
+ return b""
243
+ headers = kw.pop("headers", {}).copy()
244
+
245
+ headers["Range"] = await self._process_limits(url, start, end)
246
+ kw["headers"] = headers
247
+ session = await self.set_session()
248
+ async with session.get(self.encode_url(url), **kw) as r:
249
+ out = await r.read()
250
+ self._raise_not_found_for_status(r, url)
251
+ return out
252
+
253
+ async def _get_file(
254
+ self, rpath, lpath, chunk_size=5 * 2**20, callback=DEFAULT_CALLBACK, **kwargs
255
+ ):
256
+ kw = self.kwargs.copy()
257
+ kw.update(kwargs)
258
+ logger.debug(rpath)
259
+ session = await self.set_session()
260
+ async with session.get(self.encode_url(rpath), **kw) as r:
261
+ try:
262
+ size = int(r.headers["content-length"])
263
+ except (ValueError, KeyError):
264
+ size = None
265
+
266
+ callback.set_size(size)
267
+ self._raise_not_found_for_status(r, rpath)
268
+ if isfilelike(lpath):
269
+ outfile = lpath
270
+ else:
271
+ outfile = open(lpath, "wb") # noqa: ASYNC230
272
+
273
+ try:
274
+ chunk = True
275
+ while chunk:
276
+ chunk = await r.content.read(chunk_size)
277
+ outfile.write(chunk)
278
+ callback.relative_update(len(chunk))
279
+ finally:
280
+ if not isfilelike(lpath):
281
+ outfile.close()
282
+
283
+ async def _put_file(
284
+ self,
285
+ lpath,
286
+ rpath,
287
+ chunk_size=5 * 2**20,
288
+ callback=DEFAULT_CALLBACK,
289
+ method="post",
290
+ mode="overwrite",
291
+ **kwargs,
292
+ ):
293
+ if mode != "overwrite":
294
+ raise NotImplementedError("Exclusive write")
295
+
296
+ async def gen_chunks():
297
+ # Support passing arbitrary file-like objects
298
+ # and use them instead of streams.
299
+ if isinstance(lpath, io.IOBase):
300
+ context = nullcontext(lpath)
301
+ use_seek = False # might not support seeking
302
+ else:
303
+ context = open(lpath, "rb") # noqa: ASYNC230
304
+ use_seek = True
305
+
306
+ with context as f:
307
+ if use_seek:
308
+ callback.set_size(f.seek(0, 2))
309
+ f.seek(0)
310
+ else:
311
+ callback.set_size(getattr(f, "size", None))
312
+
313
+ chunk = f.read(chunk_size)
314
+ while chunk:
315
+ yield chunk
316
+ callback.relative_update(len(chunk))
317
+ chunk = f.read(chunk_size)
318
+
319
+ kw = self.kwargs.copy()
320
+ kw.update(kwargs)
321
+ session = await self.set_session()
322
+
323
+ method = method.lower()
324
+ if method not in ("post", "put"):
325
+ raise ValueError(
326
+ f"method has to be either 'post' or 'put', not: {method!r}"
327
+ )
328
+
329
+ meth = getattr(session, method)
330
+ async with meth(self.encode_url(rpath), data=gen_chunks(), **kw) as resp:
331
+ self._raise_not_found_for_status(resp, rpath)
332
+
333
+ async def _exists(self, path, strict=False, **kwargs):
334
+ kw = self.kwargs.copy()
335
+ kw.update(kwargs)
336
+ try:
337
+ logger.debug(path)
338
+ session = await self.set_session()
339
+ r = await session.get(self.encode_url(path), **kw)
340
+ async with r:
341
+ if strict:
342
+ self._raise_not_found_for_status(r, path)
343
+ return r.status < 400
344
+ except FileNotFoundError:
345
+ return False
346
+ except aiohttp.ClientError:
347
+ if strict:
348
+ raise
349
+ return False
350
+
351
+ async def _isfile(self, path, **kwargs):
352
+ return await self._exists(path, **kwargs)
353
+
354
+ def _open(
355
+ self,
356
+ path,
357
+ mode="rb",
358
+ block_size=None,
359
+ autocommit=None, # XXX: This differs from the base class.
360
+ cache_type=None,
361
+ cache_options=None,
362
+ size=None,
363
+ **kwargs,
364
+ ):
365
+ """Make a file-like object
366
+
367
+ Parameters
368
+ ----------
369
+ path: str
370
+ Full URL with protocol
371
+ mode: string
372
+ must be "rb"
373
+ block_size: int or None
374
+ Bytes to download in one request; use instance value if None. If
375
+ zero, will return a streaming Requests file-like instance.
376
+ kwargs: key-value
377
+ Any other parameters, passed to requests calls
378
+ """
379
+ if mode != "rb":
380
+ raise NotImplementedError
381
+ block_size = block_size if block_size is not None else self.block_size
382
+ kw = self.kwargs.copy()
383
+ kw["asynchronous"] = self.asynchronous
384
+ kw.update(kwargs)
385
+ info = {}
386
+ size = size or info.update(self.info(path, **kwargs)) or info["size"]
387
+ session = sync(self.loop, self.set_session)
388
+ if block_size and size and info.get("partial", True):
389
+ return HTTPFile(
390
+ self,
391
+ path,
392
+ session=session,
393
+ block_size=block_size,
394
+ mode=mode,
395
+ size=size,
396
+ cache_type=cache_type or self.cache_type,
397
+ cache_options=cache_options or self.cache_options,
398
+ loop=self.loop,
399
+ **kw,
400
+ )
401
+ else:
402
+ return HTTPStreamFile(
403
+ self,
404
+ path,
405
+ mode=mode,
406
+ loop=self.loop,
407
+ session=session,
408
+ **kw,
409
+ )
410
+
411
+ async def open_async(self, path, mode="rb", size=None, **kwargs):
412
+ session = await self.set_session()
413
+ if size is None:
414
+ try:
415
+ size = (await self._info(path, **kwargs))["size"]
416
+ except FileNotFoundError:
417
+ pass
418
+ return AsyncStreamFile(
419
+ self,
420
+ path,
421
+ loop=self.loop,
422
+ session=session,
423
+ size=size,
424
+ **kwargs,
425
+ )
426
+
427
+ def ukey(self, url):
428
+ """Unique identifier; assume HTTP files are static, unchanging"""
429
+ return tokenize(url, self.kwargs, self.protocol)
430
+
431
+ async def _info(self, url, **kwargs):
432
+ """Get info of URL
433
+
434
+ Tries to access location via HEAD, and then GET methods, but does
435
+ not fetch the data.
436
+
437
+ It is possible that the server does not supply any size information, in
438
+ which case size will be given as None (and certain operations on the
439
+ corresponding file will not work).
440
+ """
441
+ info = {}
442
+ session = await self.set_session()
443
+
444
+ for policy in ["head", "get"]:
445
+ try:
446
+ info.update(
447
+ await _file_info(
448
+ self.encode_url(url),
449
+ size_policy=policy,
450
+ session=session,
451
+ **self.kwargs,
452
+ **kwargs,
453
+ )
454
+ )
455
+ if info.get("size") is not None:
456
+ break
457
+ except Exception as exc:
458
+ if policy == "get":
459
+ # If get failed, then raise a FileNotFoundError
460
+ raise FileNotFoundError(url) from exc
461
+ logger.debug("", exc_info=exc)
462
+
463
+ return {"name": url, "size": None, **info, "type": "file"}
464
+
465
+ async def _glob(self, path, maxdepth=None, **kwargs):
466
+ """
467
+ Find files by glob-matching.
468
+
469
+ This implementation is idntical to the one in AbstractFileSystem,
470
+ but "?" is not considered as a character for globbing, because it is
471
+ so common in URLs, often identifying the "query" part.
472
+ """
473
+ if maxdepth is not None and maxdepth < 1:
474
+ raise ValueError("maxdepth must be at least 1")
475
+ import re
476
+
477
+ ends_with_slash = path.endswith("/") # _strip_protocol strips trailing slash
478
+ path = self._strip_protocol(path)
479
+ append_slash_to_dirname = ends_with_slash or path.endswith(("/**", "/*"))
480
+ idx_star = path.find("*") if path.find("*") >= 0 else len(path)
481
+ idx_brace = path.find("[") if path.find("[") >= 0 else len(path)
482
+
483
+ min_idx = min(idx_star, idx_brace)
484
+
485
+ detail = kwargs.pop("detail", False)
486
+
487
+ if not has_magic(path):
488
+ if await self._exists(path, **kwargs):
489
+ if not detail:
490
+ return [path]
491
+ else:
492
+ return {path: await self._info(path, **kwargs)}
493
+ else:
494
+ if not detail:
495
+ return [] # glob of non-existent returns empty
496
+ else:
497
+ return {}
498
+ elif "/" in path[:min_idx]:
499
+ min_idx = path[:min_idx].rindex("/")
500
+ root = path[: min_idx + 1]
501
+ depth = path[min_idx + 1 :].count("/") + 1
502
+ else:
503
+ root = ""
504
+ depth = path[min_idx + 1 :].count("/") + 1
505
+
506
+ if "**" in path:
507
+ if maxdepth is not None:
508
+ idx_double_stars = path.find("**")
509
+ depth_double_stars = path[idx_double_stars:].count("/") + 1
510
+ depth = depth - depth_double_stars + maxdepth
511
+ else:
512
+ depth = None
513
+
514
+ allpaths = await self._find(
515
+ root, maxdepth=depth, withdirs=True, detail=True, **kwargs
516
+ )
517
+
518
+ pattern = glob_translate(path + ("/" if ends_with_slash else ""))
519
+ pattern = re.compile(pattern)
520
+
521
+ out = {
522
+ (
523
+ p.rstrip("/")
524
+ if not append_slash_to_dirname
525
+ and info["type"] == "directory"
526
+ and p.endswith("/")
527
+ else p
528
+ ): info
529
+ for p, info in sorted(allpaths.items())
530
+ if pattern.match(p.rstrip("/"))
531
+ }
532
+
533
+ if detail:
534
+ return out
535
+ else:
536
+ return list(out)
537
+
538
+ async def _isdir(self, path):
539
+ # override, since all URLs are (also) files
540
+ try:
541
+ return bool(await self._ls(path))
542
+ except (FileNotFoundError, ValueError):
543
+ return False
544
+
545
+ async def _pipe_file(self, path, value, mode="overwrite", **kwargs):
546
+ """
547
+ Write bytes to a remote file over HTTP.
548
+
549
+ Parameters
550
+ ----------
551
+ path : str
552
+ Target URL where the data should be written
553
+ value : bytes
554
+ Data to be written
555
+ mode : str
556
+ How to write to the file - 'overwrite' or 'append'
557
+ **kwargs : dict
558
+ Additional parameters to pass to the HTTP request
559
+ """
560
+ url = self._strip_protocol(path)
561
+ headers = kwargs.pop("headers", {})
562
+ headers["Content-Length"] = str(len(value))
563
+
564
+ session = await self.set_session()
565
+
566
+ async with session.put(
567
+ self.encode_url(url), data=value, headers=headers, **kwargs
568
+ ) as r:
569
+ r.raise_for_status()
570
+
571
+
572
+ class HTTPFile(AbstractBufferedFile):
573
+ """
574
+ A file-like object pointing to a remote HTTP(S) resource
575
+
576
+ Supports only reading, with read-ahead of a predetermined block-size.
577
+
578
+ In the case that the server does not supply the filesize, only reading of
579
+ the complete file in one go is supported.
580
+
581
+ Parameters
582
+ ----------
583
+ url: str
584
+ Full URL of the remote resource, including the protocol
585
+ session: aiohttp.ClientSession or None
586
+ All calls will be made within this session, to avoid restarting
587
+ connections where the server allows this
588
+ block_size: int or None
589
+ The amount of read-ahead to do, in bytes. Default is 5MB, or the value
590
+ configured for the FileSystem creating this file
591
+ size: None or int
592
+ If given, this is the size of the file in bytes, and we don't attempt
593
+ to call the server to find the value.
594
+ kwargs: all other key-values are passed to requests calls.
595
+ """
596
+
597
+ def __init__(
598
+ self,
599
+ fs,
600
+ url,
601
+ session=None,
602
+ block_size=None,
603
+ mode="rb",
604
+ cache_type="bytes",
605
+ cache_options=None,
606
+ size=None,
607
+ loop=None,
608
+ asynchronous=False,
609
+ **kwargs,
610
+ ):
611
+ if mode != "rb":
612
+ raise NotImplementedError("File mode not supported")
613
+ self.asynchronous = asynchronous
614
+ self.loop = loop
615
+ self.url = url
616
+ self.session = session
617
+ self.details = {"name": url, "size": size, "type": "file"}
618
+ super().__init__(
619
+ fs=fs,
620
+ path=url,
621
+ mode=mode,
622
+ block_size=block_size,
623
+ cache_type=cache_type,
624
+ cache_options=cache_options,
625
+ **kwargs,
626
+ )
627
+
628
+ def read(self, length=-1):
629
+ """Read bytes from file
630
+
631
+ Parameters
632
+ ----------
633
+ length: int
634
+ Read up to this many bytes. If negative, read all content to end of
635
+ file. If the server has not supplied the filesize, attempting to
636
+ read only part of the data will raise a ValueError.
637
+ """
638
+ if (
639
+ (length < 0 and self.loc == 0) # explicit read all
640
+ # but not when the size is known and fits into a block anyways
641
+ and not (self.size is not None and self.size <= self.blocksize)
642
+ ):
643
+ self._fetch_all()
644
+ if self.size is None:
645
+ if length < 0:
646
+ self._fetch_all()
647
+ else:
648
+ length = min(self.size - self.loc, length)
649
+ return super().read(length)
650
+
651
+ async def async_fetch_all(self):
652
+ """Read whole file in one shot, without caching
653
+
654
+ This is only called when position is still at zero,
655
+ and read() is called without a byte-count.
656
+ """
657
+ logger.debug(f"Fetch all for {self}")
658
+ if not isinstance(self.cache, AllBytes):
659
+ r = await self.session.get(self.fs.encode_url(self.url), **self.kwargs)
660
+ async with r:
661
+ r.raise_for_status()
662
+ out = await r.read()
663
+ self.cache = AllBytes(
664
+ size=len(out), fetcher=None, blocksize=None, data=out
665
+ )
666
+ self.size = len(out)
667
+
668
+ _fetch_all = sync_wrapper(async_fetch_all)
669
+
670
+ def _parse_content_range(self, headers):
671
+ """Parse the Content-Range header"""
672
+ s = headers.get("Content-Range", "")
673
+ m = re.match(r"bytes (\d+-\d+|\*)/(\d+|\*)", s)
674
+ if not m:
675
+ return None, None, None
676
+
677
+ if m[1] == "*":
678
+ start = end = None
679
+ else:
680
+ start, end = [int(x) for x in m[1].split("-")]
681
+ total = None if m[2] == "*" else int(m[2])
682
+ return start, end, total
683
+
684
+ async def async_fetch_range(self, start, end):
685
+ """Download a block of data
686
+
687
+ The expectation is that the server returns only the requested bytes,
688
+ with HTTP code 206. If this is not the case, we first check the headers,
689
+ and then stream the output - if the data size is bigger than we
690
+ requested, an exception is raised.
691
+ """
692
+ logger.debug(f"Fetch range for {self}: {start}-{end}")
693
+ kwargs = self.kwargs.copy()
694
+ headers = kwargs.pop("headers", {}).copy()
695
+ headers["Range"] = f"bytes={start}-{end - 1}"
696
+ logger.debug(f"{self.url} : {headers['Range']}")
697
+ r = await self.session.get(
698
+ self.fs.encode_url(self.url), headers=headers, **kwargs
699
+ )
700
+ async with r:
701
+ if r.status == 416:
702
+ # range request outside file
703
+ return b""
704
+ r.raise_for_status()
705
+
706
+ # If the server has handled the range request, it should reply
707
+ # with status 206 (partial content). But we'll guess that a suitable
708
+ # Content-Range header or a Content-Length no more than the
709
+ # requested range also mean we have got the desired range.
710
+ response_is_range = (
711
+ r.status == 206
712
+ or self._parse_content_range(r.headers)[0] == start
713
+ or int(r.headers.get("Content-Length", end + 1)) <= end - start
714
+ )
715
+
716
+ if response_is_range:
717
+ # partial content, as expected
718
+ out = await r.read()
719
+ elif start > 0:
720
+ raise ValueError(
721
+ "The HTTP server doesn't appear to support range requests. "
722
+ "Only reading this file from the beginning is supported. "
723
+ "Open with block_size=0 for a streaming file interface."
724
+ )
725
+ else:
726
+ # Response is not a range, but we want the start of the file,
727
+ # so we can read the required amount anyway.
728
+ cl = 0
729
+ out = []
730
+ while True:
731
+ chunk = await r.content.read(2**20)
732
+ # data size unknown, let's read until we have enough
733
+ if chunk:
734
+ out.append(chunk)
735
+ cl += len(chunk)
736
+ if cl > end - start:
737
+ break
738
+ else:
739
+ break
740
+ out = b"".join(out)[: end - start]
741
+ return out
742
+
743
+ _fetch_range = sync_wrapper(async_fetch_range)
744
+
745
+
746
+ magic_check = re.compile("([*[])")
747
+
748
+
749
+ def has_magic(s):
750
+ match = magic_check.search(s)
751
+ return match is not None
752
+
753
+
754
+ class HTTPStreamFile(AbstractBufferedFile):
755
+ def __init__(self, fs, url, mode="rb", loop=None, session=None, **kwargs):
756
+ self.asynchronous = kwargs.pop("asynchronous", False)
757
+ self.url = url
758
+ self.loop = loop
759
+ self.session = session
760
+ if mode != "rb":
761
+ raise ValueError
762
+ self.details = {"name": url, "size": None}
763
+ super().__init__(fs=fs, path=url, mode=mode, cache_type="none", **kwargs)
764
+
765
+ async def cor():
766
+ r = await self.session.get(self.fs.encode_url(url), **kwargs).__aenter__()
767
+ self.fs._raise_not_found_for_status(r, url)
768
+ return r
769
+
770
+ self.r = sync(self.loop, cor)
771
+ self.loop = fs.loop
772
+
773
+ def seek(self, loc, whence=0):
774
+ if loc == 0 and whence == 1:
775
+ return
776
+ if loc == self.loc and whence == 0:
777
+ return
778
+ raise ValueError("Cannot seek streaming HTTP file")
779
+
780
+ async def _read(self, num=-1):
781
+ out = await self.r.content.read(num)
782
+ self.loc += len(out)
783
+ return out
784
+
785
+ read = sync_wrapper(_read)
786
+
787
+ async def _close(self):
788
+ self.r.close()
789
+
790
+ def close(self):
791
+ asyncio.run_coroutine_threadsafe(self._close(), self.loop)
792
+ super().close()
793
+
794
+
795
+ class AsyncStreamFile(AbstractAsyncStreamedFile):
796
+ def __init__(
797
+ self, fs, url, mode="rb", loop=None, session=None, size=None, **kwargs
798
+ ):
799
+ self.url = url
800
+ self.session = session
801
+ self.r = None
802
+ if mode != "rb":
803
+ raise ValueError
804
+ self.details = {"name": url, "size": None}
805
+ self.kwargs = kwargs
806
+ super().__init__(fs=fs, path=url, mode=mode, cache_type="none")
807
+ self.size = size
808
+
809
+ async def read(self, num=-1):
810
+ if self.r is None:
811
+ r = await self.session.get(
812
+ self.fs.encode_url(self.url), **self.kwargs
813
+ ).__aenter__()
814
+ self.fs._raise_not_found_for_status(r, self.url)
815
+ self.r = r
816
+ out = await self.r.content.read(num)
817
+ self.loc += len(out)
818
+ return out
819
+
820
+ async def close(self):
821
+ if self.r is not None:
822
+ self.r.close()
823
+ self.r = None
824
+ await super().close()
825
+
826
+
827
+ async def get_range(session, url, start, end, file=None, **kwargs):
828
+ # explicit get a range when we know it must be safe
829
+ kwargs = kwargs.copy()
830
+ headers = kwargs.pop("headers", {}).copy()
831
+ headers["Range"] = f"bytes={start}-{end - 1}"
832
+ r = await session.get(url, headers=headers, **kwargs)
833
+ r.raise_for_status()
834
+ async with r:
835
+ out = await r.read()
836
+ if file:
837
+ with open(file, "r+b") as f: # noqa: ASYNC230
838
+ f.seek(start)
839
+ f.write(out)
840
+ else:
841
+ return out
842
+
843
+
844
+ async def _file_info(url, session, size_policy="head", **kwargs):
845
+ """Call HEAD on the server to get details about the file (size/checksum etc.)
846
+
847
+ Default operation is to explicitly allow redirects and use encoding
848
+ 'identity' (no compression) to get the true size of the target.
849
+ """
850
+ logger.debug("Retrieve file size for %s", url)
851
+ kwargs = kwargs.copy()
852
+ ar = kwargs.pop("allow_redirects", True)
853
+ head = kwargs.get("headers", {}).copy()
854
+ head["Accept-Encoding"] = "identity"
855
+ kwargs["headers"] = head
856
+
857
+ info = {}
858
+ if size_policy == "head":
859
+ r = await session.head(url, allow_redirects=ar, **kwargs)
860
+ elif size_policy == "get":
861
+ r = await session.get(url, allow_redirects=ar, **kwargs)
862
+ else:
863
+ raise TypeError(f'size_policy must be "head" or "get", got {size_policy}')
864
+ async with r:
865
+ r.raise_for_status()
866
+
867
+ if "Content-Length" in r.headers:
868
+ # Some servers may choose to ignore Accept-Encoding and return
869
+ # compressed content, in which case the returned size is unreliable.
870
+ if "Content-Encoding" not in r.headers or r.headers["Content-Encoding"] in [
871
+ "identity",
872
+ "",
873
+ ]:
874
+ info["size"] = int(r.headers["Content-Length"])
875
+ elif "Content-Range" in r.headers:
876
+ info["size"] = int(r.headers["Content-Range"].split("/")[1])
877
+
878
+ if "Content-Type" in r.headers:
879
+ info["mimetype"] = r.headers["Content-Type"].partition(";")[0]
880
+
881
+ if r.headers.get("Accept-Ranges") == "none":
882
+ # Some servers may explicitly discourage partial content requests, but
883
+ # the lack of "Accept-Ranges" does not always indicate they would fail
884
+ info["partial"] = False
885
+
886
+ info["url"] = str(r.url)
887
+
888
+ for checksum_field in ["ETag", "Content-MD5", "Digest", "Last-Modified"]:
889
+ if r.headers.get(checksum_field):
890
+ info[checksum_field] = r.headers[checksum_field]
891
+
892
+ return info
893
+
894
+
895
+ async def _file_size(url, session=None, *args, **kwargs):
896
+ if session is None:
897
+ session = await get_client()
898
+ info = await _file_info(url, session=session, *args, **kwargs)
899
+ return info.get("size")
900
+
901
+
902
+ file_size = sync_wrapper(_file_size)
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/fsspec/implementations/http_sync.py ADDED
@@ -0,0 +1,937 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """This file is largely copied from http.py"""
2
+
3
+ import io
4
+ import logging
5
+ import re
6
+ import urllib.error
7
+ import urllib.parse
8
+ from copy import copy
9
+ from json import dumps, loads
10
+ from urllib.parse import urlparse
11
+
12
+ try:
13
+ import yarl
14
+ except (ImportError, ModuleNotFoundError, OSError):
15
+ yarl = False
16
+
17
+ from fsspec.callbacks import _DEFAULT_CALLBACK
18
+ from fsspec.registry import register_implementation
19
+ from fsspec.spec import AbstractBufferedFile, AbstractFileSystem
20
+ from fsspec.utils import DEFAULT_BLOCK_SIZE, isfilelike, nullcontext, tokenize
21
+
22
+ from ..caching import AllBytes
23
+
24
+ # https://stackoverflow.com/a/15926317/3821154
25
+ ex = re.compile(r"""<(a|A)\s+(?:[^>]*?\s+)?(href|HREF)=["'](?P<url>[^"']+)""")
26
+ ex2 = re.compile(r"""(?P<url>http[s]?://[-a-zA-Z0-9@:%_+.~#?&/=]+)""")
27
+ logger = logging.getLogger("fsspec.http")
28
+
29
+
30
+ class JsHttpException(urllib.error.HTTPError): ...
31
+
32
+
33
+ class StreamIO(io.BytesIO):
34
+ # fake class, so you can set attributes on it
35
+ # will eventually actually stream
36
+ ...
37
+
38
+
39
+ class ResponseProxy:
40
+ """Looks like a requests response"""
41
+
42
+ def __init__(self, req, stream=False):
43
+ self.request = req
44
+ self.stream = stream
45
+ self._data = None
46
+ self._headers = None
47
+
48
+ @property
49
+ def raw(self):
50
+ if self._data is None:
51
+ b = self.request.response.to_bytes()
52
+ if self.stream:
53
+ self._data = StreamIO(b)
54
+ else:
55
+ self._data = b
56
+ return self._data
57
+
58
+ def close(self):
59
+ if hasattr(self, "_data"):
60
+ del self._data
61
+
62
+ @property
63
+ def headers(self):
64
+ if self._headers is None:
65
+ self._headers = dict(
66
+ [
67
+ _.split(": ")
68
+ for _ in self.request.getAllResponseHeaders().strip().split("\r\n")
69
+ ]
70
+ )
71
+ return self._headers
72
+
73
+ @property
74
+ def status_code(self):
75
+ return int(self.request.status)
76
+
77
+ def raise_for_status(self):
78
+ if not self.ok:
79
+ raise JsHttpException(
80
+ self.url, self.status_code, self.reason, self.headers, None
81
+ )
82
+
83
+ def iter_content(self, chunksize, *_, **__):
84
+ while True:
85
+ out = self.raw.read(chunksize)
86
+ if out:
87
+ yield out
88
+ else:
89
+ break
90
+
91
+ @property
92
+ def reason(self):
93
+ return self.request.statusText
94
+
95
+ @property
96
+ def ok(self):
97
+ return self.status_code < 400
98
+
99
+ @property
100
+ def url(self):
101
+ return self.request.response.responseURL
102
+
103
+ @property
104
+ def text(self):
105
+ # TODO: encoding from headers
106
+ return self.content.decode()
107
+
108
+ @property
109
+ def content(self):
110
+ self.stream = False
111
+ return self.raw
112
+
113
+ def json(self):
114
+ return loads(self.text)
115
+
116
+
117
+ class RequestsSessionShim:
118
+ def __init__(self):
119
+ self.headers = {}
120
+
121
+ def request(
122
+ self,
123
+ method,
124
+ url,
125
+ params=None,
126
+ data=None,
127
+ headers=None,
128
+ cookies=None,
129
+ files=None,
130
+ auth=None,
131
+ timeout=None,
132
+ allow_redirects=None,
133
+ proxies=None,
134
+ hooks=None,
135
+ stream=None,
136
+ verify=None,
137
+ cert=None,
138
+ json=None,
139
+ ):
140
+ from js import Blob, XMLHttpRequest
141
+
142
+ logger.debug("JS request: %s %s", method, url)
143
+
144
+ if cert or verify or proxies or files or cookies or hooks:
145
+ raise NotImplementedError
146
+ if data and json:
147
+ raise ValueError("Use json= or data=, not both")
148
+ req = XMLHttpRequest.new()
149
+ extra = auth if auth else ()
150
+ if params:
151
+ url = f"{url}?{urllib.parse.urlencode(params)}"
152
+ req.open(method, url, False, *extra)
153
+ if timeout:
154
+ req.timeout = timeout
155
+ if headers:
156
+ for k, v in headers.items():
157
+ req.setRequestHeader(k, v)
158
+
159
+ req.setRequestHeader("Accept", "application/octet-stream")
160
+ req.responseType = "arraybuffer"
161
+ if json:
162
+ blob = Blob.new([dumps(data)], {type: "application/json"})
163
+ req.send(blob)
164
+ elif data:
165
+ if isinstance(data, io.IOBase):
166
+ data = data.read()
167
+ blob = Blob.new([data], {type: "application/octet-stream"})
168
+ req.send(blob)
169
+ else:
170
+ req.send(None)
171
+ return ResponseProxy(req, stream=stream)
172
+
173
+ def get(self, url, **kwargs):
174
+ return self.request("GET", url, **kwargs)
175
+
176
+ def head(self, url, **kwargs):
177
+ return self.request("HEAD", url, **kwargs)
178
+
179
+ def post(self, url, **kwargs):
180
+ return self.request("POST}", url, **kwargs)
181
+
182
+ def put(self, url, **kwargs):
183
+ return self.request("PUT", url, **kwargs)
184
+
185
+ def patch(self, url, **kwargs):
186
+ return self.request("PATCH", url, **kwargs)
187
+
188
+ def delete(self, url, **kwargs):
189
+ return self.request("DELETE", url, **kwargs)
190
+
191
+
192
+ class HTTPFileSystem(AbstractFileSystem):
193
+ """
194
+ Simple File-System for fetching data via HTTP(S)
195
+
196
+ This is the BLOCKING version of the normal HTTPFileSystem. It uses
197
+ requests in normal python and the JS runtime in pyodide.
198
+
199
+ ***This implementation is extremely experimental, do not use unless
200
+ you are testing pyodide/pyscript integration***
201
+ """
202
+
203
+ protocol = ("http", "https", "sync-http", "sync-https")
204
+ sep = "/"
205
+
206
+ def __init__(
207
+ self,
208
+ simple_links=True,
209
+ block_size=None,
210
+ same_scheme=True,
211
+ cache_type="readahead",
212
+ cache_options=None,
213
+ client_kwargs=None,
214
+ encoded=False,
215
+ **storage_options,
216
+ ):
217
+ """
218
+
219
+ Parameters
220
+ ----------
221
+ block_size: int
222
+ Blocks to read bytes; if 0, will default to raw requests file-like
223
+ objects instead of HTTPFile instances
224
+ simple_links: bool
225
+ If True, will consider both HTML <a> tags and anything that looks
226
+ like a URL; if False, will consider only the former.
227
+ same_scheme: True
228
+ When doing ls/glob, if this is True, only consider paths that have
229
+ http/https matching the input URLs.
230
+ size_policy: this argument is deprecated
231
+ client_kwargs: dict
232
+ Passed to aiohttp.ClientSession, see
233
+ https://docs.aiohttp.org/en/stable/client_reference.html
234
+ For example, ``{'auth': aiohttp.BasicAuth('user', 'pass')}``
235
+ storage_options: key-value
236
+ Any other parameters passed on to requests
237
+ cache_type, cache_options: defaults used in open
238
+ """
239
+ super().__init__(self, **storage_options)
240
+ self.block_size = block_size if block_size is not None else DEFAULT_BLOCK_SIZE
241
+ self.simple_links = simple_links
242
+ self.same_schema = same_scheme
243
+ self.cache_type = cache_type
244
+ self.cache_options = cache_options
245
+ self.client_kwargs = client_kwargs or {}
246
+ self.encoded = encoded
247
+ self.kwargs = storage_options
248
+
249
+ try:
250
+ import js # noqa: F401
251
+
252
+ logger.debug("Starting JS session")
253
+ self.session = RequestsSessionShim()
254
+ self.js = True
255
+ except Exception as e:
256
+ import requests
257
+
258
+ logger.debug("Starting cpython session because of: %s", e)
259
+ self.session = requests.Session(**(client_kwargs or {}))
260
+ self.js = False
261
+
262
+ request_options = copy(storage_options)
263
+ self.use_listings_cache = request_options.pop("use_listings_cache", False)
264
+ request_options.pop("listings_expiry_time", None)
265
+ request_options.pop("max_paths", None)
266
+ request_options.pop("skip_instance_cache", None)
267
+ self.kwargs = request_options
268
+
269
+ @property
270
+ def fsid(self):
271
+ return "sync-http"
272
+
273
+ def encode_url(self, url):
274
+ if yarl:
275
+ return yarl.URL(url, encoded=self.encoded)
276
+ return url
277
+
278
+ @classmethod
279
+ def _strip_protocol(cls, path: str) -> str:
280
+ """For HTTP, we always want to keep the full URL"""
281
+ path = path.replace("sync-http://", "http://").replace(
282
+ "sync-https://", "https://"
283
+ )
284
+ return path
285
+
286
+ @classmethod
287
+ def _parent(cls, path):
288
+ # override, since _strip_protocol is different for URLs
289
+ par = super()._parent(path)
290
+ if len(par) > 7: # "http://..."
291
+ return par
292
+ return ""
293
+
294
+ def _ls_real(self, url, detail=True, **kwargs):
295
+ # ignoring URL-encoded arguments
296
+ kw = self.kwargs.copy()
297
+ kw.update(kwargs)
298
+ logger.debug(url)
299
+ r = self.session.get(self.encode_url(url), **self.kwargs)
300
+ self._raise_not_found_for_status(r, url)
301
+ text = r.text
302
+ if self.simple_links:
303
+ links = ex2.findall(text) + [u[2] for u in ex.findall(text)]
304
+ else:
305
+ links = [u[2] for u in ex.findall(text)]
306
+ out = set()
307
+ parts = urlparse(url)
308
+ for l in links:
309
+ if isinstance(l, tuple):
310
+ l = l[1]
311
+ if l.startswith("/") and len(l) > 1:
312
+ # absolute URL on this server
313
+ l = parts.scheme + "://" + parts.netloc + l
314
+ if l.startswith("http"):
315
+ if self.same_schema and l.startswith(url.rstrip("/") + "/"):
316
+ out.add(l)
317
+ elif l.replace("https", "http").startswith(
318
+ url.replace("https", "http").rstrip("/") + "/"
319
+ ):
320
+ # allowed to cross http <-> https
321
+ out.add(l)
322
+ else:
323
+ if l not in ["..", "../"]:
324
+ # Ignore FTP-like "parent"
325
+ out.add("/".join([url.rstrip("/"), l.lstrip("/")]))
326
+ if not out and url.endswith("/"):
327
+ out = self._ls_real(url.rstrip("/"), detail=False)
328
+ if detail:
329
+ return [
330
+ {
331
+ "name": u,
332
+ "size": None,
333
+ "type": "directory" if u.endswith("/") else "file",
334
+ }
335
+ for u in out
336
+ ]
337
+ else:
338
+ return sorted(out)
339
+
340
+ def ls(self, url, detail=True, **kwargs):
341
+ if self.use_listings_cache and url in self.dircache:
342
+ out = self.dircache[url]
343
+ else:
344
+ out = self._ls_real(url, detail=detail, **kwargs)
345
+ self.dircache[url] = out
346
+ return out
347
+
348
+ def _raise_not_found_for_status(self, response, url):
349
+ """
350
+ Raises FileNotFoundError for 404s, otherwise uses raise_for_status.
351
+ """
352
+ if response.status_code == 404:
353
+ raise FileNotFoundError(url)
354
+ response.raise_for_status()
355
+
356
+ def cat_file(self, url, start=None, end=None, **kwargs):
357
+ kw = self.kwargs.copy()
358
+ kw.update(kwargs)
359
+ logger.debug(url)
360
+
361
+ if start is not None or end is not None:
362
+ if start == end:
363
+ return b""
364
+ headers = kw.pop("headers", {}).copy()
365
+
366
+ headers["Range"] = self._process_limits(url, start, end)
367
+ kw["headers"] = headers
368
+ r = self.session.get(self.encode_url(url), **kw)
369
+ self._raise_not_found_for_status(r, url)
370
+ return r.content
371
+
372
+ def get_file(
373
+ self, rpath, lpath, chunk_size=5 * 2**20, callback=_DEFAULT_CALLBACK, **kwargs
374
+ ):
375
+ kw = self.kwargs.copy()
376
+ kw.update(kwargs)
377
+ logger.debug(rpath)
378
+ r = self.session.get(self.encode_url(rpath), **kw)
379
+ try:
380
+ size = int(
381
+ r.headers.get("content-length", None)
382
+ or r.headers.get("Content-Length", None)
383
+ )
384
+ except (ValueError, KeyError, TypeError):
385
+ size = None
386
+
387
+ callback.set_size(size)
388
+ self._raise_not_found_for_status(r, rpath)
389
+ if not isfilelike(lpath):
390
+ lpath = open(lpath, "wb")
391
+ for chunk in r.iter_content(chunk_size, decode_unicode=False):
392
+ lpath.write(chunk)
393
+ callback.relative_update(len(chunk))
394
+
395
+ def put_file(
396
+ self,
397
+ lpath,
398
+ rpath,
399
+ chunk_size=5 * 2**20,
400
+ callback=_DEFAULT_CALLBACK,
401
+ method="post",
402
+ **kwargs,
403
+ ):
404
+ def gen_chunks():
405
+ # Support passing arbitrary file-like objects
406
+ # and use them instead of streams.
407
+ if isinstance(lpath, io.IOBase):
408
+ context = nullcontext(lpath)
409
+ use_seek = False # might not support seeking
410
+ else:
411
+ context = open(lpath, "rb")
412
+ use_seek = True
413
+
414
+ with context as f:
415
+ if use_seek:
416
+ callback.set_size(f.seek(0, 2))
417
+ f.seek(0)
418
+ else:
419
+ callback.set_size(getattr(f, "size", None))
420
+
421
+ chunk = f.read(chunk_size)
422
+ while chunk:
423
+ yield chunk
424
+ callback.relative_update(len(chunk))
425
+ chunk = f.read(chunk_size)
426
+
427
+ kw = self.kwargs.copy()
428
+ kw.update(kwargs)
429
+
430
+ method = method.lower()
431
+ if method not in ("post", "put"):
432
+ raise ValueError(
433
+ f"method has to be either 'post' or 'put', not: {method!r}"
434
+ )
435
+
436
+ meth = getattr(self.session, method)
437
+ resp = meth(rpath, data=gen_chunks(), **kw)
438
+ self._raise_not_found_for_status(resp, rpath)
439
+
440
+ def _process_limits(self, url, start, end):
441
+ """Helper for "Range"-based _cat_file"""
442
+ size = None
443
+ suff = False
444
+ if start is not None and start < 0:
445
+ # if start is negative and end None, end is the "suffix length"
446
+ if end is None:
447
+ end = -start
448
+ start = ""
449
+ suff = True
450
+ else:
451
+ size = size or self.info(url)["size"]
452
+ start = size + start
453
+ elif start is None:
454
+ start = 0
455
+ if not suff:
456
+ if end is not None and end < 0:
457
+ if start is not None:
458
+ size = size or self.info(url)["size"]
459
+ end = size + end
460
+ elif end is None:
461
+ end = ""
462
+ if isinstance(end, int):
463
+ end -= 1 # bytes range is inclusive
464
+ return f"bytes={start}-{end}"
465
+
466
+ def exists(self, path, strict=False, **kwargs):
467
+ kw = self.kwargs.copy()
468
+ kw.update(kwargs)
469
+ try:
470
+ logger.debug(path)
471
+ r = self.session.get(self.encode_url(path), **kw)
472
+ if strict:
473
+ self._raise_not_found_for_status(r, path)
474
+ return r.status_code < 400
475
+ except FileNotFoundError:
476
+ return False
477
+ except Exception:
478
+ if strict:
479
+ raise
480
+ return False
481
+
482
+ def isfile(self, path, **kwargs):
483
+ return self.exists(path, **kwargs)
484
+
485
+ def _open(
486
+ self,
487
+ path,
488
+ mode="rb",
489
+ block_size=None,
490
+ autocommit=None, # XXX: This differs from the base class.
491
+ cache_type=None,
492
+ cache_options=None,
493
+ size=None,
494
+ **kwargs,
495
+ ):
496
+ """Make a file-like object
497
+
498
+ Parameters
499
+ ----------
500
+ path: str
501
+ Full URL with protocol
502
+ mode: string
503
+ must be "rb"
504
+ block_size: int or None
505
+ Bytes to download in one request; use instance value if None. If
506
+ zero, will return a streaming Requests file-like instance.
507
+ kwargs: key-value
508
+ Any other parameters, passed to requests calls
509
+ """
510
+ if mode != "rb":
511
+ raise NotImplementedError
512
+ block_size = block_size if block_size is not None else self.block_size
513
+ kw = self.kwargs.copy()
514
+ kw.update(kwargs)
515
+ size = size or self.info(path, **kwargs)["size"]
516
+ if block_size and size:
517
+ return HTTPFile(
518
+ self,
519
+ path,
520
+ session=self.session,
521
+ block_size=block_size,
522
+ mode=mode,
523
+ size=size,
524
+ cache_type=cache_type or self.cache_type,
525
+ cache_options=cache_options or self.cache_options,
526
+ **kw,
527
+ )
528
+ else:
529
+ return HTTPStreamFile(
530
+ self,
531
+ path,
532
+ mode=mode,
533
+ session=self.session,
534
+ **kw,
535
+ )
536
+
537
+ def ukey(self, url):
538
+ """Unique identifier; assume HTTP files are static, unchanging"""
539
+ return tokenize(url, self.kwargs, self.protocol)
540
+
541
+ def info(self, url, **kwargs):
542
+ """Get info of URL
543
+
544
+ Tries to access location via HEAD, and then GET methods, but does
545
+ not fetch the data.
546
+
547
+ It is possible that the server does not supply any size information, in
548
+ which case size will be given as None (and certain operations on the
549
+ corresponding file will not work).
550
+ """
551
+ info = {}
552
+ for policy in ["head", "get"]:
553
+ try:
554
+ info.update(
555
+ _file_info(
556
+ self.encode_url(url),
557
+ size_policy=policy,
558
+ session=self.session,
559
+ **self.kwargs,
560
+ **kwargs,
561
+ )
562
+ )
563
+ if info.get("size") is not None:
564
+ break
565
+ except Exception as exc:
566
+ if policy == "get":
567
+ # If get failed, then raise a FileNotFoundError
568
+ raise FileNotFoundError(url) from exc
569
+ logger.debug(str(exc))
570
+
571
+ return {"name": url, "size": None, **info, "type": "file"}
572
+
573
+ def glob(self, path, maxdepth=None, **kwargs):
574
+ """
575
+ Find files by glob-matching.
576
+
577
+ This implementation is idntical to the one in AbstractFileSystem,
578
+ but "?" is not considered as a character for globbing, because it is
579
+ so common in URLs, often identifying the "query" part.
580
+ """
581
+ import re
582
+
583
+ ends = path.endswith("/")
584
+ path = self._strip_protocol(path)
585
+ indstar = path.find("*") if path.find("*") >= 0 else len(path)
586
+ indbrace = path.find("[") if path.find("[") >= 0 else len(path)
587
+
588
+ ind = min(indstar, indbrace)
589
+
590
+ detail = kwargs.pop("detail", False)
591
+
592
+ if not has_magic(path):
593
+ root = path
594
+ depth = 1
595
+ if ends:
596
+ path += "/*"
597
+ elif self.exists(path):
598
+ if not detail:
599
+ return [path]
600
+ else:
601
+ return {path: self.info(path)}
602
+ else:
603
+ if not detail:
604
+ return [] # glob of non-existent returns empty
605
+ else:
606
+ return {}
607
+ elif "/" in path[:ind]:
608
+ ind2 = path[:ind].rindex("/")
609
+ root = path[: ind2 + 1]
610
+ depth = None if "**" in path else path[ind2 + 1 :].count("/") + 1
611
+ else:
612
+ root = ""
613
+ depth = None if "**" in path else path[ind + 1 :].count("/") + 1
614
+
615
+ allpaths = self.find(
616
+ root, maxdepth=maxdepth or depth, withdirs=True, detail=True, **kwargs
617
+ )
618
+ # Escape characters special to python regex, leaving our supported
619
+ # special characters in place.
620
+ # See https://www.gnu.org/software/bash/manual/html_node/Pattern-Matching.html
621
+ # for shell globbing details.
622
+ pattern = (
623
+ "^"
624
+ + (
625
+ path.replace("\\", r"\\")
626
+ .replace(".", r"\.")
627
+ .replace("+", r"\+")
628
+ .replace("//", "/")
629
+ .replace("(", r"\(")
630
+ .replace(")", r"\)")
631
+ .replace("|", r"\|")
632
+ .replace("^", r"\^")
633
+ .replace("$", r"\$")
634
+ .replace("{", r"\{")
635
+ .replace("}", r"\}")
636
+ .rstrip("/")
637
+ )
638
+ + "$"
639
+ )
640
+ pattern = re.sub("[*]{2}", "=PLACEHOLDER=", pattern)
641
+ pattern = re.sub("[*]", "[^/]*", pattern)
642
+ pattern = re.compile(pattern.replace("=PLACEHOLDER=", ".*"))
643
+ out = {
644
+ p: allpaths[p]
645
+ for p in sorted(allpaths)
646
+ if pattern.match(p.replace("//", "/").rstrip("/"))
647
+ }
648
+ if detail:
649
+ return out
650
+ else:
651
+ return list(out)
652
+
653
+ def isdir(self, path):
654
+ # override, since all URLs are (also) files
655
+ try:
656
+ return bool(self.ls(path))
657
+ except (FileNotFoundError, ValueError):
658
+ return False
659
+
660
+
661
+ class HTTPFile(AbstractBufferedFile):
662
+ """
663
+ A file-like object pointing to a remove HTTP(S) resource
664
+
665
+ Supports only reading, with read-ahead of a predermined block-size.
666
+
667
+ In the case that the server does not supply the filesize, only reading of
668
+ the complete file in one go is supported.
669
+
670
+ Parameters
671
+ ----------
672
+ url: str
673
+ Full URL of the remote resource, including the protocol
674
+ session: requests.Session or None
675
+ All calls will be made within this session, to avoid restarting
676
+ connections where the server allows this
677
+ block_size: int or None
678
+ The amount of read-ahead to do, in bytes. Default is 5MB, or the value
679
+ configured for the FileSystem creating this file
680
+ size: None or int
681
+ If given, this is the size of the file in bytes, and we don't attempt
682
+ to call the server to find the value.
683
+ kwargs: all other key-values are passed to requests calls.
684
+ """
685
+
686
+ def __init__(
687
+ self,
688
+ fs,
689
+ url,
690
+ session=None,
691
+ block_size=None,
692
+ mode="rb",
693
+ cache_type="bytes",
694
+ cache_options=None,
695
+ size=None,
696
+ **kwargs,
697
+ ):
698
+ if mode != "rb":
699
+ raise NotImplementedError("File mode not supported")
700
+ self.url = url
701
+ self.session = session
702
+ self.details = {"name": url, "size": size, "type": "file"}
703
+ super().__init__(
704
+ fs=fs,
705
+ path=url,
706
+ mode=mode,
707
+ block_size=block_size,
708
+ cache_type=cache_type,
709
+ cache_options=cache_options,
710
+ **kwargs,
711
+ )
712
+
713
+ def read(self, length=-1):
714
+ """Read bytes from file
715
+
716
+ Parameters
717
+ ----------
718
+ length: int
719
+ Read up to this many bytes. If negative, read all content to end of
720
+ file. If the server has not supplied the filesize, attempting to
721
+ read only part of the data will raise a ValueError.
722
+ """
723
+ if (
724
+ (length < 0 and self.loc == 0) # explicit read all
725
+ # but not when the size is known and fits into a block anyways
726
+ and not (self.size is not None and self.size <= self.blocksize)
727
+ ):
728
+ self._fetch_all()
729
+ if self.size is None:
730
+ if length < 0:
731
+ self._fetch_all()
732
+ else:
733
+ length = min(self.size - self.loc, length)
734
+ return super().read(length)
735
+
736
+ def _fetch_all(self):
737
+ """Read whole file in one shot, without caching
738
+
739
+ This is only called when position is still at zero,
740
+ and read() is called without a byte-count.
741
+ """
742
+ logger.debug(f"Fetch all for {self}")
743
+ if not isinstance(self.cache, AllBytes):
744
+ r = self.session.get(self.fs.encode_url(self.url), **self.kwargs)
745
+ r.raise_for_status()
746
+ out = r.content
747
+ self.cache = AllBytes(size=len(out), fetcher=None, blocksize=None, data=out)
748
+ self.size = len(out)
749
+
750
+ def _parse_content_range(self, headers):
751
+ """Parse the Content-Range header"""
752
+ s = headers.get("Content-Range", "")
753
+ m = re.match(r"bytes (\d+-\d+|\*)/(\d+|\*)", s)
754
+ if not m:
755
+ return None, None, None
756
+
757
+ if m[1] == "*":
758
+ start = end = None
759
+ else:
760
+ start, end = [int(x) for x in m[1].split("-")]
761
+ total = None if m[2] == "*" else int(m[2])
762
+ return start, end, total
763
+
764
+ def _fetch_range(self, start, end):
765
+ """Download a block of data
766
+
767
+ The expectation is that the server returns only the requested bytes,
768
+ with HTTP code 206. If this is not the case, we first check the headers,
769
+ and then stream the output - if the data size is bigger than we
770
+ requested, an exception is raised.
771
+ """
772
+ logger.debug(f"Fetch range for {self}: {start}-{end}")
773
+ kwargs = self.kwargs.copy()
774
+ headers = kwargs.pop("headers", {}).copy()
775
+ headers["Range"] = f"bytes={start}-{end - 1}"
776
+ logger.debug("%s : %s", self.url, headers["Range"])
777
+ r = self.session.get(self.fs.encode_url(self.url), headers=headers, **kwargs)
778
+ if r.status_code == 416:
779
+ # range request outside file
780
+ return b""
781
+ r.raise_for_status()
782
+
783
+ # If the server has handled the range request, it should reply
784
+ # with status 206 (partial content). But we'll guess that a suitable
785
+ # Content-Range header or a Content-Length no more than the
786
+ # requested range also mean we have got the desired range.
787
+ cl = r.headers.get("Content-Length", r.headers.get("content-length", end + 1))
788
+ response_is_range = (
789
+ r.status_code == 206
790
+ or self._parse_content_range(r.headers)[0] == start
791
+ or int(cl) <= end - start
792
+ )
793
+
794
+ if response_is_range:
795
+ # partial content, as expected
796
+ out = r.content
797
+ elif start > 0:
798
+ raise ValueError(
799
+ "The HTTP server doesn't appear to support range requests. "
800
+ "Only reading this file from the beginning is supported. "
801
+ "Open with block_size=0 for a streaming file interface."
802
+ )
803
+ else:
804
+ # Response is not a range, but we want the start of the file,
805
+ # so we can read the required amount anyway.
806
+ cl = 0
807
+ out = []
808
+ for chunk in r.iter_content(2**20, False):
809
+ out.append(chunk)
810
+ cl += len(chunk)
811
+ out = b"".join(out)[: end - start]
812
+ return out
813
+
814
+
815
+ magic_check = re.compile("([*[])")
816
+
817
+
818
+ def has_magic(s):
819
+ match = magic_check.search(s)
820
+ return match is not None
821
+
822
+
823
+ class HTTPStreamFile(AbstractBufferedFile):
824
+ def __init__(self, fs, url, mode="rb", session=None, **kwargs):
825
+ self.url = url
826
+ self.session = session
827
+ if mode != "rb":
828
+ raise ValueError
829
+ self.details = {"name": url, "size": None}
830
+ super().__init__(fs=fs, path=url, mode=mode, cache_type="readahead", **kwargs)
831
+
832
+ r = self.session.get(self.fs.encode_url(url), stream=True, **kwargs)
833
+ self.fs._raise_not_found_for_status(r, url)
834
+ self.it = r.iter_content(1024, False)
835
+ self.leftover = b""
836
+
837
+ self.r = r
838
+
839
+ def seek(self, *args, **kwargs):
840
+ raise ValueError("Cannot seek streaming HTTP file")
841
+
842
+ def read(self, num=-1):
843
+ bufs = [self.leftover]
844
+ leng = len(self.leftover)
845
+ while leng < num or num < 0:
846
+ try:
847
+ out = self.it.__next__()
848
+ except StopIteration:
849
+ break
850
+ if out:
851
+ bufs.append(out)
852
+ else:
853
+ break
854
+ leng += len(out)
855
+ out = b"".join(bufs)
856
+ if num >= 0:
857
+ self.leftover = out[num:]
858
+ out = out[:num]
859
+ else:
860
+ self.leftover = b""
861
+ self.loc += len(out)
862
+ return out
863
+
864
+ def close(self):
865
+ self.r.close()
866
+ self.closed = True
867
+
868
+
869
+ def get_range(session, url, start, end, **kwargs):
870
+ # explicit get a range when we know it must be safe
871
+ kwargs = kwargs.copy()
872
+ headers = kwargs.pop("headers", {}).copy()
873
+ headers["Range"] = f"bytes={start}-{end - 1}"
874
+ r = session.get(url, headers=headers, **kwargs)
875
+ r.raise_for_status()
876
+ return r.content
877
+
878
+
879
+ def _file_info(url, session, size_policy="head", **kwargs):
880
+ """Call HEAD on the server to get details about the file (size/checksum etc.)
881
+
882
+ Default operation is to explicitly allow redirects and use encoding
883
+ 'identity' (no compression) to get the true size of the target.
884
+ """
885
+ logger.debug("Retrieve file size for %s", url)
886
+ kwargs = kwargs.copy()
887
+ ar = kwargs.pop("allow_redirects", True)
888
+ head = kwargs.get("headers", {}).copy()
889
+ # TODO: not allowed in JS
890
+ # head["Accept-Encoding"] = "identity"
891
+ kwargs["headers"] = head
892
+
893
+ info = {}
894
+ if size_policy == "head":
895
+ r = session.head(url, allow_redirects=ar, **kwargs)
896
+ elif size_policy == "get":
897
+ r = session.get(url, allow_redirects=ar, **kwargs)
898
+ else:
899
+ raise TypeError(f'size_policy must be "head" or "get", got {size_policy}')
900
+ r.raise_for_status()
901
+
902
+ # TODO:
903
+ # recognise lack of 'Accept-Ranges',
904
+ # or 'Accept-Ranges': 'none' (not 'bytes')
905
+ # to mean streaming only, no random access => return None
906
+ if "Content-Length" in r.headers:
907
+ info["size"] = int(r.headers["Content-Length"])
908
+ elif "Content-Range" in r.headers:
909
+ info["size"] = int(r.headers["Content-Range"].split("/")[1])
910
+ elif "content-length" in r.headers:
911
+ info["size"] = int(r.headers["content-length"])
912
+ elif "content-range" in r.headers:
913
+ info["size"] = int(r.headers["content-range"].split("/")[1])
914
+
915
+ for checksum_field in ["ETag", "Content-MD5", "Digest"]:
916
+ if r.headers.get(checksum_field):
917
+ info[checksum_field] = r.headers[checksum_field]
918
+
919
+ return info
920
+
921
+
922
+ # importing this is enough to register it
923
+ def register():
924
+ register_implementation("http", HTTPFileSystem, clobber=True)
925
+ register_implementation("https", HTTPFileSystem, clobber=True)
926
+ register_implementation("sync-http", HTTPFileSystem, clobber=True)
927
+ register_implementation("sync-https", HTTPFileSystem, clobber=True)
928
+
929
+
930
+ register()
931
+
932
+
933
+ def unregister():
934
+ from fsspec.implementations.http import HTTPFileSystem
935
+
936
+ register_implementation("http", HTTPFileSystem, clobber=True)
937
+ register_implementation("https", HTTPFileSystem, clobber=True)
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/fsspec/implementations/memory.py ADDED
@@ -0,0 +1,311 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+ from datetime import datetime, timezone
5
+ from errno import ENOTEMPTY
6
+ from io import BytesIO
7
+ from pathlib import PurePath, PureWindowsPath
8
+ from typing import Any, ClassVar
9
+
10
+ from fsspec import AbstractFileSystem
11
+ from fsspec.implementations.local import LocalFileSystem
12
+ from fsspec.utils import stringify_path
13
+
14
+ logger = logging.getLogger("fsspec.memoryfs")
15
+
16
+
17
+ class MemoryFileSystem(AbstractFileSystem):
18
+ """A filesystem based on a dict of BytesIO objects
19
+
20
+ This is a global filesystem so instances of this class all point to the same
21
+ in memory filesystem.
22
+ """
23
+
24
+ store: ClassVar[dict[str, Any]] = {} # global, do not overwrite!
25
+ pseudo_dirs = [""] # global, do not overwrite!
26
+ protocol = "memory"
27
+ root_marker = "/"
28
+
29
+ @classmethod
30
+ def _strip_protocol(cls, path):
31
+ if isinstance(path, PurePath):
32
+ if isinstance(path, PureWindowsPath):
33
+ return LocalFileSystem._strip_protocol(path)
34
+ else:
35
+ path = stringify_path(path)
36
+
37
+ path = path.removeprefix("memory://")
38
+ if "::" in path or "://" in path:
39
+ return path.rstrip("/")
40
+ path = path.lstrip("/").rstrip("/")
41
+ return "/" + path if path else ""
42
+
43
+ def ls(self, path, detail=True, **kwargs):
44
+ path = self._strip_protocol(path)
45
+ if path in self.store:
46
+ # there is a key with this exact name
47
+ if not detail:
48
+ return [path]
49
+ return [
50
+ {
51
+ "name": path,
52
+ "size": self.store[path].size,
53
+ "type": "file",
54
+ "created": self.store[path].created.timestamp(),
55
+ }
56
+ ]
57
+ paths = set()
58
+ starter = path + "/"
59
+ out = []
60
+ for p2 in tuple(self.store):
61
+ if p2.startswith(starter):
62
+ if "/" not in p2[len(starter) :]:
63
+ # exact child
64
+ out.append(
65
+ {
66
+ "name": p2,
67
+ "size": self.store[p2].size,
68
+ "type": "file",
69
+ "created": self.store[p2].created.timestamp(),
70
+ }
71
+ )
72
+ elif len(p2) > len(starter):
73
+ # implied child directory
74
+ ppath = starter + p2[len(starter) :].split("/", 1)[0]
75
+ if ppath not in paths:
76
+ out = out or []
77
+ out.append(
78
+ {
79
+ "name": ppath,
80
+ "size": 0,
81
+ "type": "directory",
82
+ }
83
+ )
84
+ paths.add(ppath)
85
+ for p2 in self.pseudo_dirs:
86
+ if p2.startswith(starter):
87
+ if "/" not in p2[len(starter) :]:
88
+ # exact child pdir
89
+ if p2 not in paths:
90
+ out.append({"name": p2, "size": 0, "type": "directory"})
91
+ paths.add(p2)
92
+ else:
93
+ # directory implied by deeper pdir
94
+ ppath = starter + p2[len(starter) :].split("/", 1)[0]
95
+ if ppath not in paths:
96
+ out.append({"name": ppath, "size": 0, "type": "directory"})
97
+ paths.add(ppath)
98
+ if not out:
99
+ if path in self.pseudo_dirs:
100
+ # empty dir
101
+ return []
102
+ raise FileNotFoundError(path)
103
+ if detail:
104
+ return out
105
+ return sorted([f["name"] for f in out])
106
+
107
+ def mkdir(self, path, create_parents=True, **kwargs):
108
+ path = self._strip_protocol(path)
109
+ if path in self.store or path in self.pseudo_dirs:
110
+ raise FileExistsError(path)
111
+ if self._parent(path).strip("/") and self.isfile(self._parent(path)):
112
+ raise NotADirectoryError(self._parent(path))
113
+ if create_parents and self._parent(path).strip("/"):
114
+ try:
115
+ self.mkdir(self._parent(path), create_parents, **kwargs)
116
+ except FileExistsError:
117
+ pass
118
+ if path and path not in self.pseudo_dirs:
119
+ self.pseudo_dirs.append(path)
120
+
121
+ def makedirs(self, path, exist_ok=False):
122
+ try:
123
+ self.mkdir(path, create_parents=True)
124
+ except FileExistsError:
125
+ if not exist_ok:
126
+ raise
127
+
128
+ def pipe_file(self, path, value, mode="overwrite", **kwargs):
129
+ """Set the bytes of given file
130
+
131
+ Avoids copies of the data if possible
132
+ """
133
+ mode = "xb" if mode == "create" else "wb"
134
+ self.open(path, mode=mode, data=value)
135
+
136
+ def rmdir(self, path):
137
+ path = self._strip_protocol(path)
138
+ if path == "":
139
+ # silently avoid deleting FS root
140
+ return
141
+ if path in self.pseudo_dirs:
142
+ if not self.ls(path):
143
+ self.pseudo_dirs.remove(path)
144
+ else:
145
+ raise OSError(ENOTEMPTY, "Directory not empty", path)
146
+ else:
147
+ raise FileNotFoundError(path)
148
+
149
+ def info(self, path, **kwargs):
150
+ logger.debug("info: %s", path)
151
+ path = self._strip_protocol(path)
152
+ if path in self.pseudo_dirs or any(
153
+ p.startswith(path + "/") for p in list(self.store) + self.pseudo_dirs
154
+ ):
155
+ return {
156
+ "name": path,
157
+ "size": 0,
158
+ "type": "directory",
159
+ }
160
+ elif path in self.store:
161
+ filelike = self.store[path]
162
+ return {
163
+ "name": path,
164
+ "size": filelike.size,
165
+ "type": "file",
166
+ "created": getattr(filelike, "created", None),
167
+ }
168
+ else:
169
+ raise FileNotFoundError(path)
170
+
171
+ def _open(
172
+ self,
173
+ path,
174
+ mode="rb",
175
+ block_size=None,
176
+ autocommit=True,
177
+ cache_options=None,
178
+ **kwargs,
179
+ ):
180
+ path = self._strip_protocol(path)
181
+ if "x" in mode and self.exists(path):
182
+ raise FileExistsError
183
+ if path in self.pseudo_dirs:
184
+ raise IsADirectoryError(path)
185
+ parent = path
186
+ while len(parent) > 1:
187
+ parent = self._parent(parent)
188
+ if self.isfile(parent):
189
+ raise FileExistsError(parent)
190
+ if mode in ["rb", "ab", "r+b", "a+b"]:
191
+ if path in self.store:
192
+ f = self.store[path]
193
+ if "a" in mode:
194
+ # position at the end of file
195
+ f.seek(0, 2)
196
+ else:
197
+ # position at the beginning of file
198
+ f.seek(0)
199
+ return f
200
+ else:
201
+ raise FileNotFoundError(path)
202
+ elif mode in {"wb", "w+b", "xb", "x+b"}:
203
+ if "x" in mode and self.exists(path):
204
+ raise FileExistsError
205
+ m = MemoryFile(self, path, kwargs.get("data"))
206
+ if not self._intrans:
207
+ m.commit()
208
+ return m
209
+ else:
210
+ name = self.__class__.__name__
211
+ raise ValueError(f"unsupported file mode for {name}: {mode!r}")
212
+
213
+ def cp_file(self, path1, path2, **kwargs):
214
+ path1 = self._strip_protocol(path1)
215
+ path2 = self._strip_protocol(path2)
216
+ if self.isfile(path1):
217
+ self.store[path2] = MemoryFile(
218
+ self, path2, self.store[path1].getvalue()
219
+ ) # implicit copy
220
+ elif self.isdir(path1):
221
+ if path2 not in self.pseudo_dirs:
222
+ self.pseudo_dirs.append(path2)
223
+ else:
224
+ raise FileNotFoundError(path1)
225
+
226
+ def cat_file(self, path, start=None, end=None, **kwargs):
227
+ logger.debug("cat: %s", path)
228
+ path = self._strip_protocol(path)
229
+ try:
230
+ return bytes(self.store[path].getbuffer()[start:end])
231
+ except KeyError as e:
232
+ raise FileNotFoundError(path) from e
233
+
234
+ def _rm(self, path):
235
+ path = self._strip_protocol(path)
236
+ try:
237
+ del self.store[path]
238
+ except KeyError as e:
239
+ raise FileNotFoundError(path) from e
240
+
241
+ def modified(self, path):
242
+ path = self._strip_protocol(path)
243
+ try:
244
+ return self.store[path].modified
245
+ except KeyError as e:
246
+ raise FileNotFoundError(path) from e
247
+
248
+ def created(self, path):
249
+ path = self._strip_protocol(path)
250
+ try:
251
+ return self.store[path].created
252
+ except KeyError as e:
253
+ raise FileNotFoundError(path) from e
254
+
255
+ def isfile(self, path):
256
+ path = self._strip_protocol(path)
257
+ return path in self.store
258
+
259
+ def rm(self, path, recursive=False, maxdepth=None):
260
+ if isinstance(path, str):
261
+ path = self._strip_protocol(path)
262
+ else:
263
+ path = [self._strip_protocol(p) for p in path]
264
+ paths = self.expand_path(path, recursive=recursive, maxdepth=maxdepth)
265
+ for p in reversed(paths):
266
+ if self.isfile(p):
267
+ self.rm_file(p)
268
+ # If the expanded path doesn't exist, it is only because the expanded
269
+ # path was a directory that does not exist in self.pseudo_dirs. This
270
+ # is possible if you directly create files without making the
271
+ # directories first.
272
+ elif not self.exists(p):
273
+ continue
274
+ else:
275
+ self.rmdir(p)
276
+
277
+
278
+ class MemoryFile(BytesIO):
279
+ """A BytesIO which can't close and works as a context manager
280
+
281
+ Can initialise with data. Each path should only be active once at any moment.
282
+
283
+ No need to provide fs, path if auto-committing (default)
284
+ """
285
+
286
+ def __init__(self, fs=None, path=None, data=None):
287
+ logger.debug("open file %s", path)
288
+ self.fs = fs
289
+ self.path = path
290
+ self.created = datetime.now(tz=timezone.utc)
291
+ self.modified = datetime.now(tz=timezone.utc)
292
+ if data:
293
+ super().__init__(data)
294
+ self.seek(0)
295
+
296
+ @property
297
+ def size(self):
298
+ return self.getbuffer().nbytes
299
+
300
+ def __enter__(self):
301
+ return self
302
+
303
+ def close(self):
304
+ pass
305
+
306
+ def discard(self):
307
+ pass
308
+
309
+ def commit(self):
310
+ self.fs.store[self.path] = self
311
+ self.modified = datetime.now(tz=timezone.utc)
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/fsspec/implementations/zip.py ADDED
@@ -0,0 +1,183 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import zipfile
3
+
4
+ import fsspec
5
+ from fsspec.archive import AbstractArchiveFileSystem
6
+
7
+
8
+ class ZipFileSystem(AbstractArchiveFileSystem):
9
+ """Read/Write contents of ZIP archive as a file-system
10
+
11
+ Keeps file object open while instance lives.
12
+
13
+ This class is pickleable, but not necessarily thread-safe
14
+ """
15
+
16
+ root_marker = ""
17
+ protocol = "zip"
18
+ cachable = False
19
+
20
+ def __init__(
21
+ self,
22
+ fo="",
23
+ mode="r",
24
+ target_protocol=None,
25
+ target_options=None,
26
+ compression=zipfile.ZIP_STORED,
27
+ allowZip64=True,
28
+ compresslevel=None,
29
+ **kwargs,
30
+ ):
31
+ """
32
+ Parameters
33
+ ----------
34
+ fo: str or file-like
35
+ Contains ZIP, and must exist. If a str, will fetch file using
36
+ :meth:`~fsspec.open_files`, which must return one file exactly.
37
+ mode: str
38
+ Accept: "r", "w", "a"
39
+ target_protocol: str (optional)
40
+ If ``fo`` is a string, this value can be used to override the
41
+ FS protocol inferred from a URL
42
+ target_options: dict (optional)
43
+ Kwargs passed when instantiating the target FS, if ``fo`` is
44
+ a string.
45
+ compression, allowZip64, compresslevel: passed to ZipFile
46
+ Only relevant when creating a ZIP
47
+ """
48
+ super().__init__(self, **kwargs)
49
+ if mode not in set("rwa"):
50
+ raise ValueError(f"mode '{mode}' no understood")
51
+ self.mode = mode
52
+ if isinstance(fo, (str, os.PathLike)):
53
+ if mode == "a":
54
+ m = "r+b"
55
+ else:
56
+ m = mode + "b"
57
+ fo = fsspec.open(
58
+ fo, mode=m, protocol=target_protocol, **(target_options or {})
59
+ )
60
+ self.force_zip_64 = allowZip64
61
+ self.of = fo
62
+ self.fo = fo.__enter__() # the whole instance is a context
63
+ self.zip = zipfile.ZipFile(
64
+ self.fo,
65
+ mode=mode,
66
+ compression=compression,
67
+ allowZip64=allowZip64,
68
+ compresslevel=compresslevel,
69
+ )
70
+ self.dir_cache = None
71
+
72
+ @classmethod
73
+ def _strip_protocol(cls, path):
74
+ # zip file paths are always relative to the archive root
75
+ return super()._strip_protocol(path).lstrip("/")
76
+
77
+ def __del__(self):
78
+ if hasattr(self, "zip"):
79
+ self.close()
80
+ del self.zip
81
+ if hasattr(self, "of") and hasattr(self.of, "__exit__"):
82
+ self.of.__exit__(None, None, None)
83
+
84
+ def close(self):
85
+ """Commits any write changes to the file. Done on ``del`` too."""
86
+ self.zip.close()
87
+
88
+ def _get_dirs(self):
89
+ if self.dir_cache is None or self.mode in set("wa"):
90
+ # when writing, dir_cache is always in the ZipFile's attributes,
91
+ # not read from the file.
92
+ files = self.zip.infolist()
93
+ self.dir_cache = {
94
+ dirname.rstrip("/"): {
95
+ "name": dirname.rstrip("/"),
96
+ "size": 0,
97
+ "type": "directory",
98
+ }
99
+ for dirname in self._all_dirnames(self.zip.namelist())
100
+ }
101
+ for z in files:
102
+ f = {s: getattr(z, s, None) for s in zipfile.ZipInfo.__slots__}
103
+ f.update(
104
+ {
105
+ "name": z.filename.rstrip("/"),
106
+ "size": z.file_size,
107
+ "type": ("directory" if z.is_dir() else "file"),
108
+ }
109
+ )
110
+ self.dir_cache[f["name"]] = f
111
+
112
+ def pipe_file(self, path, value, **kwargs):
113
+ # override upstream, because we know the exact file size in this case
114
+ self.zip.writestr(path, value, **kwargs)
115
+
116
+ def _open(
117
+ self,
118
+ path,
119
+ mode="rb",
120
+ block_size=None,
121
+ autocommit=True,
122
+ cache_options=None,
123
+ **kwargs,
124
+ ):
125
+ path = self._strip_protocol(path)
126
+ if "r" in mode and self.mode in set("wa"):
127
+ if self.exists(path):
128
+ raise OSError("ZipFS can only be open for reading or writing, not both")
129
+ raise FileNotFoundError(path)
130
+ if "r" in self.mode and "w" in mode:
131
+ raise OSError("ZipFS can only be open for reading or writing, not both")
132
+ out = self.zip.open(path, mode.strip("b"), force_zip64=self.force_zip_64)
133
+ if "r" in mode:
134
+ info = self.info(path)
135
+ out.size = info["size"]
136
+ out.name = info["name"]
137
+ return out
138
+
139
+ def find(self, path, maxdepth=None, withdirs=False, detail=False, **kwargs):
140
+ if maxdepth is not None and maxdepth < 1:
141
+ raise ValueError("maxdepth must be at least 1")
142
+
143
+ def to_parts(_path: str):
144
+ return list(filter(None, _path.replace("\\", "/").split("/")))
145
+
146
+ if not isinstance(path, str):
147
+ path = str(path)
148
+
149
+ # Remove the leading slash, as the zip file paths are always
150
+ # given without a leading slash
151
+ path = path.lstrip("/")
152
+ path_parts = to_parts(path)
153
+ path_depth = len(path_parts)
154
+
155
+ self._get_dirs()
156
+
157
+ result = {}
158
+ # To match posix find, if an exact file name is given, we should
159
+ # return only that file
160
+ if path in self.dir_cache and self.dir_cache[path]["type"] == "file":
161
+ result[path] = self.dir_cache[path]
162
+ return result if detail else [path]
163
+
164
+ for file_path, file_info in self.dir_cache.items():
165
+ if len(file_parts := to_parts(file_path)) < path_depth or any(
166
+ a != b for a, b in zip(path_parts, file_parts)
167
+ ):
168
+ # skip parent folders and mismatching paths
169
+ continue
170
+
171
+ if file_info["type"] == "directory":
172
+ if withdirs and file_path not in result:
173
+ result[file_path.strip("/")] = file_info
174
+ continue
175
+
176
+ if file_path not in result:
177
+ result[file_path] = file_info if detail else None
178
+
179
+ if maxdepth:
180
+ result = {
181
+ k: v for k, v in result.items() if k.count("/") < maxdepth + path_depth
182
+ }
183
+ return result if detail else sorted(result)
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/_version.py ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Utility to compare (NumPy) version strings.
2
+
3
+ The NumpyVersion class allows properly comparing numpy version strings.
4
+ The LooseVersion and StrictVersion classes that distutils provides don't
5
+ work; they don't recognize anything like alpha/beta/rc/dev versions.
6
+
7
+ """
8
+ import re
9
+
10
+
11
+ __all__ = ['NumpyVersion']
12
+
13
+
14
+ class NumpyVersion():
15
+ """Parse and compare numpy version strings.
16
+
17
+ NumPy has the following versioning scheme (numbers given are examples; they
18
+ can be > 9 in principle):
19
+
20
+ - Released version: '1.8.0', '1.8.1', etc.
21
+ - Alpha: '1.8.0a1', '1.8.0a2', etc.
22
+ - Beta: '1.8.0b1', '1.8.0b2', etc.
23
+ - Release candidates: '1.8.0rc1', '1.8.0rc2', etc.
24
+ - Development versions: '1.8.0.dev-f1234afa' (git commit hash appended)
25
+ - Development versions after a1: '1.8.0a1.dev-f1234afa',
26
+ '1.8.0b2.dev-f1234afa',
27
+ '1.8.1rc1.dev-f1234afa', etc.
28
+ - Development versions (no git hash available): '1.8.0.dev-Unknown'
29
+
30
+ Comparing needs to be done against a valid version string or other
31
+ `NumpyVersion` instance. Note that all development versions of the same
32
+ (pre-)release compare equal.
33
+
34
+ .. versionadded:: 1.9.0
35
+
36
+ Parameters
37
+ ----------
38
+ vstring : str
39
+ NumPy version string (``np.__version__``).
40
+
41
+ Examples
42
+ --------
43
+ >>> from numpy.lib import NumpyVersion
44
+ >>> if NumpyVersion(np.__version__) < '1.7.0':
45
+ ... print('skip')
46
+ >>> # skip
47
+
48
+ >>> NumpyVersion('1.7') # raises ValueError, add ".0"
49
+ Traceback (most recent call last):
50
+ ...
51
+ ValueError: Not a valid numpy version string
52
+
53
+ """
54
+
55
+ def __init__(self, vstring):
56
+ self.vstring = vstring
57
+ ver_main = re.match(r'\d+\.\d+\.\d+', vstring)
58
+ if not ver_main:
59
+ raise ValueError("Not a valid numpy version string")
60
+
61
+ self.version = ver_main.group()
62
+ self.major, self.minor, self.bugfix = [int(x) for x in
63
+ self.version.split('.')]
64
+ if len(vstring) == ver_main.end():
65
+ self.pre_release = 'final'
66
+ else:
67
+ alpha = re.match(r'a\d', vstring[ver_main.end():])
68
+ beta = re.match(r'b\d', vstring[ver_main.end():])
69
+ rc = re.match(r'rc\d', vstring[ver_main.end():])
70
+ pre_rel = [m for m in [alpha, beta, rc] if m is not None]
71
+ if pre_rel:
72
+ self.pre_release = pre_rel[0].group()
73
+ else:
74
+ self.pre_release = ''
75
+
76
+ self.is_devversion = bool(re.search(r'.dev', vstring))
77
+
78
+ def _compare_version(self, other):
79
+ """Compare major.minor.bugfix"""
80
+ if self.major == other.major:
81
+ if self.minor == other.minor:
82
+ if self.bugfix == other.bugfix:
83
+ vercmp = 0
84
+ elif self.bugfix > other.bugfix:
85
+ vercmp = 1
86
+ else:
87
+ vercmp = -1
88
+ elif self.minor > other.minor:
89
+ vercmp = 1
90
+ else:
91
+ vercmp = -1
92
+ elif self.major > other.major:
93
+ vercmp = 1
94
+ else:
95
+ vercmp = -1
96
+
97
+ return vercmp
98
+
99
+ def _compare_pre_release(self, other):
100
+ """Compare alpha/beta/rc/final."""
101
+ if self.pre_release == other.pre_release:
102
+ vercmp = 0
103
+ elif self.pre_release == 'final':
104
+ vercmp = 1
105
+ elif other.pre_release == 'final':
106
+ vercmp = -1
107
+ elif self.pre_release > other.pre_release:
108
+ vercmp = 1
109
+ else:
110
+ vercmp = -1
111
+
112
+ return vercmp
113
+
114
+ def _compare(self, other):
115
+ if not isinstance(other, (str, NumpyVersion)):
116
+ raise ValueError("Invalid object to compare with NumpyVersion.")
117
+
118
+ if isinstance(other, str):
119
+ other = NumpyVersion(other)
120
+
121
+ vercmp = self._compare_version(other)
122
+ if vercmp == 0:
123
+ # Same x.y.z version, check for alpha/beta/rc
124
+ vercmp = self._compare_pre_release(other)
125
+ if vercmp == 0:
126
+ # Same version and same pre-release, check if dev version
127
+ if self.is_devversion is other.is_devversion:
128
+ vercmp = 0
129
+ elif self.is_devversion:
130
+ vercmp = -1
131
+ else:
132
+ vercmp = 1
133
+
134
+ return vercmp
135
+
136
+ def __lt__(self, other):
137
+ return self._compare(other) < 0
138
+
139
+ def __le__(self, other):
140
+ return self._compare(other) <= 0
141
+
142
+ def __eq__(self, other):
143
+ return self._compare(other) == 0
144
+
145
+ def __ne__(self, other):
146
+ return self._compare(other) != 0
147
+
148
+ def __gt__(self, other):
149
+ return self._compare(other) > 0
150
+
151
+ def __ge__(self, other):
152
+ return self._compare(other) >= 0
153
+
154
+ def __repr__(self):
155
+ return "NumpyVersion(%s)" % self.vstring
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/histograms.py ADDED
@@ -0,0 +1,1072 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Histogram-related functions
3
+ """
4
+ import contextlib
5
+ import functools
6
+ import operator
7
+ import warnings
8
+
9
+ import numpy as np
10
+ from numpy.core import overrides
11
+
12
+ __all__ = ['histogram', 'histogramdd', 'histogram_bin_edges']
13
+
14
+ array_function_dispatch = functools.partial(
15
+ overrides.array_function_dispatch, module='numpy')
16
+
17
+ # range is a keyword argument to many functions, so save the builtin so they can
18
+ # use it.
19
+ _range = range
20
+
21
+
22
+ def _ptp(x):
23
+ """Peak-to-peak value of x.
24
+
25
+ This implementation avoids the problem of signed integer arrays having a
26
+ peak-to-peak value that cannot be represented with the array's data type.
27
+ This function returns an unsigned value for signed integer arrays.
28
+ """
29
+ return _unsigned_subtract(x.max(), x.min())
30
+
31
+
32
+ def _hist_bin_sqrt(x, range):
33
+ """
34
+ Square root histogram bin estimator.
35
+
36
+ Bin width is inversely proportional to the data size. Used by many
37
+ programs for its simplicity.
38
+
39
+ Parameters
40
+ ----------
41
+ x : array_like
42
+ Input data that is to be histogrammed, trimmed to range. May not
43
+ be empty.
44
+
45
+ Returns
46
+ -------
47
+ h : An estimate of the optimal bin width for the given data.
48
+ """
49
+ del range # unused
50
+ return _ptp(x) / np.sqrt(x.size)
51
+
52
+
53
+ def _hist_bin_sturges(x, range):
54
+ """
55
+ Sturges histogram bin estimator.
56
+
57
+ A very simplistic estimator based on the assumption of normality of
58
+ the data. This estimator has poor performance for non-normal data,
59
+ which becomes especially obvious for large data sets. The estimate
60
+ depends only on size of the data.
61
+
62
+ Parameters
63
+ ----------
64
+ x : array_like
65
+ Input data that is to be histogrammed, trimmed to range. May not
66
+ be empty.
67
+
68
+ Returns
69
+ -------
70
+ h : An estimate of the optimal bin width for the given data.
71
+ """
72
+ del range # unused
73
+ return _ptp(x) / (np.log2(x.size) + 1.0)
74
+
75
+
76
+ def _hist_bin_rice(x, range):
77
+ """
78
+ Rice histogram bin estimator.
79
+
80
+ Another simple estimator with no normality assumption. It has better
81
+ performance for large data than Sturges, but tends to overestimate
82
+ the number of bins. The number of bins is proportional to the cube
83
+ root of data size (asymptotically optimal). The estimate depends
84
+ only on size of the data.
85
+
86
+ Parameters
87
+ ----------
88
+ x : array_like
89
+ Input data that is to be histogrammed, trimmed to range. May not
90
+ be empty.
91
+
92
+ Returns
93
+ -------
94
+ h : An estimate of the optimal bin width for the given data.
95
+ """
96
+ del range # unused
97
+ return _ptp(x) / (2.0 * x.size ** (1.0 / 3))
98
+
99
+
100
+ def _hist_bin_scott(x, range):
101
+ """
102
+ Scott histogram bin estimator.
103
+
104
+ The binwidth is proportional to the standard deviation of the data
105
+ and inversely proportional to the cube root of data size
106
+ (asymptotically optimal).
107
+
108
+ Parameters
109
+ ----------
110
+ x : array_like
111
+ Input data that is to be histogrammed, trimmed to range. May not
112
+ be empty.
113
+
114
+ Returns
115
+ -------
116
+ h : An estimate of the optimal bin width for the given data.
117
+ """
118
+ del range # unused
119
+ return (24.0 * np.pi**0.5 / x.size)**(1.0 / 3.0) * np.std(x)
120
+
121
+
122
+ def _hist_bin_stone(x, range):
123
+ """
124
+ Histogram bin estimator based on minimizing the estimated integrated squared error (ISE).
125
+
126
+ The number of bins is chosen by minimizing the estimated ISE against the unknown true distribution.
127
+ The ISE is estimated using cross-validation and can be regarded as a generalization of Scott's rule.
128
+ https://en.wikipedia.org/wiki/Histogram#Scott.27s_normal_reference_rule
129
+
130
+ This paper by Stone appears to be the origination of this rule.
131
+ http://digitalassets.lib.berkeley.edu/sdtr/ucb/text/34.pdf
132
+
133
+ Parameters
134
+ ----------
135
+ x : array_like
136
+ Input data that is to be histogrammed, trimmed to range. May not
137
+ be empty.
138
+ range : (float, float)
139
+ The lower and upper range of the bins.
140
+
141
+ Returns
142
+ -------
143
+ h : An estimate of the optimal bin width for the given data.
144
+ """
145
+
146
+ n = x.size
147
+ ptp_x = _ptp(x)
148
+ if n <= 1 or ptp_x == 0:
149
+ return 0
150
+
151
+ def jhat(nbins):
152
+ hh = ptp_x / nbins
153
+ p_k = np.histogram(x, bins=nbins, range=range)[0] / n
154
+ return (2 - (n + 1) * p_k.dot(p_k)) / hh
155
+
156
+ nbins_upper_bound = max(100, int(np.sqrt(n)))
157
+ nbins = min(_range(1, nbins_upper_bound + 1), key=jhat)
158
+ if nbins == nbins_upper_bound:
159
+ warnings.warn("The number of bins estimated may be suboptimal.",
160
+ RuntimeWarning, stacklevel=3)
161
+ return ptp_x / nbins
162
+
163
+
164
+ def _hist_bin_doane(x, range):
165
+ """
166
+ Doane's histogram bin estimator.
167
+
168
+ Improved version of Sturges' formula which works better for
169
+ non-normal data. See
170
+ stats.stackexchange.com/questions/55134/doanes-formula-for-histogram-binning
171
+
172
+ Parameters
173
+ ----------
174
+ x : array_like
175
+ Input data that is to be histogrammed, trimmed to range. May not
176
+ be empty.
177
+
178
+ Returns
179
+ -------
180
+ h : An estimate of the optimal bin width for the given data.
181
+ """
182
+ del range # unused
183
+ if x.size > 2:
184
+ sg1 = np.sqrt(6.0 * (x.size - 2) / ((x.size + 1.0) * (x.size + 3)))
185
+ sigma = np.std(x)
186
+ if sigma > 0.0:
187
+ # These three operations add up to
188
+ # g1 = np.mean(((x - np.mean(x)) / sigma)**3)
189
+ # but use only one temp array instead of three
190
+ temp = x - np.mean(x)
191
+ np.true_divide(temp, sigma, temp)
192
+ np.power(temp, 3, temp)
193
+ g1 = np.mean(temp)
194
+ return _ptp(x) / (1.0 + np.log2(x.size) +
195
+ np.log2(1.0 + np.absolute(g1) / sg1))
196
+ return 0.0
197
+
198
+
199
+ def _hist_bin_fd(x, range):
200
+ """
201
+ The Freedman-Diaconis histogram bin estimator.
202
+
203
+ The Freedman-Diaconis rule uses interquartile range (IQR) to
204
+ estimate binwidth. It is considered a variation of the Scott rule
205
+ with more robustness as the IQR is less affected by outliers than
206
+ the standard deviation. However, the IQR depends on fewer points
207
+ than the standard deviation, so it is less accurate, especially for
208
+ long tailed distributions.
209
+
210
+ If the IQR is 0, this function returns 0 for the bin width.
211
+ Binwidth is inversely proportional to the cube root of data size
212
+ (asymptotically optimal).
213
+
214
+ Parameters
215
+ ----------
216
+ x : array_like
217
+ Input data that is to be histogrammed, trimmed to range. May not
218
+ be empty.
219
+
220
+ Returns
221
+ -------
222
+ h : An estimate of the optimal bin width for the given data.
223
+ """
224
+ del range # unused
225
+ iqr = np.subtract(*np.percentile(x, [75, 25]))
226
+ return 2.0 * iqr * x.size ** (-1.0 / 3.0)
227
+
228
+
229
+ def _hist_bin_auto(x, range):
230
+ """
231
+ Histogram bin estimator that uses the minimum width of the
232
+ Freedman-Diaconis and Sturges estimators if the FD bin width is non-zero.
233
+ If the bin width from the FD estimator is 0, the Sturges estimator is used.
234
+
235
+ The FD estimator is usually the most robust method, but its width
236
+ estimate tends to be too large for small `x` and bad for data with limited
237
+ variance. The Sturges estimator is quite good for small (<1000) datasets
238
+ and is the default in the R language. This method gives good off-the-shelf
239
+ behaviour.
240
+
241
+ .. versionchanged:: 1.15.0
242
+ If there is limited variance the IQR can be 0, which results in the
243
+ FD bin width being 0 too. This is not a valid bin width, so
244
+ ``np.histogram_bin_edges`` chooses 1 bin instead, which may not be optimal.
245
+ If the IQR is 0, it's unlikely any variance-based estimators will be of
246
+ use, so we revert to the Sturges estimator, which only uses the size of the
247
+ dataset in its calculation.
248
+
249
+ Parameters
250
+ ----------
251
+ x : array_like
252
+ Input data that is to be histogrammed, trimmed to range. May not
253
+ be empty.
254
+
255
+ Returns
256
+ -------
257
+ h : An estimate of the optimal bin width for the given data.
258
+
259
+ See Also
260
+ --------
261
+ _hist_bin_fd, _hist_bin_sturges
262
+ """
263
+ fd_bw = _hist_bin_fd(x, range)
264
+ sturges_bw = _hist_bin_sturges(x, range)
265
+ del range # unused
266
+ if fd_bw:
267
+ return min(fd_bw, sturges_bw)
268
+ else:
269
+ # limited variance, so we return a len dependent bw estimator
270
+ return sturges_bw
271
+
272
+ # Private dict initialized at module load time
273
+ _hist_bin_selectors = {'stone': _hist_bin_stone,
274
+ 'auto': _hist_bin_auto,
275
+ 'doane': _hist_bin_doane,
276
+ 'fd': _hist_bin_fd,
277
+ 'rice': _hist_bin_rice,
278
+ 'scott': _hist_bin_scott,
279
+ 'sqrt': _hist_bin_sqrt,
280
+ 'sturges': _hist_bin_sturges}
281
+
282
+
283
+ def _ravel_and_check_weights(a, weights):
284
+ """ Check a and weights have matching shapes, and ravel both """
285
+ a = np.asarray(a)
286
+
287
+ # Ensure that the array is a "subtractable" dtype
288
+ if a.dtype == np.bool_:
289
+ warnings.warn("Converting input from {} to {} for compatibility."
290
+ .format(a.dtype, np.uint8),
291
+ RuntimeWarning, stacklevel=3)
292
+ a = a.astype(np.uint8)
293
+
294
+ if weights is not None:
295
+ weights = np.asarray(weights)
296
+ if weights.shape != a.shape:
297
+ raise ValueError(
298
+ 'weights should have the same shape as a.')
299
+ weights = weights.ravel()
300
+ a = a.ravel()
301
+ return a, weights
302
+
303
+
304
+ def _get_outer_edges(a, range):
305
+ """
306
+ Determine the outer bin edges to use, from either the data or the range
307
+ argument
308
+ """
309
+ if range is not None:
310
+ first_edge, last_edge = range
311
+ if first_edge > last_edge:
312
+ raise ValueError(
313
+ 'max must be larger than min in range parameter.')
314
+ if not (np.isfinite(first_edge) and np.isfinite(last_edge)):
315
+ raise ValueError(
316
+ "supplied range of [{}, {}] is not finite".format(first_edge, last_edge))
317
+ elif a.size == 0:
318
+ # handle empty arrays. Can't determine range, so use 0-1.
319
+ first_edge, last_edge = 0, 1
320
+ else:
321
+ first_edge, last_edge = a.min(), a.max()
322
+ if not (np.isfinite(first_edge) and np.isfinite(last_edge)):
323
+ raise ValueError(
324
+ "autodetected range of [{}, {}] is not finite".format(first_edge, last_edge))
325
+
326
+ # expand empty range to avoid divide by zero
327
+ if first_edge == last_edge:
328
+ first_edge = first_edge - 0.5
329
+ last_edge = last_edge + 0.5
330
+
331
+ return first_edge, last_edge
332
+
333
+
334
+ def _unsigned_subtract(a, b):
335
+ """
336
+ Subtract two values where a >= b, and produce an unsigned result
337
+
338
+ This is needed when finding the difference between the upper and lower
339
+ bound of an int16 histogram
340
+ """
341
+ # coerce to a single type
342
+ signed_to_unsigned = {
343
+ np.byte: np.ubyte,
344
+ np.short: np.ushort,
345
+ np.intc: np.uintc,
346
+ np.int_: np.uint,
347
+ np.longlong: np.ulonglong
348
+ }
349
+ dt = np.result_type(a, b)
350
+ try:
351
+ dt = signed_to_unsigned[dt.type]
352
+ except KeyError:
353
+ return np.subtract(a, b, dtype=dt)
354
+ else:
355
+ # we know the inputs are integers, and we are deliberately casting
356
+ # signed to unsigned
357
+ return np.subtract(a, b, casting='unsafe', dtype=dt)
358
+
359
+
360
+ def _get_bin_edges(a, bins, range, weights):
361
+ """
362
+ Computes the bins used internally by `histogram`.
363
+
364
+ Parameters
365
+ ==========
366
+ a : ndarray
367
+ Ravelled data array
368
+ bins, range
369
+ Forwarded arguments from `histogram`.
370
+ weights : ndarray, optional
371
+ Ravelled weights array, or None
372
+
373
+ Returns
374
+ =======
375
+ bin_edges : ndarray
376
+ Array of bin edges
377
+ uniform_bins : (Number, Number, int):
378
+ The upper bound, lowerbound, and number of bins, used in the optimized
379
+ implementation of `histogram` that works on uniform bins.
380
+ """
381
+ # parse the overloaded bins argument
382
+ n_equal_bins = None
383
+ bin_edges = None
384
+
385
+ if isinstance(bins, str):
386
+ bin_name = bins
387
+ # if `bins` is a string for an automatic method,
388
+ # this will replace it with the number of bins calculated
389
+ if bin_name not in _hist_bin_selectors:
390
+ raise ValueError(
391
+ "{!r} is not a valid estimator for `bins`".format(bin_name))
392
+ if weights is not None:
393
+ raise TypeError("Automated estimation of the number of "
394
+ "bins is not supported for weighted data")
395
+
396
+ first_edge, last_edge = _get_outer_edges(a, range)
397
+
398
+ # truncate the range if needed
399
+ if range is not None:
400
+ keep = (a >= first_edge)
401
+ keep &= (a <= last_edge)
402
+ if not np.logical_and.reduce(keep):
403
+ a = a[keep]
404
+
405
+ if a.size == 0:
406
+ n_equal_bins = 1
407
+ else:
408
+ # Do not call selectors on empty arrays
409
+ width = _hist_bin_selectors[bin_name](a, (first_edge, last_edge))
410
+ if width:
411
+ n_equal_bins = int(np.ceil(_unsigned_subtract(last_edge, first_edge) / width))
412
+ else:
413
+ # Width can be zero for some estimators, e.g. FD when
414
+ # the IQR of the data is zero.
415
+ n_equal_bins = 1
416
+
417
+ elif np.ndim(bins) == 0:
418
+ try:
419
+ n_equal_bins = operator.index(bins)
420
+ except TypeError as e:
421
+ raise TypeError(
422
+ '`bins` must be an integer, a string, or an array') from e
423
+ if n_equal_bins < 1:
424
+ raise ValueError('`bins` must be positive, when an integer')
425
+
426
+ first_edge, last_edge = _get_outer_edges(a, range)
427
+
428
+ elif np.ndim(bins) == 1:
429
+ bin_edges = np.asarray(bins)
430
+ if np.any(bin_edges[:-1] > bin_edges[1:]):
431
+ raise ValueError(
432
+ '`bins` must increase monotonically, when an array')
433
+
434
+ else:
435
+ raise ValueError('`bins` must be 1d, when an array')
436
+
437
+ if n_equal_bins is not None:
438
+ # gh-10322 means that type resolution rules are dependent on array
439
+ # shapes. To avoid this causing problems, we pick a type now and stick
440
+ # with it throughout.
441
+ bin_type = np.result_type(first_edge, last_edge, a)
442
+ if np.issubdtype(bin_type, np.integer):
443
+ bin_type = np.result_type(bin_type, float)
444
+
445
+ # bin edges must be computed
446
+ bin_edges = np.linspace(
447
+ first_edge, last_edge, n_equal_bins + 1,
448
+ endpoint=True, dtype=bin_type)
449
+ return bin_edges, (first_edge, last_edge, n_equal_bins)
450
+ else:
451
+ return bin_edges, None
452
+
453
+
454
+ def _search_sorted_inclusive(a, v):
455
+ """
456
+ Like `searchsorted`, but where the last item in `v` is placed on the right.
457
+
458
+ In the context of a histogram, this makes the last bin edge inclusive
459
+ """
460
+ return np.concatenate((
461
+ a.searchsorted(v[:-1], 'left'),
462
+ a.searchsorted(v[-1:], 'right')
463
+ ))
464
+
465
+
466
+ def _histogram_bin_edges_dispatcher(a, bins=None, range=None, weights=None):
467
+ return (a, bins, weights)
468
+
469
+
470
+ @array_function_dispatch(_histogram_bin_edges_dispatcher)
471
+ def histogram_bin_edges(a, bins=10, range=None, weights=None):
472
+ r"""
473
+ Function to calculate only the edges of the bins used by the `histogram`
474
+ function.
475
+
476
+ Parameters
477
+ ----------
478
+ a : array_like
479
+ Input data. The histogram is computed over the flattened array.
480
+ bins : int or sequence of scalars or str, optional
481
+ If `bins` is an int, it defines the number of equal-width
482
+ bins in the given range (10, by default). If `bins` is a
483
+ sequence, it defines the bin edges, including the rightmost
484
+ edge, allowing for non-uniform bin widths.
485
+
486
+ If `bins` is a string from the list below, `histogram_bin_edges` will use
487
+ the method chosen to calculate the optimal bin width and
488
+ consequently the number of bins (see `Notes` for more detail on
489
+ the estimators) from the data that falls within the requested
490
+ range. While the bin width will be optimal for the actual data
491
+ in the range, the number of bins will be computed to fill the
492
+ entire range, including the empty portions. For visualisation,
493
+ using the 'auto' option is suggested. Weighted data is not
494
+ supported for automated bin size selection.
495
+
496
+ 'auto'
497
+ Maximum of the 'sturges' and 'fd' estimators. Provides good
498
+ all around performance.
499
+
500
+ 'fd' (Freedman Diaconis Estimator)
501
+ Robust (resilient to outliers) estimator that takes into
502
+ account data variability and data size.
503
+
504
+ 'doane'
505
+ An improved version of Sturges' estimator that works better
506
+ with non-normal datasets.
507
+
508
+ 'scott'
509
+ Less robust estimator that takes into account data variability
510
+ and data size.
511
+
512
+ 'stone'
513
+ Estimator based on leave-one-out cross-validation estimate of
514
+ the integrated squared error. Can be regarded as a generalization
515
+ of Scott's rule.
516
+
517
+ 'rice'
518
+ Estimator does not take variability into account, only data
519
+ size. Commonly overestimates number of bins required.
520
+
521
+ 'sturges'
522
+ R's default method, only accounts for data size. Only
523
+ optimal for gaussian data and underestimates number of bins
524
+ for large non-gaussian datasets.
525
+
526
+ 'sqrt'
527
+ Square root (of data size) estimator, used by Excel and
528
+ other programs for its speed and simplicity.
529
+
530
+ range : (float, float), optional
531
+ The lower and upper range of the bins. If not provided, range
532
+ is simply ``(a.min(), a.max())``. Values outside the range are
533
+ ignored. The first element of the range must be less than or
534
+ equal to the second. `range` affects the automatic bin
535
+ computation as well. While bin width is computed to be optimal
536
+ based on the actual data within `range`, the bin count will fill
537
+ the entire range including portions containing no data.
538
+
539
+ weights : array_like, optional
540
+ An array of weights, of the same shape as `a`. Each value in
541
+ `a` only contributes its associated weight towards the bin count
542
+ (instead of 1). This is currently not used by any of the bin estimators,
543
+ but may be in the future.
544
+
545
+ Returns
546
+ -------
547
+ bin_edges : array of dtype float
548
+ The edges to pass into `histogram`
549
+
550
+ See Also
551
+ --------
552
+ histogram
553
+
554
+ Notes
555
+ -----
556
+ The methods to estimate the optimal number of bins are well founded
557
+ in literature, and are inspired by the choices R provides for
558
+ histogram visualisation. Note that having the number of bins
559
+ proportional to :math:`n^{1/3}` is asymptotically optimal, which is
560
+ why it appears in most estimators. These are simply plug-in methods
561
+ that give good starting points for number of bins. In the equations
562
+ below, :math:`h` is the binwidth and :math:`n_h` is the number of
563
+ bins. All estimators that compute bin counts are recast to bin width
564
+ using the `ptp` of the data. The final bin count is obtained from
565
+ ``np.round(np.ceil(range / h))``. The final bin width is often less
566
+ than what is returned by the estimators below.
567
+
568
+ 'auto' (maximum of the 'sturges' and 'fd' estimators)
569
+ A compromise to get a good value. For small datasets the Sturges
570
+ value will usually be chosen, while larger datasets will usually
571
+ default to FD. Avoids the overly conservative behaviour of FD
572
+ and Sturges for small and large datasets respectively.
573
+ Switchover point is usually :math:`a.size \approx 1000`.
574
+
575
+ 'fd' (Freedman Diaconis Estimator)
576
+ .. math:: h = 2 \frac{IQR}{n^{1/3}}
577
+
578
+ The binwidth is proportional to the interquartile range (IQR)
579
+ and inversely proportional to cube root of a.size. Can be too
580
+ conservative for small datasets, but is quite good for large
581
+ datasets. The IQR is very robust to outliers.
582
+
583
+ 'scott'
584
+ .. math:: h = \sigma \sqrt[3]{\frac{24 \sqrt{\pi}}{n}}
585
+
586
+ The binwidth is proportional to the standard deviation of the
587
+ data and inversely proportional to cube root of ``x.size``. Can
588
+ be too conservative for small datasets, but is quite good for
589
+ large datasets. The standard deviation is not very robust to
590
+ outliers. Values are very similar to the Freedman-Diaconis
591
+ estimator in the absence of outliers.
592
+
593
+ 'rice'
594
+ .. math:: n_h = 2n^{1/3}
595
+
596
+ The number of bins is only proportional to cube root of
597
+ ``a.size``. It tends to overestimate the number of bins and it
598
+ does not take into account data variability.
599
+
600
+ 'sturges'
601
+ .. math:: n_h = \log _{2}(n) + 1
602
+
603
+ The number of bins is the base 2 log of ``a.size``. This
604
+ estimator assumes normality of data and is too conservative for
605
+ larger, non-normal datasets. This is the default method in R's
606
+ ``hist`` method.
607
+
608
+ 'doane'
609
+ .. math:: n_h = 1 + \log_{2}(n) +
610
+ \log_{2}\left(1 + \frac{|g_1|}{\sigma_{g_1}}\right)
611
+
612
+ g_1 = mean\left[\left(\frac{x - \mu}{\sigma}\right)^3\right]
613
+
614
+ \sigma_{g_1} = \sqrt{\frac{6(n - 2)}{(n + 1)(n + 3)}}
615
+
616
+ An improved version of Sturges' formula that produces better
617
+ estimates for non-normal datasets. This estimator attempts to
618
+ account for the skew of the data.
619
+
620
+ 'sqrt'
621
+ .. math:: n_h = \sqrt n
622
+
623
+ The simplest and fastest estimator. Only takes into account the
624
+ data size.
625
+
626
+ Examples
627
+ --------
628
+ >>> arr = np.array([0, 0, 0, 1, 2, 3, 3, 4, 5])
629
+ >>> np.histogram_bin_edges(arr, bins='auto', range=(0, 1))
630
+ array([0. , 0.25, 0.5 , 0.75, 1. ])
631
+ >>> np.histogram_bin_edges(arr, bins=2)
632
+ array([0. , 2.5, 5. ])
633
+
634
+ For consistency with histogram, an array of pre-computed bins is
635
+ passed through unmodified:
636
+
637
+ >>> np.histogram_bin_edges(arr, [1, 2])
638
+ array([1, 2])
639
+
640
+ This function allows one set of bins to be computed, and reused across
641
+ multiple histograms:
642
+
643
+ >>> shared_bins = np.histogram_bin_edges(arr, bins='auto')
644
+ >>> shared_bins
645
+ array([0., 1., 2., 3., 4., 5.])
646
+
647
+ >>> group_id = np.array([0, 1, 1, 0, 1, 1, 0, 1, 1])
648
+ >>> hist_0, _ = np.histogram(arr[group_id == 0], bins=shared_bins)
649
+ >>> hist_1, _ = np.histogram(arr[group_id == 1], bins=shared_bins)
650
+
651
+ >>> hist_0; hist_1
652
+ array([1, 1, 0, 1, 0])
653
+ array([2, 0, 1, 1, 2])
654
+
655
+ Which gives more easily comparable results than using separate bins for
656
+ each histogram:
657
+
658
+ >>> hist_0, bins_0 = np.histogram(arr[group_id == 0], bins='auto')
659
+ >>> hist_1, bins_1 = np.histogram(arr[group_id == 1], bins='auto')
660
+ >>> hist_0; hist_1
661
+ array([1, 1, 1])
662
+ array([2, 1, 1, 2])
663
+ >>> bins_0; bins_1
664
+ array([0., 1., 2., 3.])
665
+ array([0. , 1.25, 2.5 , 3.75, 5. ])
666
+
667
+ """
668
+ a, weights = _ravel_and_check_weights(a, weights)
669
+ bin_edges, _ = _get_bin_edges(a, bins, range, weights)
670
+ return bin_edges
671
+
672
+
673
+ def _histogram_dispatcher(
674
+ a, bins=None, range=None, density=None, weights=None):
675
+ return (a, bins, weights)
676
+
677
+
678
+ @array_function_dispatch(_histogram_dispatcher)
679
+ def histogram(a, bins=10, range=None, density=None, weights=None):
680
+ r"""
681
+ Compute the histogram of a dataset.
682
+
683
+ Parameters
684
+ ----------
685
+ a : array_like
686
+ Input data. The histogram is computed over the flattened array.
687
+ bins : int or sequence of scalars or str, optional
688
+ If `bins` is an int, it defines the number of equal-width
689
+ bins in the given range (10, by default). If `bins` is a
690
+ sequence, it defines a monotonically increasing array of bin edges,
691
+ including the rightmost edge, allowing for non-uniform bin widths.
692
+
693
+ .. versionadded:: 1.11.0
694
+
695
+ If `bins` is a string, it defines the method used to calculate the
696
+ optimal bin width, as defined by `histogram_bin_edges`.
697
+
698
+ range : (float, float), optional
699
+ The lower and upper range of the bins. If not provided, range
700
+ is simply ``(a.min(), a.max())``. Values outside the range are
701
+ ignored. The first element of the range must be less than or
702
+ equal to the second. `range` affects the automatic bin
703
+ computation as well. While bin width is computed to be optimal
704
+ based on the actual data within `range`, the bin count will fill
705
+ the entire range including portions containing no data.
706
+ weights : array_like, optional
707
+ An array of weights, of the same shape as `a`. Each value in
708
+ `a` only contributes its associated weight towards the bin count
709
+ (instead of 1). If `density` is True, the weights are
710
+ normalized, so that the integral of the density over the range
711
+ remains 1.
712
+ density : bool, optional
713
+ If ``False``, the result will contain the number of samples in
714
+ each bin. If ``True``, the result is the value of the
715
+ probability *density* function at the bin, normalized such that
716
+ the *integral* over the range is 1. Note that the sum of the
717
+ histogram values will not be equal to 1 unless bins of unity
718
+ width are chosen; it is not a probability *mass* function.
719
+
720
+ Returns
721
+ -------
722
+ hist : array
723
+ The values of the histogram. See `density` and `weights` for a
724
+ description of the possible semantics.
725
+ bin_edges : array of dtype float
726
+ Return the bin edges ``(length(hist)+1)``.
727
+
728
+
729
+ See Also
730
+ --------
731
+ histogramdd, bincount, searchsorted, digitize, histogram_bin_edges
732
+
733
+ Notes
734
+ -----
735
+ All but the last (righthand-most) bin is half-open. In other words,
736
+ if `bins` is::
737
+
738
+ [1, 2, 3, 4]
739
+
740
+ then the first bin is ``[1, 2)`` (including 1, but excluding 2) and
741
+ the second ``[2, 3)``. The last bin, however, is ``[3, 4]``, which
742
+ *includes* 4.
743
+
744
+
745
+ Examples
746
+ --------
747
+ >>> np.histogram([1, 2, 1], bins=[0, 1, 2, 3])
748
+ (array([0, 2, 1]), array([0, 1, 2, 3]))
749
+ >>> np.histogram(np.arange(4), bins=np.arange(5), density=True)
750
+ (array([0.25, 0.25, 0.25, 0.25]), array([0, 1, 2, 3, 4]))
751
+ >>> np.histogram([[1, 2, 1], [1, 0, 1]], bins=[0,1,2,3])
752
+ (array([1, 4, 1]), array([0, 1, 2, 3]))
753
+
754
+ >>> a = np.arange(5)
755
+ >>> hist, bin_edges = np.histogram(a, density=True)
756
+ >>> hist
757
+ array([0.5, 0. , 0.5, 0. , 0. , 0.5, 0. , 0.5, 0. , 0.5])
758
+ >>> hist.sum()
759
+ 2.4999999999999996
760
+ >>> np.sum(hist * np.diff(bin_edges))
761
+ 1.0
762
+
763
+ .. versionadded:: 1.11.0
764
+
765
+ Automated Bin Selection Methods example, using 2 peak random data
766
+ with 2000 points:
767
+
768
+ >>> import matplotlib.pyplot as plt
769
+ >>> rng = np.random.RandomState(10) # deterministic random data
770
+ >>> a = np.hstack((rng.normal(size=1000),
771
+ ... rng.normal(loc=5, scale=2, size=1000)))
772
+ >>> _ = plt.hist(a, bins='auto') # arguments are passed to np.histogram
773
+ >>> plt.title("Histogram with 'auto' bins")
774
+ Text(0.5, 1.0, "Histogram with 'auto' bins")
775
+ >>> plt.show()
776
+
777
+ """
778
+ a, weights = _ravel_and_check_weights(a, weights)
779
+
780
+ bin_edges, uniform_bins = _get_bin_edges(a, bins, range, weights)
781
+
782
+ # Histogram is an integer or a float array depending on the weights.
783
+ if weights is None:
784
+ ntype = np.dtype(np.intp)
785
+ else:
786
+ ntype = weights.dtype
787
+
788
+ # We set a block size, as this allows us to iterate over chunks when
789
+ # computing histograms, to minimize memory usage.
790
+ BLOCK = 65536
791
+
792
+ # The fast path uses bincount, but that only works for certain types
793
+ # of weight
794
+ simple_weights = (
795
+ weights is None or
796
+ np.can_cast(weights.dtype, np.double) or
797
+ np.can_cast(weights.dtype, complex)
798
+ )
799
+
800
+ if uniform_bins is not None and simple_weights:
801
+ # Fast algorithm for equal bins
802
+ # We now convert values of a to bin indices, under the assumption of
803
+ # equal bin widths (which is valid here).
804
+ first_edge, last_edge, n_equal_bins = uniform_bins
805
+
806
+ # Initialize empty histogram
807
+ n = np.zeros(n_equal_bins, ntype)
808
+
809
+ # Pre-compute histogram scaling factor
810
+ norm_numerator = n_equal_bins
811
+ norm_denom = _unsigned_subtract(last_edge, first_edge)
812
+
813
+ # We iterate over blocks here for two reasons: the first is that for
814
+ # large arrays, it is actually faster (for example for a 10^8 array it
815
+ # is 2x as fast) and it results in a memory footprint 3x lower in the
816
+ # limit of large arrays.
817
+ for i in _range(0, len(a), BLOCK):
818
+ tmp_a = a[i:i+BLOCK]
819
+ if weights is None:
820
+ tmp_w = None
821
+ else:
822
+ tmp_w = weights[i:i + BLOCK]
823
+
824
+ # Only include values in the right range
825
+ keep = (tmp_a >= first_edge)
826
+ keep &= (tmp_a <= last_edge)
827
+ if not np.logical_and.reduce(keep):
828
+ tmp_a = tmp_a[keep]
829
+ if tmp_w is not None:
830
+ tmp_w = tmp_w[keep]
831
+
832
+ # This cast ensures no type promotions occur below, which gh-10322
833
+ # make unpredictable. Getting it wrong leads to precision errors
834
+ # like gh-8123.
835
+ tmp_a = tmp_a.astype(bin_edges.dtype, copy=False)
836
+
837
+ # Compute the bin indices, and for values that lie exactly on
838
+ # last_edge we need to subtract one
839
+ f_indices = ((_unsigned_subtract(tmp_a, first_edge) / norm_denom)
840
+ * norm_numerator)
841
+ indices = f_indices.astype(np.intp)
842
+ indices[indices == n_equal_bins] -= 1
843
+
844
+ # The index computation is not guaranteed to give exactly
845
+ # consistent results within ~1 ULP of the bin edges.
846
+ decrement = tmp_a < bin_edges[indices]
847
+ indices[decrement] -= 1
848
+ # The last bin includes the right edge. The other bins do not.
849
+ increment = ((tmp_a >= bin_edges[indices + 1])
850
+ & (indices != n_equal_bins - 1))
851
+ indices[increment] += 1
852
+
853
+ # We now compute the histogram using bincount
854
+ if ntype.kind == 'c':
855
+ n.real += np.bincount(indices, weights=tmp_w.real,
856
+ minlength=n_equal_bins)
857
+ n.imag += np.bincount(indices, weights=tmp_w.imag,
858
+ minlength=n_equal_bins)
859
+ else:
860
+ n += np.bincount(indices, weights=tmp_w,
861
+ minlength=n_equal_bins).astype(ntype)
862
+ else:
863
+ # Compute via cumulative histogram
864
+ cum_n = np.zeros(bin_edges.shape, ntype)
865
+ if weights is None:
866
+ for i in _range(0, len(a), BLOCK):
867
+ sa = np.sort(a[i:i+BLOCK])
868
+ cum_n += _search_sorted_inclusive(sa, bin_edges)
869
+ else:
870
+ zero = np.zeros(1, dtype=ntype)
871
+ for i in _range(0, len(a), BLOCK):
872
+ tmp_a = a[i:i+BLOCK]
873
+ tmp_w = weights[i:i+BLOCK]
874
+ sorting_index = np.argsort(tmp_a)
875
+ sa = tmp_a[sorting_index]
876
+ sw = tmp_w[sorting_index]
877
+ cw = np.concatenate((zero, sw.cumsum()))
878
+ bin_index = _search_sorted_inclusive(sa, bin_edges)
879
+ cum_n += cw[bin_index]
880
+
881
+ n = np.diff(cum_n)
882
+
883
+ if density:
884
+ db = np.array(np.diff(bin_edges), float)
885
+ return n/db/n.sum(), bin_edges
886
+
887
+ return n, bin_edges
888
+
889
+
890
+ def _histogramdd_dispatcher(sample, bins=None, range=None, density=None,
891
+ weights=None):
892
+ if hasattr(sample, 'shape'): # same condition as used in histogramdd
893
+ yield sample
894
+ else:
895
+ yield from sample
896
+ with contextlib.suppress(TypeError):
897
+ yield from bins
898
+ yield weights
899
+
900
+
901
+ @array_function_dispatch(_histogramdd_dispatcher)
902
+ def histogramdd(sample, bins=10, range=None, density=None, weights=None):
903
+ """
904
+ Compute the multidimensional histogram of some data.
905
+
906
+ Parameters
907
+ ----------
908
+ sample : (N, D) array, or (N, D) array_like
909
+ The data to be histogrammed.
910
+
911
+ Note the unusual interpretation of sample when an array_like:
912
+
913
+ * When an array, each row is a coordinate in a D-dimensional space -
914
+ such as ``histogramdd(np.array([p1, p2, p3]))``.
915
+ * When an array_like, each element is the list of values for single
916
+ coordinate - such as ``histogramdd((X, Y, Z))``.
917
+
918
+ The first form should be preferred.
919
+
920
+ bins : sequence or int, optional
921
+ The bin specification:
922
+
923
+ * A sequence of arrays describing the monotonically increasing bin
924
+ edges along each dimension.
925
+ * The number of bins for each dimension (nx, ny, ... =bins)
926
+ * The number of bins for all dimensions (nx=ny=...=bins).
927
+
928
+ range : sequence, optional
929
+ A sequence of length D, each an optional (lower, upper) tuple giving
930
+ the outer bin edges to be used if the edges are not given explicitly in
931
+ `bins`.
932
+ An entry of None in the sequence results in the minimum and maximum
933
+ values being used for the corresponding dimension.
934
+ The default, None, is equivalent to passing a tuple of D None values.
935
+ density : bool, optional
936
+ If False, the default, returns the number of samples in each bin.
937
+ If True, returns the probability *density* function at the bin,
938
+ ``bin_count / sample_count / bin_volume``.
939
+ weights : (N,) array_like, optional
940
+ An array of values `w_i` weighing each sample `(x_i, y_i, z_i, ...)`.
941
+ Weights are normalized to 1 if density is True. If density is False,
942
+ the values of the returned histogram are equal to the sum of the
943
+ weights belonging to the samples falling into each bin.
944
+
945
+ Returns
946
+ -------
947
+ H : ndarray
948
+ The multidimensional histogram of sample x. See density and weights
949
+ for the different possible semantics.
950
+ edges : list
951
+ A list of D arrays describing the bin edges for each dimension.
952
+
953
+ See Also
954
+ --------
955
+ histogram: 1-D histogram
956
+ histogram2d: 2-D histogram
957
+
958
+ Examples
959
+ --------
960
+ >>> r = np.random.randn(100,3)
961
+ >>> H, edges = np.histogramdd(r, bins = (5, 8, 4))
962
+ >>> H.shape, edges[0].size, edges[1].size, edges[2].size
963
+ ((5, 8, 4), 6, 9, 5)
964
+
965
+ """
966
+
967
+ try:
968
+ # Sample is an ND-array.
969
+ N, D = sample.shape
970
+ except (AttributeError, ValueError):
971
+ # Sample is a sequence of 1D arrays.
972
+ sample = np.atleast_2d(sample).T
973
+ N, D = sample.shape
974
+
975
+ nbin = np.empty(D, np.intp)
976
+ edges = D*[None]
977
+ dedges = D*[None]
978
+ if weights is not None:
979
+ weights = np.asarray(weights)
980
+
981
+ try:
982
+ M = len(bins)
983
+ if M != D:
984
+ raise ValueError(
985
+ 'The dimension of bins must be equal to the dimension of the '
986
+ 'sample x.')
987
+ except TypeError:
988
+ # bins is an integer
989
+ bins = D*[bins]
990
+
991
+ # normalize the range argument
992
+ if range is None:
993
+ range = (None,) * D
994
+ elif len(range) != D:
995
+ raise ValueError('range argument must have one entry per dimension')
996
+
997
+ # Create edge arrays
998
+ for i in _range(D):
999
+ if np.ndim(bins[i]) == 0:
1000
+ if bins[i] < 1:
1001
+ raise ValueError(
1002
+ '`bins[{}]` must be positive, when an integer'.format(i))
1003
+ smin, smax = _get_outer_edges(sample[:,i], range[i])
1004
+ try:
1005
+ n = operator.index(bins[i])
1006
+
1007
+ except TypeError as e:
1008
+ raise TypeError(
1009
+ "`bins[{}]` must be an integer, when a scalar".format(i)
1010
+ ) from e
1011
+
1012
+ edges[i] = np.linspace(smin, smax, n + 1)
1013
+ elif np.ndim(bins[i]) == 1:
1014
+ edges[i] = np.asarray(bins[i])
1015
+ if np.any(edges[i][:-1] > edges[i][1:]):
1016
+ raise ValueError(
1017
+ '`bins[{}]` must be monotonically increasing, when an array'
1018
+ .format(i))
1019
+ else:
1020
+ raise ValueError(
1021
+ '`bins[{}]` must be a scalar or 1d array'.format(i))
1022
+
1023
+ nbin[i] = len(edges[i]) + 1 # includes an outlier on each end
1024
+ dedges[i] = np.diff(edges[i])
1025
+
1026
+ # Compute the bin number each sample falls into.
1027
+ Ncount = tuple(
1028
+ # avoid np.digitize to work around gh-11022
1029
+ np.searchsorted(edges[i], sample[:, i], side='right')
1030
+ for i in _range(D)
1031
+ )
1032
+
1033
+ # Using digitize, values that fall on an edge are put in the right bin.
1034
+ # For the rightmost bin, we want values equal to the right edge to be
1035
+ # counted in the last bin, and not as an outlier.
1036
+ for i in _range(D):
1037
+ # Find which points are on the rightmost edge.
1038
+ on_edge = (sample[:, i] == edges[i][-1])
1039
+ # Shift these points one bin to the left.
1040
+ Ncount[i][on_edge] -= 1
1041
+
1042
+ # Compute the sample indices in the flattened histogram matrix.
1043
+ # This raises an error if the array is too large.
1044
+ xy = np.ravel_multi_index(Ncount, nbin)
1045
+
1046
+ # Compute the number of repetitions in xy and assign it to the
1047
+ # flattened histmat.
1048
+ hist = np.bincount(xy, weights, minlength=nbin.prod())
1049
+
1050
+ # Shape into a proper matrix
1051
+ hist = hist.reshape(nbin)
1052
+
1053
+ # This preserves the (bad) behavior observed in gh-7845, for now.
1054
+ hist = hist.astype(float, casting='safe')
1055
+
1056
+ # Remove outliers (indices 0 and -1 for each dimension).
1057
+ core = D*(slice(1, -1),)
1058
+ hist = hist[core]
1059
+
1060
+ if density:
1061
+ # calculate the probability density function
1062
+ s = hist.sum()
1063
+ for i in _range(D):
1064
+ shape = np.ones(D, int)
1065
+ shape[i] = nbin[i] - 2
1066
+ hist = hist / dedges[i].reshape(shape)
1067
+ hist /= s
1068
+
1069
+ if (hist.shape != nbin - 2).any():
1070
+ raise RuntimeError(
1071
+ "Internal Shape Error")
1072
+ return hist, edges
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/index_tricks.py ADDED
@@ -0,0 +1,1046 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import functools
2
+ import sys
3
+ import math
4
+ import warnings
5
+
6
+ import numpy as np
7
+ from .._utils import set_module
8
+ import numpy.core.numeric as _nx
9
+ from numpy.core.numeric import ScalarType, array
10
+ from numpy.core.numerictypes import issubdtype
11
+
12
+ import numpy.matrixlib as matrixlib
13
+ from .function_base import diff
14
+ from numpy.core.multiarray import ravel_multi_index, unravel_index
15
+ from numpy.core import overrides, linspace
16
+ from numpy.lib.stride_tricks import as_strided
17
+
18
+
19
+ array_function_dispatch = functools.partial(
20
+ overrides.array_function_dispatch, module='numpy')
21
+
22
+
23
+ __all__ = [
24
+ 'ravel_multi_index', 'unravel_index', 'mgrid', 'ogrid', 'r_', 'c_',
25
+ 's_', 'index_exp', 'ix_', 'ndenumerate', 'ndindex', 'fill_diagonal',
26
+ 'diag_indices', 'diag_indices_from'
27
+ ]
28
+
29
+
30
+ def _ix__dispatcher(*args):
31
+ return args
32
+
33
+
34
+ @array_function_dispatch(_ix__dispatcher)
35
+ def ix_(*args):
36
+ """
37
+ Construct an open mesh from multiple sequences.
38
+
39
+ This function takes N 1-D sequences and returns N outputs with N
40
+ dimensions each, such that the shape is 1 in all but one dimension
41
+ and the dimension with the non-unit shape value cycles through all
42
+ N dimensions.
43
+
44
+ Using `ix_` one can quickly construct index arrays that will index
45
+ the cross product. ``a[np.ix_([1,3],[2,5])]`` returns the array
46
+ ``[[a[1,2] a[1,5]], [a[3,2] a[3,5]]]``.
47
+
48
+ Parameters
49
+ ----------
50
+ args : 1-D sequences
51
+ Each sequence should be of integer or boolean type.
52
+ Boolean sequences will be interpreted as boolean masks for the
53
+ corresponding dimension (equivalent to passing in
54
+ ``np.nonzero(boolean_sequence)``).
55
+
56
+ Returns
57
+ -------
58
+ out : tuple of ndarrays
59
+ N arrays with N dimensions each, with N the number of input
60
+ sequences. Together these arrays form an open mesh.
61
+
62
+ See Also
63
+ --------
64
+ ogrid, mgrid, meshgrid
65
+
66
+ Examples
67
+ --------
68
+ >>> a = np.arange(10).reshape(2, 5)
69
+ >>> a
70
+ array([[0, 1, 2, 3, 4],
71
+ [5, 6, 7, 8, 9]])
72
+ >>> ixgrid = np.ix_([0, 1], [2, 4])
73
+ >>> ixgrid
74
+ (array([[0],
75
+ [1]]), array([[2, 4]]))
76
+ >>> ixgrid[0].shape, ixgrid[1].shape
77
+ ((2, 1), (1, 2))
78
+ >>> a[ixgrid]
79
+ array([[2, 4],
80
+ [7, 9]])
81
+
82
+ >>> ixgrid = np.ix_([True, True], [2, 4])
83
+ >>> a[ixgrid]
84
+ array([[2, 4],
85
+ [7, 9]])
86
+ >>> ixgrid = np.ix_([True, True], [False, False, True, False, True])
87
+ >>> a[ixgrid]
88
+ array([[2, 4],
89
+ [7, 9]])
90
+
91
+ """
92
+ out = []
93
+ nd = len(args)
94
+ for k, new in enumerate(args):
95
+ if not isinstance(new, _nx.ndarray):
96
+ new = np.asarray(new)
97
+ if new.size == 0:
98
+ # Explicitly type empty arrays to avoid float default
99
+ new = new.astype(_nx.intp)
100
+ if new.ndim != 1:
101
+ raise ValueError("Cross index must be 1 dimensional")
102
+ if issubdtype(new.dtype, _nx.bool_):
103
+ new, = new.nonzero()
104
+ new = new.reshape((1,)*k + (new.size,) + (1,)*(nd-k-1))
105
+ out.append(new)
106
+ return tuple(out)
107
+
108
+
109
+ class nd_grid:
110
+ """
111
+ Construct a multi-dimensional "meshgrid".
112
+
113
+ ``grid = nd_grid()`` creates an instance which will return a mesh-grid
114
+ when indexed. The dimension and number of the output arrays are equal
115
+ to the number of indexing dimensions. If the step length is not a
116
+ complex number, then the stop is not inclusive.
117
+
118
+ However, if the step length is a **complex number** (e.g. 5j), then the
119
+ integer part of its magnitude is interpreted as specifying the
120
+ number of points to create between the start and stop values, where
121
+ the stop value **is inclusive**.
122
+
123
+ If instantiated with an argument of ``sparse=True``, the mesh-grid is
124
+ open (or not fleshed out) so that only one-dimension of each returned
125
+ argument is greater than 1.
126
+
127
+ Parameters
128
+ ----------
129
+ sparse : bool, optional
130
+ Whether the grid is sparse or not. Default is False.
131
+
132
+ Notes
133
+ -----
134
+ Two instances of `nd_grid` are made available in the NumPy namespace,
135
+ `mgrid` and `ogrid`, approximately defined as::
136
+
137
+ mgrid = nd_grid(sparse=False)
138
+ ogrid = nd_grid(sparse=True)
139
+
140
+ Users should use these pre-defined instances instead of using `nd_grid`
141
+ directly.
142
+ """
143
+
144
+ def __init__(self, sparse=False):
145
+ self.sparse = sparse
146
+
147
+ def __getitem__(self, key):
148
+ try:
149
+ size = []
150
+ # Mimic the behavior of `np.arange` and use a data type
151
+ # which is at least as large as `np.int_`
152
+ num_list = [0]
153
+ for k in range(len(key)):
154
+ step = key[k].step
155
+ start = key[k].start
156
+ stop = key[k].stop
157
+ if start is None:
158
+ start = 0
159
+ if step is None:
160
+ step = 1
161
+ if isinstance(step, (_nx.complexfloating, complex)):
162
+ step = abs(step)
163
+ size.append(int(step))
164
+ else:
165
+ size.append(
166
+ int(math.ceil((stop - start) / (step*1.0))))
167
+ num_list += [start, stop, step]
168
+ typ = _nx.result_type(*num_list)
169
+ if self.sparse:
170
+ nn = [_nx.arange(_x, dtype=_t)
171
+ for _x, _t in zip(size, (typ,)*len(size))]
172
+ else:
173
+ nn = _nx.indices(size, typ)
174
+ for k, kk in enumerate(key):
175
+ step = kk.step
176
+ start = kk.start
177
+ if start is None:
178
+ start = 0
179
+ if step is None:
180
+ step = 1
181
+ if isinstance(step, (_nx.complexfloating, complex)):
182
+ step = int(abs(step))
183
+ if step != 1:
184
+ step = (kk.stop - start) / float(step - 1)
185
+ nn[k] = (nn[k]*step+start)
186
+ if self.sparse:
187
+ slobj = [_nx.newaxis]*len(size)
188
+ for k in range(len(size)):
189
+ slobj[k] = slice(None, None)
190
+ nn[k] = nn[k][tuple(slobj)]
191
+ slobj[k] = _nx.newaxis
192
+ return nn
193
+ except (IndexError, TypeError):
194
+ step = key.step
195
+ stop = key.stop
196
+ start = key.start
197
+ if start is None:
198
+ start = 0
199
+ if isinstance(step, (_nx.complexfloating, complex)):
200
+ # Prevent the (potential) creation of integer arrays
201
+ step_float = abs(step)
202
+ step = length = int(step_float)
203
+ if step != 1:
204
+ step = (key.stop-start)/float(step-1)
205
+ typ = _nx.result_type(start, stop, step_float)
206
+ return _nx.arange(0, length, 1, dtype=typ)*step + start
207
+ else:
208
+ return _nx.arange(start, stop, step)
209
+
210
+
211
+ class MGridClass(nd_grid):
212
+ """
213
+ An instance which returns a dense multi-dimensional "meshgrid".
214
+
215
+ An instance which returns a dense (or fleshed out) mesh-grid
216
+ when indexed, so that each returned argument has the same shape.
217
+ The dimensions and number of the output arrays are equal to the
218
+ number of indexing dimensions. If the step length is not a complex
219
+ number, then the stop is not inclusive.
220
+
221
+ However, if the step length is a **complex number** (e.g. 5j), then
222
+ the integer part of its magnitude is interpreted as specifying the
223
+ number of points to create between the start and stop values, where
224
+ the stop value **is inclusive**.
225
+
226
+ Returns
227
+ -------
228
+ mesh-grid `ndarrays` all of the same dimensions
229
+
230
+ See Also
231
+ --------
232
+ ogrid : like `mgrid` but returns open (not fleshed out) mesh grids
233
+ meshgrid: return coordinate matrices from coordinate vectors
234
+ r_ : array concatenator
235
+ :ref:`how-to-partition`
236
+
237
+ Examples
238
+ --------
239
+ >>> np.mgrid[0:5, 0:5]
240
+ array([[[0, 0, 0, 0, 0],
241
+ [1, 1, 1, 1, 1],
242
+ [2, 2, 2, 2, 2],
243
+ [3, 3, 3, 3, 3],
244
+ [4, 4, 4, 4, 4]],
245
+ [[0, 1, 2, 3, 4],
246
+ [0, 1, 2, 3, 4],
247
+ [0, 1, 2, 3, 4],
248
+ [0, 1, 2, 3, 4],
249
+ [0, 1, 2, 3, 4]]])
250
+ >>> np.mgrid[-1:1:5j]
251
+ array([-1. , -0.5, 0. , 0.5, 1. ])
252
+
253
+ """
254
+
255
+ def __init__(self):
256
+ super().__init__(sparse=False)
257
+
258
+
259
+ mgrid = MGridClass()
260
+
261
+
262
+ class OGridClass(nd_grid):
263
+ """
264
+ An instance which returns an open multi-dimensional "meshgrid".
265
+
266
+ An instance which returns an open (i.e. not fleshed out) mesh-grid
267
+ when indexed, so that only one dimension of each returned array is
268
+ greater than 1. The dimension and number of the output arrays are
269
+ equal to the number of indexing dimensions. If the step length is
270
+ not a complex number, then the stop is not inclusive.
271
+
272
+ However, if the step length is a **complex number** (e.g. 5j), then
273
+ the integer part of its magnitude is interpreted as specifying the
274
+ number of points to create between the start and stop values, where
275
+ the stop value **is inclusive**.
276
+
277
+ Returns
278
+ -------
279
+ mesh-grid
280
+ `ndarrays` with only one dimension not equal to 1
281
+
282
+ See Also
283
+ --------
284
+ mgrid : like `ogrid` but returns dense (or fleshed out) mesh grids
285
+ meshgrid: return coordinate matrices from coordinate vectors
286
+ r_ : array concatenator
287
+ :ref:`how-to-partition`
288
+
289
+ Examples
290
+ --------
291
+ >>> from numpy import ogrid
292
+ >>> ogrid[-1:1:5j]
293
+ array([-1. , -0.5, 0. , 0.5, 1. ])
294
+ >>> ogrid[0:5,0:5]
295
+ [array([[0],
296
+ [1],
297
+ [2],
298
+ [3],
299
+ [4]]), array([[0, 1, 2, 3, 4]])]
300
+
301
+ """
302
+
303
+ def __init__(self):
304
+ super().__init__(sparse=True)
305
+
306
+
307
+ ogrid = OGridClass()
308
+
309
+
310
+ class AxisConcatenator:
311
+ """
312
+ Translates slice objects to concatenation along an axis.
313
+
314
+ For detailed documentation on usage, see `r_`.
315
+ """
316
+ # allow ma.mr_ to override this
317
+ concatenate = staticmethod(_nx.concatenate)
318
+ makemat = staticmethod(matrixlib.matrix)
319
+
320
+ def __init__(self, axis=0, matrix=False, ndmin=1, trans1d=-1):
321
+ self.axis = axis
322
+ self.matrix = matrix
323
+ self.trans1d = trans1d
324
+ self.ndmin = ndmin
325
+
326
+ def __getitem__(self, key):
327
+ # handle matrix builder syntax
328
+ if isinstance(key, str):
329
+ frame = sys._getframe().f_back
330
+ mymat = matrixlib.bmat(key, frame.f_globals, frame.f_locals)
331
+ return mymat
332
+
333
+ if not isinstance(key, tuple):
334
+ key = (key,)
335
+
336
+ # copy attributes, since they can be overridden in the first argument
337
+ trans1d = self.trans1d
338
+ ndmin = self.ndmin
339
+ matrix = self.matrix
340
+ axis = self.axis
341
+
342
+ objs = []
343
+ # dtypes or scalars for weak scalar handling in result_type
344
+ result_type_objs = []
345
+
346
+ for k, item in enumerate(key):
347
+ scalar = False
348
+ if isinstance(item, slice):
349
+ step = item.step
350
+ start = item.start
351
+ stop = item.stop
352
+ if start is None:
353
+ start = 0
354
+ if step is None:
355
+ step = 1
356
+ if isinstance(step, (_nx.complexfloating, complex)):
357
+ size = int(abs(step))
358
+ newobj = linspace(start, stop, num=size)
359
+ else:
360
+ newobj = _nx.arange(start, stop, step)
361
+ if ndmin > 1:
362
+ newobj = array(newobj, copy=False, ndmin=ndmin)
363
+ if trans1d != -1:
364
+ newobj = newobj.swapaxes(-1, trans1d)
365
+ elif isinstance(item, str):
366
+ if k != 0:
367
+ raise ValueError("special directives must be the "
368
+ "first entry.")
369
+ if item in ('r', 'c'):
370
+ matrix = True
371
+ col = (item == 'c')
372
+ continue
373
+ if ',' in item:
374
+ vec = item.split(',')
375
+ try:
376
+ axis, ndmin = [int(x) for x in vec[:2]]
377
+ if len(vec) == 3:
378
+ trans1d = int(vec[2])
379
+ continue
380
+ except Exception as e:
381
+ raise ValueError(
382
+ "unknown special directive {!r}".format(item)
383
+ ) from e
384
+ try:
385
+ axis = int(item)
386
+ continue
387
+ except (ValueError, TypeError) as e:
388
+ raise ValueError("unknown special directive") from e
389
+ elif type(item) in ScalarType:
390
+ scalar = True
391
+ newobj = item
392
+ else:
393
+ item_ndim = np.ndim(item)
394
+ newobj = array(item, copy=False, subok=True, ndmin=ndmin)
395
+ if trans1d != -1 and item_ndim < ndmin:
396
+ k2 = ndmin - item_ndim
397
+ k1 = trans1d
398
+ if k1 < 0:
399
+ k1 += k2 + 1
400
+ defaxes = list(range(ndmin))
401
+ axes = defaxes[:k1] + defaxes[k2:] + defaxes[k1:k2]
402
+ newobj = newobj.transpose(axes)
403
+
404
+ objs.append(newobj)
405
+ if scalar:
406
+ result_type_objs.append(item)
407
+ else:
408
+ result_type_objs.append(newobj.dtype)
409
+
410
+ # Ensure that scalars won't up-cast unless warranted, for 0, drops
411
+ # through to error in concatenate.
412
+ if len(result_type_objs) != 0:
413
+ final_dtype = _nx.result_type(*result_type_objs)
414
+ # concatenate could do cast, but that can be overriden:
415
+ objs = [array(obj, copy=False, subok=True,
416
+ ndmin=ndmin, dtype=final_dtype) for obj in objs]
417
+
418
+ res = self.concatenate(tuple(objs), axis=axis)
419
+
420
+ if matrix:
421
+ oldndim = res.ndim
422
+ res = self.makemat(res)
423
+ if oldndim == 1 and col:
424
+ res = res.T
425
+ return res
426
+
427
+ def __len__(self):
428
+ return 0
429
+
430
+ # separate classes are used here instead of just making r_ = concatentor(0),
431
+ # etc. because otherwise we couldn't get the doc string to come out right
432
+ # in help(r_)
433
+
434
+
435
+ class RClass(AxisConcatenator):
436
+ """
437
+ Translates slice objects to concatenation along the first axis.
438
+
439
+ This is a simple way to build up arrays quickly. There are two use cases.
440
+
441
+ 1. If the index expression contains comma separated arrays, then stack
442
+ them along their first axis.
443
+ 2. If the index expression contains slice notation or scalars then create
444
+ a 1-D array with a range indicated by the slice notation.
445
+
446
+ If slice notation is used, the syntax ``start:stop:step`` is equivalent
447
+ to ``np.arange(start, stop, step)`` inside of the brackets. However, if
448
+ ``step`` is an imaginary number (i.e. 100j) then its integer portion is
449
+ interpreted as a number-of-points desired and the start and stop are
450
+ inclusive. In other words ``start:stop:stepj`` is interpreted as
451
+ ``np.linspace(start, stop, step, endpoint=1)`` inside of the brackets.
452
+ After expansion of slice notation, all comma separated sequences are
453
+ concatenated together.
454
+
455
+ Optional character strings placed as the first element of the index
456
+ expression can be used to change the output. The strings 'r' or 'c' result
457
+ in matrix output. If the result is 1-D and 'r' is specified a 1 x N (row)
458
+ matrix is produced. If the result is 1-D and 'c' is specified, then a N x 1
459
+ (column) matrix is produced. If the result is 2-D then both provide the
460
+ same matrix result.
461
+
462
+ A string integer specifies which axis to stack multiple comma separated
463
+ arrays along. A string of two comma-separated integers allows indication
464
+ of the minimum number of dimensions to force each entry into as the
465
+ second integer (the axis to concatenate along is still the first integer).
466
+
467
+ A string with three comma-separated integers allows specification of the
468
+ axis to concatenate along, the minimum number of dimensions to force the
469
+ entries to, and which axis should contain the start of the arrays which
470
+ are less than the specified number of dimensions. In other words the third
471
+ integer allows you to specify where the 1's should be placed in the shape
472
+ of the arrays that have their shapes upgraded. By default, they are placed
473
+ in the front of the shape tuple. The third argument allows you to specify
474
+ where the start of the array should be instead. Thus, a third argument of
475
+ '0' would place the 1's at the end of the array shape. Negative integers
476
+ specify where in the new shape tuple the last dimension of upgraded arrays
477
+ should be placed, so the default is '-1'.
478
+
479
+ Parameters
480
+ ----------
481
+ Not a function, so takes no parameters
482
+
483
+
484
+ Returns
485
+ -------
486
+ A concatenated ndarray or matrix.
487
+
488
+ See Also
489
+ --------
490
+ concatenate : Join a sequence of arrays along an existing axis.
491
+ c_ : Translates slice objects to concatenation along the second axis.
492
+
493
+ Examples
494
+ --------
495
+ >>> np.r_[np.array([1,2,3]), 0, 0, np.array([4,5,6])]
496
+ array([1, 2, 3, ..., 4, 5, 6])
497
+ >>> np.r_[-1:1:6j, [0]*3, 5, 6]
498
+ array([-1. , -0.6, -0.2, 0.2, 0.6, 1. , 0. , 0. , 0. , 5. , 6. ])
499
+
500
+ String integers specify the axis to concatenate along or the minimum
501
+ number of dimensions to force entries into.
502
+
503
+ >>> a = np.array([[0, 1, 2], [3, 4, 5]])
504
+ >>> np.r_['-1', a, a] # concatenate along last axis
505
+ array([[0, 1, 2, 0, 1, 2],
506
+ [3, 4, 5, 3, 4, 5]])
507
+ >>> np.r_['0,2', [1,2,3], [4,5,6]] # concatenate along first axis, dim>=2
508
+ array([[1, 2, 3],
509
+ [4, 5, 6]])
510
+
511
+ >>> np.r_['0,2,0', [1,2,3], [4,5,6]]
512
+ array([[1],
513
+ [2],
514
+ [3],
515
+ [4],
516
+ [5],
517
+ [6]])
518
+ >>> np.r_['1,2,0', [1,2,3], [4,5,6]]
519
+ array([[1, 4],
520
+ [2, 5],
521
+ [3, 6]])
522
+
523
+ Using 'r' or 'c' as a first string argument creates a matrix.
524
+
525
+ >>> np.r_['r',[1,2,3], [4,5,6]]
526
+ matrix([[1, 2, 3, 4, 5, 6]])
527
+
528
+ """
529
+
530
+ def __init__(self):
531
+ AxisConcatenator.__init__(self, 0)
532
+
533
+
534
+ r_ = RClass()
535
+
536
+
537
+ class CClass(AxisConcatenator):
538
+ """
539
+ Translates slice objects to concatenation along the second axis.
540
+
541
+ This is short-hand for ``np.r_['-1,2,0', index expression]``, which is
542
+ useful because of its common occurrence. In particular, arrays will be
543
+ stacked along their last axis after being upgraded to at least 2-D with
544
+ 1's post-pended to the shape (column vectors made out of 1-D arrays).
545
+
546
+ See Also
547
+ --------
548
+ column_stack : Stack 1-D arrays as columns into a 2-D array.
549
+ r_ : For more detailed documentation.
550
+
551
+ Examples
552
+ --------
553
+ >>> np.c_[np.array([1,2,3]), np.array([4,5,6])]
554
+ array([[1, 4],
555
+ [2, 5],
556
+ [3, 6]])
557
+ >>> np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])]
558
+ array([[1, 2, 3, ..., 4, 5, 6]])
559
+
560
+ """
561
+
562
+ def __init__(self):
563
+ AxisConcatenator.__init__(self, -1, ndmin=2, trans1d=0)
564
+
565
+
566
+ c_ = CClass()
567
+
568
+
569
+ @set_module('numpy')
570
+ class ndenumerate:
571
+ """
572
+ Multidimensional index iterator.
573
+
574
+ Return an iterator yielding pairs of array coordinates and values.
575
+
576
+ Parameters
577
+ ----------
578
+ arr : ndarray
579
+ Input array.
580
+
581
+ See Also
582
+ --------
583
+ ndindex, flatiter
584
+
585
+ Examples
586
+ --------
587
+ >>> a = np.array([[1, 2], [3, 4]])
588
+ >>> for index, x in np.ndenumerate(a):
589
+ ... print(index, x)
590
+ (0, 0) 1
591
+ (0, 1) 2
592
+ (1, 0) 3
593
+ (1, 1) 4
594
+
595
+ """
596
+
597
+ def __init__(self, arr):
598
+ self.iter = np.asarray(arr).flat
599
+
600
+ def __next__(self):
601
+ """
602
+ Standard iterator method, returns the index tuple and array value.
603
+
604
+ Returns
605
+ -------
606
+ coords : tuple of ints
607
+ The indices of the current iteration.
608
+ val : scalar
609
+ The array element of the current iteration.
610
+
611
+ """
612
+ return self.iter.coords, next(self.iter)
613
+
614
+ def __iter__(self):
615
+ return self
616
+
617
+
618
+ @set_module('numpy')
619
+ class ndindex:
620
+ """
621
+ An N-dimensional iterator object to index arrays.
622
+
623
+ Given the shape of an array, an `ndindex` instance iterates over
624
+ the N-dimensional index of the array. At each iteration a tuple
625
+ of indices is returned, the last dimension is iterated over first.
626
+
627
+ Parameters
628
+ ----------
629
+ shape : ints, or a single tuple of ints
630
+ The size of each dimension of the array can be passed as
631
+ individual parameters or as the elements of a tuple.
632
+
633
+ See Also
634
+ --------
635
+ ndenumerate, flatiter
636
+
637
+ Examples
638
+ --------
639
+ Dimensions as individual arguments
640
+
641
+ >>> for index in np.ndindex(3, 2, 1):
642
+ ... print(index)
643
+ (0, 0, 0)
644
+ (0, 1, 0)
645
+ (1, 0, 0)
646
+ (1, 1, 0)
647
+ (2, 0, 0)
648
+ (2, 1, 0)
649
+
650
+ Same dimensions - but in a tuple ``(3, 2, 1)``
651
+
652
+ >>> for index in np.ndindex((3, 2, 1)):
653
+ ... print(index)
654
+ (0, 0, 0)
655
+ (0, 1, 0)
656
+ (1, 0, 0)
657
+ (1, 1, 0)
658
+ (2, 0, 0)
659
+ (2, 1, 0)
660
+
661
+ """
662
+
663
+ def __init__(self, *shape):
664
+ if len(shape) == 1 and isinstance(shape[0], tuple):
665
+ shape = shape[0]
666
+ x = as_strided(_nx.zeros(1), shape=shape,
667
+ strides=_nx.zeros_like(shape))
668
+ self._it = _nx.nditer(x, flags=['multi_index', 'zerosize_ok'],
669
+ order='C')
670
+
671
+ def __iter__(self):
672
+ return self
673
+
674
+ def ndincr(self):
675
+ """
676
+ Increment the multi-dimensional index by one.
677
+
678
+ This method is for backward compatibility only: do not use.
679
+
680
+ .. deprecated:: 1.20.0
681
+ This method has been advised against since numpy 1.8.0, but only
682
+ started emitting DeprecationWarning as of this version.
683
+ """
684
+ # NumPy 1.20.0, 2020-09-08
685
+ warnings.warn(
686
+ "`ndindex.ndincr()` is deprecated, use `next(ndindex)` instead",
687
+ DeprecationWarning, stacklevel=2)
688
+ next(self)
689
+
690
+ def __next__(self):
691
+ """
692
+ Standard iterator method, updates the index and returns the index
693
+ tuple.
694
+
695
+ Returns
696
+ -------
697
+ val : tuple of ints
698
+ Returns a tuple containing the indices of the current
699
+ iteration.
700
+
701
+ """
702
+ next(self._it)
703
+ return self._it.multi_index
704
+
705
+
706
+ # You can do all this with slice() plus a few special objects,
707
+ # but there's a lot to remember. This version is simpler because
708
+ # it uses the standard array indexing syntax.
709
+ #
710
+ # Written by Konrad Hinsen <hinsen@cnrs-orleans.fr>
711
+ # last revision: 1999-7-23
712
+ #
713
+ # Cosmetic changes by T. Oliphant 2001
714
+ #
715
+ #
716
+
717
+ class IndexExpression:
718
+ """
719
+ A nicer way to build up index tuples for arrays.
720
+
721
+ .. note::
722
+ Use one of the two predefined instances `index_exp` or `s_`
723
+ rather than directly using `IndexExpression`.
724
+
725
+ For any index combination, including slicing and axis insertion,
726
+ ``a[indices]`` is the same as ``a[np.index_exp[indices]]`` for any
727
+ array `a`. However, ``np.index_exp[indices]`` can be used anywhere
728
+ in Python code and returns a tuple of slice objects that can be
729
+ used in the construction of complex index expressions.
730
+
731
+ Parameters
732
+ ----------
733
+ maketuple : bool
734
+ If True, always returns a tuple.
735
+
736
+ See Also
737
+ --------
738
+ index_exp : Predefined instance that always returns a tuple:
739
+ `index_exp = IndexExpression(maketuple=True)`.
740
+ s_ : Predefined instance without tuple conversion:
741
+ `s_ = IndexExpression(maketuple=False)`.
742
+
743
+ Notes
744
+ -----
745
+ You can do all this with `slice()` plus a few special objects,
746
+ but there's a lot to remember and this version is simpler because
747
+ it uses the standard array indexing syntax.
748
+
749
+ Examples
750
+ --------
751
+ >>> np.s_[2::2]
752
+ slice(2, None, 2)
753
+ >>> np.index_exp[2::2]
754
+ (slice(2, None, 2),)
755
+
756
+ >>> np.array([0, 1, 2, 3, 4])[np.s_[2::2]]
757
+ array([2, 4])
758
+
759
+ """
760
+
761
+ def __init__(self, maketuple):
762
+ self.maketuple = maketuple
763
+
764
+ def __getitem__(self, item):
765
+ if self.maketuple and not isinstance(item, tuple):
766
+ return (item,)
767
+ else:
768
+ return item
769
+
770
+
771
+ index_exp = IndexExpression(maketuple=True)
772
+ s_ = IndexExpression(maketuple=False)
773
+
774
+ # End contribution from Konrad.
775
+
776
+
777
+ # The following functions complement those in twodim_base, but are
778
+ # applicable to N-dimensions.
779
+
780
+
781
+ def _fill_diagonal_dispatcher(a, val, wrap=None):
782
+ return (a,)
783
+
784
+
785
+ @array_function_dispatch(_fill_diagonal_dispatcher)
786
+ def fill_diagonal(a, val, wrap=False):
787
+ """Fill the main diagonal of the given array of any dimensionality.
788
+
789
+ For an array `a` with ``a.ndim >= 2``, the diagonal is the list of
790
+ locations with indices ``a[i, ..., i]`` all identical. This function
791
+ modifies the input array in-place, it does not return a value.
792
+
793
+ Parameters
794
+ ----------
795
+ a : array, at least 2-D.
796
+ Array whose diagonal is to be filled, it gets modified in-place.
797
+
798
+ val : scalar or array_like
799
+ Value(s) to write on the diagonal. If `val` is scalar, the value is
800
+ written along the diagonal. If array-like, the flattened `val` is
801
+ written along the diagonal, repeating if necessary to fill all
802
+ diagonal entries.
803
+
804
+ wrap : bool
805
+ For tall matrices in NumPy version up to 1.6.2, the
806
+ diagonal "wrapped" after N columns. You can have this behavior
807
+ with this option. This affects only tall matrices.
808
+
809
+ See also
810
+ --------
811
+ diag_indices, diag_indices_from
812
+
813
+ Notes
814
+ -----
815
+ .. versionadded:: 1.4.0
816
+
817
+ This functionality can be obtained via `diag_indices`, but internally
818
+ this version uses a much faster implementation that never constructs the
819
+ indices and uses simple slicing.
820
+
821
+ Examples
822
+ --------
823
+ >>> a = np.zeros((3, 3), int)
824
+ >>> np.fill_diagonal(a, 5)
825
+ >>> a
826
+ array([[5, 0, 0],
827
+ [0, 5, 0],
828
+ [0, 0, 5]])
829
+
830
+ The same function can operate on a 4-D array:
831
+
832
+ >>> a = np.zeros((3, 3, 3, 3), int)
833
+ >>> np.fill_diagonal(a, 4)
834
+
835
+ We only show a few blocks for clarity:
836
+
837
+ >>> a[0, 0]
838
+ array([[4, 0, 0],
839
+ [0, 0, 0],
840
+ [0, 0, 0]])
841
+ >>> a[1, 1]
842
+ array([[0, 0, 0],
843
+ [0, 4, 0],
844
+ [0, 0, 0]])
845
+ >>> a[2, 2]
846
+ array([[0, 0, 0],
847
+ [0, 0, 0],
848
+ [0, 0, 4]])
849
+
850
+ The wrap option affects only tall matrices:
851
+
852
+ >>> # tall matrices no wrap
853
+ >>> a = np.zeros((5, 3), int)
854
+ >>> np.fill_diagonal(a, 4)
855
+ >>> a
856
+ array([[4, 0, 0],
857
+ [0, 4, 0],
858
+ [0, 0, 4],
859
+ [0, 0, 0],
860
+ [0, 0, 0]])
861
+
862
+ >>> # tall matrices wrap
863
+ >>> a = np.zeros((5, 3), int)
864
+ >>> np.fill_diagonal(a, 4, wrap=True)
865
+ >>> a
866
+ array([[4, 0, 0],
867
+ [0, 4, 0],
868
+ [0, 0, 4],
869
+ [0, 0, 0],
870
+ [4, 0, 0]])
871
+
872
+ >>> # wide matrices
873
+ >>> a = np.zeros((3, 5), int)
874
+ >>> np.fill_diagonal(a, 4, wrap=True)
875
+ >>> a
876
+ array([[4, 0, 0, 0, 0],
877
+ [0, 4, 0, 0, 0],
878
+ [0, 0, 4, 0, 0]])
879
+
880
+ The anti-diagonal can be filled by reversing the order of elements
881
+ using either `numpy.flipud` or `numpy.fliplr`.
882
+
883
+ >>> a = np.zeros((3, 3), int);
884
+ >>> np.fill_diagonal(np.fliplr(a), [1,2,3]) # Horizontal flip
885
+ >>> a
886
+ array([[0, 0, 1],
887
+ [0, 2, 0],
888
+ [3, 0, 0]])
889
+ >>> np.fill_diagonal(np.flipud(a), [1,2,3]) # Vertical flip
890
+ >>> a
891
+ array([[0, 0, 3],
892
+ [0, 2, 0],
893
+ [1, 0, 0]])
894
+
895
+ Note that the order in which the diagonal is filled varies depending
896
+ on the flip function.
897
+ """
898
+ if a.ndim < 2:
899
+ raise ValueError("array must be at least 2-d")
900
+ end = None
901
+ if a.ndim == 2:
902
+ # Explicit, fast formula for the common case. For 2-d arrays, we
903
+ # accept rectangular ones.
904
+ step = a.shape[1] + 1
905
+ # This is needed to don't have tall matrix have the diagonal wrap.
906
+ if not wrap:
907
+ end = a.shape[1] * a.shape[1]
908
+ else:
909
+ # For more than d=2, the strided formula is only valid for arrays with
910
+ # all dimensions equal, so we check first.
911
+ if not np.all(diff(a.shape) == 0):
912
+ raise ValueError("All dimensions of input must be of equal length")
913
+ step = 1 + (np.cumprod(a.shape[:-1])).sum()
914
+
915
+ # Write the value out into the diagonal.
916
+ a.flat[:end:step] = val
917
+
918
+
919
+ @set_module('numpy')
920
+ def diag_indices(n, ndim=2):
921
+ """
922
+ Return the indices to access the main diagonal of an array.
923
+
924
+ This returns a tuple of indices that can be used to access the main
925
+ diagonal of an array `a` with ``a.ndim >= 2`` dimensions and shape
926
+ (n, n, ..., n). For ``a.ndim = 2`` this is the usual diagonal, for
927
+ ``a.ndim > 2`` this is the set of indices to access ``a[i, i, ..., i]``
928
+ for ``i = [0..n-1]``.
929
+
930
+ Parameters
931
+ ----------
932
+ n : int
933
+ The size, along each dimension, of the arrays for which the returned
934
+ indices can be used.
935
+
936
+ ndim : int, optional
937
+ The number of dimensions.
938
+
939
+ See Also
940
+ --------
941
+ diag_indices_from
942
+
943
+ Notes
944
+ -----
945
+ .. versionadded:: 1.4.0
946
+
947
+ Examples
948
+ --------
949
+ Create a set of indices to access the diagonal of a (4, 4) array:
950
+
951
+ >>> di = np.diag_indices(4)
952
+ >>> di
953
+ (array([0, 1, 2, 3]), array([0, 1, 2, 3]))
954
+ >>> a = np.arange(16).reshape(4, 4)
955
+ >>> a
956
+ array([[ 0, 1, 2, 3],
957
+ [ 4, 5, 6, 7],
958
+ [ 8, 9, 10, 11],
959
+ [12, 13, 14, 15]])
960
+ >>> a[di] = 100
961
+ >>> a
962
+ array([[100, 1, 2, 3],
963
+ [ 4, 100, 6, 7],
964
+ [ 8, 9, 100, 11],
965
+ [ 12, 13, 14, 100]])
966
+
967
+ Now, we create indices to manipulate a 3-D array:
968
+
969
+ >>> d3 = np.diag_indices(2, 3)
970
+ >>> d3
971
+ (array([0, 1]), array([0, 1]), array([0, 1]))
972
+
973
+ And use it to set the diagonal of an array of zeros to 1:
974
+
975
+ >>> a = np.zeros((2, 2, 2), dtype=int)
976
+ >>> a[d3] = 1
977
+ >>> a
978
+ array([[[1, 0],
979
+ [0, 0]],
980
+ [[0, 0],
981
+ [0, 1]]])
982
+
983
+ """
984
+ idx = np.arange(n)
985
+ return (idx,) * ndim
986
+
987
+
988
+ def _diag_indices_from(arr):
989
+ return (arr,)
990
+
991
+
992
+ @array_function_dispatch(_diag_indices_from)
993
+ def diag_indices_from(arr):
994
+ """
995
+ Return the indices to access the main diagonal of an n-dimensional array.
996
+
997
+ See `diag_indices` for full details.
998
+
999
+ Parameters
1000
+ ----------
1001
+ arr : array, at least 2-D
1002
+
1003
+ See Also
1004
+ --------
1005
+ diag_indices
1006
+
1007
+ Notes
1008
+ -----
1009
+ .. versionadded:: 1.4.0
1010
+
1011
+ Examples
1012
+ --------
1013
+
1014
+ Create a 4 by 4 array.
1015
+
1016
+ >>> a = np.arange(16).reshape(4, 4)
1017
+ >>> a
1018
+ array([[ 0, 1, 2, 3],
1019
+ [ 4, 5, 6, 7],
1020
+ [ 8, 9, 10, 11],
1021
+ [12, 13, 14, 15]])
1022
+
1023
+ Get the indices of the diagonal elements.
1024
+
1025
+ >>> di = np.diag_indices_from(a)
1026
+ >>> di
1027
+ (array([0, 1, 2, 3]), array([0, 1, 2, 3]))
1028
+
1029
+ >>> a[di]
1030
+ array([ 0, 5, 10, 15])
1031
+
1032
+ This is simply syntactic sugar for diag_indices.
1033
+
1034
+ >>> np.diag_indices(a.shape[0])
1035
+ (array([0, 1, 2, 3]), array([0, 1, 2, 3]))
1036
+
1037
+ """
1038
+
1039
+ if not arr.ndim >= 2:
1040
+ raise ValueError("input array must be at least 2-d")
1041
+ # For more than d=2, the strided formula is only valid for arrays with
1042
+ # all dimensions equal, so we check first.
1043
+ if not np.all(diff(arr.shape) == 0):
1044
+ raise ValueError("All dimensions of input must be of equal length")
1045
+
1046
+ return diag_indices(arr.shape[0], arr.ndim)
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/mixins.pyi ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from abc import ABCMeta, abstractmethod
2
+ from typing import Literal as L, Any
3
+
4
+ from numpy import ufunc
5
+
6
+ __all__: list[str]
7
+
8
+ # NOTE: `NDArrayOperatorsMixin` is not formally an abstract baseclass,
9
+ # even though it's reliant on subclasses implementing `__array_ufunc__`
10
+
11
+ # NOTE: The accepted input- and output-types of the various dunders are
12
+ # completely dependent on how `__array_ufunc__` is implemented.
13
+ # As such, only little type safety can be provided here.
14
+
15
+ class NDArrayOperatorsMixin(metaclass=ABCMeta):
16
+ @abstractmethod
17
+ def __array_ufunc__(
18
+ self,
19
+ ufunc: ufunc,
20
+ method: L["__call__", "reduce", "reduceat", "accumulate", "outer", "inner"],
21
+ *inputs: Any,
22
+ **kwargs: Any,
23
+ ) -> Any: ...
24
+ def __lt__(self, other: Any) -> Any: ...
25
+ def __le__(self, other: Any) -> Any: ...
26
+ def __eq__(self, other: Any) -> Any: ...
27
+ def __ne__(self, other: Any) -> Any: ...
28
+ def __gt__(self, other: Any) -> Any: ...
29
+ def __ge__(self, other: Any) -> Any: ...
30
+ def __add__(self, other: Any) -> Any: ...
31
+ def __radd__(self, other: Any) -> Any: ...
32
+ def __iadd__(self, other: Any) -> Any: ...
33
+ def __sub__(self, other: Any) -> Any: ...
34
+ def __rsub__(self, other: Any) -> Any: ...
35
+ def __isub__(self, other: Any) -> Any: ...
36
+ def __mul__(self, other: Any) -> Any: ...
37
+ def __rmul__(self, other: Any) -> Any: ...
38
+ def __imul__(self, other: Any) -> Any: ...
39
+ def __matmul__(self, other: Any) -> Any: ...
40
+ def __rmatmul__(self, other: Any) -> Any: ...
41
+ def __imatmul__(self, other: Any) -> Any: ...
42
+ def __truediv__(self, other: Any) -> Any: ...
43
+ def __rtruediv__(self, other: Any) -> Any: ...
44
+ def __itruediv__(self, other: Any) -> Any: ...
45
+ def __floordiv__(self, other: Any) -> Any: ...
46
+ def __rfloordiv__(self, other: Any) -> Any: ...
47
+ def __ifloordiv__(self, other: Any) -> Any: ...
48
+ def __mod__(self, other: Any) -> Any: ...
49
+ def __rmod__(self, other: Any) -> Any: ...
50
+ def __imod__(self, other: Any) -> Any: ...
51
+ def __divmod__(self, other: Any) -> Any: ...
52
+ def __rdivmod__(self, other: Any) -> Any: ...
53
+ def __pow__(self, other: Any) -> Any: ...
54
+ def __rpow__(self, other: Any) -> Any: ...
55
+ def __ipow__(self, other: Any) -> Any: ...
56
+ def __lshift__(self, other: Any) -> Any: ...
57
+ def __rlshift__(self, other: Any) -> Any: ...
58
+ def __ilshift__(self, other: Any) -> Any: ...
59
+ def __rshift__(self, other: Any) -> Any: ...
60
+ def __rrshift__(self, other: Any) -> Any: ...
61
+ def __irshift__(self, other: Any) -> Any: ...
62
+ def __and__(self, other: Any) -> Any: ...
63
+ def __rand__(self, other: Any) -> Any: ...
64
+ def __iand__(self, other: Any) -> Any: ...
65
+ def __xor__(self, other: Any) -> Any: ...
66
+ def __rxor__(self, other: Any) -> Any: ...
67
+ def __ixor__(self, other: Any) -> Any: ...
68
+ def __or__(self, other: Any) -> Any: ...
69
+ def __ror__(self, other: Any) -> Any: ...
70
+ def __ior__(self, other: Any) -> Any: ...
71
+ def __neg__(self) -> Any: ...
72
+ def __pos__(self) -> Any: ...
73
+ def __abs__(self) -> Any: ...
74
+ def __invert__(self) -> Any: ...
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/polynomial.pyi ADDED
@@ -0,0 +1,303 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import (
2
+ Literal as L,
3
+ overload,
4
+ Any,
5
+ SupportsInt,
6
+ SupportsIndex,
7
+ TypeVar,
8
+ NoReturn,
9
+ )
10
+
11
+ from numpy import (
12
+ RankWarning as RankWarning,
13
+ poly1d as poly1d,
14
+ unsignedinteger,
15
+ signedinteger,
16
+ floating,
17
+ complexfloating,
18
+ bool_,
19
+ int32,
20
+ int64,
21
+ float64,
22
+ complex128,
23
+ object_,
24
+ )
25
+
26
+ from numpy._typing import (
27
+ NDArray,
28
+ ArrayLike,
29
+ _ArrayLikeBool_co,
30
+ _ArrayLikeUInt_co,
31
+ _ArrayLikeInt_co,
32
+ _ArrayLikeFloat_co,
33
+ _ArrayLikeComplex_co,
34
+ _ArrayLikeObject_co,
35
+ )
36
+
37
+ _T = TypeVar("_T")
38
+
39
+ _2Tup = tuple[_T, _T]
40
+ _5Tup = tuple[
41
+ _T,
42
+ NDArray[float64],
43
+ NDArray[int32],
44
+ NDArray[float64],
45
+ NDArray[float64],
46
+ ]
47
+
48
+ __all__: list[str]
49
+
50
+ def poly(seq_of_zeros: ArrayLike) -> NDArray[floating[Any]]: ...
51
+
52
+ # Returns either a float or complex array depending on the input values.
53
+ # See `np.linalg.eigvals`.
54
+ def roots(p: ArrayLike) -> NDArray[complexfloating[Any, Any]] | NDArray[floating[Any]]: ...
55
+
56
+ @overload
57
+ def polyint(
58
+ p: poly1d,
59
+ m: SupportsInt | SupportsIndex = ...,
60
+ k: None | _ArrayLikeComplex_co | _ArrayLikeObject_co = ...,
61
+ ) -> poly1d: ...
62
+ @overload
63
+ def polyint(
64
+ p: _ArrayLikeFloat_co,
65
+ m: SupportsInt | SupportsIndex = ...,
66
+ k: None | _ArrayLikeFloat_co = ...,
67
+ ) -> NDArray[floating[Any]]: ...
68
+ @overload
69
+ def polyint(
70
+ p: _ArrayLikeComplex_co,
71
+ m: SupportsInt | SupportsIndex = ...,
72
+ k: None | _ArrayLikeComplex_co = ...,
73
+ ) -> NDArray[complexfloating[Any, Any]]: ...
74
+ @overload
75
+ def polyint(
76
+ p: _ArrayLikeObject_co,
77
+ m: SupportsInt | SupportsIndex = ...,
78
+ k: None | _ArrayLikeObject_co = ...,
79
+ ) -> NDArray[object_]: ...
80
+
81
+ @overload
82
+ def polyder(
83
+ p: poly1d,
84
+ m: SupportsInt | SupportsIndex = ...,
85
+ ) -> poly1d: ...
86
+ @overload
87
+ def polyder(
88
+ p: _ArrayLikeFloat_co,
89
+ m: SupportsInt | SupportsIndex = ...,
90
+ ) -> NDArray[floating[Any]]: ...
91
+ @overload
92
+ def polyder(
93
+ p: _ArrayLikeComplex_co,
94
+ m: SupportsInt | SupportsIndex = ...,
95
+ ) -> NDArray[complexfloating[Any, Any]]: ...
96
+ @overload
97
+ def polyder(
98
+ p: _ArrayLikeObject_co,
99
+ m: SupportsInt | SupportsIndex = ...,
100
+ ) -> NDArray[object_]: ...
101
+
102
+ @overload
103
+ def polyfit(
104
+ x: _ArrayLikeFloat_co,
105
+ y: _ArrayLikeFloat_co,
106
+ deg: SupportsIndex | SupportsInt,
107
+ rcond: None | float = ...,
108
+ full: L[False] = ...,
109
+ w: None | _ArrayLikeFloat_co = ...,
110
+ cov: L[False] = ...,
111
+ ) -> NDArray[float64]: ...
112
+ @overload
113
+ def polyfit(
114
+ x: _ArrayLikeComplex_co,
115
+ y: _ArrayLikeComplex_co,
116
+ deg: SupportsIndex | SupportsInt,
117
+ rcond: None | float = ...,
118
+ full: L[False] = ...,
119
+ w: None | _ArrayLikeFloat_co = ...,
120
+ cov: L[False] = ...,
121
+ ) -> NDArray[complex128]: ...
122
+ @overload
123
+ def polyfit(
124
+ x: _ArrayLikeFloat_co,
125
+ y: _ArrayLikeFloat_co,
126
+ deg: SupportsIndex | SupportsInt,
127
+ rcond: None | float = ...,
128
+ full: L[False] = ...,
129
+ w: None | _ArrayLikeFloat_co = ...,
130
+ cov: L[True, "unscaled"] = ...,
131
+ ) -> _2Tup[NDArray[float64]]: ...
132
+ @overload
133
+ def polyfit(
134
+ x: _ArrayLikeComplex_co,
135
+ y: _ArrayLikeComplex_co,
136
+ deg: SupportsIndex | SupportsInt,
137
+ rcond: None | float = ...,
138
+ full: L[False] = ...,
139
+ w: None | _ArrayLikeFloat_co = ...,
140
+ cov: L[True, "unscaled"] = ...,
141
+ ) -> _2Tup[NDArray[complex128]]: ...
142
+ @overload
143
+ def polyfit(
144
+ x: _ArrayLikeFloat_co,
145
+ y: _ArrayLikeFloat_co,
146
+ deg: SupportsIndex | SupportsInt,
147
+ rcond: None | float = ...,
148
+ full: L[True] = ...,
149
+ w: None | _ArrayLikeFloat_co = ...,
150
+ cov: bool | L["unscaled"] = ...,
151
+ ) -> _5Tup[NDArray[float64]]: ...
152
+ @overload
153
+ def polyfit(
154
+ x: _ArrayLikeComplex_co,
155
+ y: _ArrayLikeComplex_co,
156
+ deg: SupportsIndex | SupportsInt,
157
+ rcond: None | float = ...,
158
+ full: L[True] = ...,
159
+ w: None | _ArrayLikeFloat_co = ...,
160
+ cov: bool | L["unscaled"] = ...,
161
+ ) -> _5Tup[NDArray[complex128]]: ...
162
+
163
+ @overload
164
+ def polyval(
165
+ p: _ArrayLikeBool_co,
166
+ x: _ArrayLikeBool_co,
167
+ ) -> NDArray[int64]: ...
168
+ @overload
169
+ def polyval(
170
+ p: _ArrayLikeUInt_co,
171
+ x: _ArrayLikeUInt_co,
172
+ ) -> NDArray[unsignedinteger[Any]]: ...
173
+ @overload
174
+ def polyval(
175
+ p: _ArrayLikeInt_co,
176
+ x: _ArrayLikeInt_co,
177
+ ) -> NDArray[signedinteger[Any]]: ...
178
+ @overload
179
+ def polyval(
180
+ p: _ArrayLikeFloat_co,
181
+ x: _ArrayLikeFloat_co,
182
+ ) -> NDArray[floating[Any]]: ...
183
+ @overload
184
+ def polyval(
185
+ p: _ArrayLikeComplex_co,
186
+ x: _ArrayLikeComplex_co,
187
+ ) -> NDArray[complexfloating[Any, Any]]: ...
188
+ @overload
189
+ def polyval(
190
+ p: _ArrayLikeObject_co,
191
+ x: _ArrayLikeObject_co,
192
+ ) -> NDArray[object_]: ...
193
+
194
+ @overload
195
+ def polyadd(
196
+ a1: poly1d,
197
+ a2: _ArrayLikeComplex_co | _ArrayLikeObject_co,
198
+ ) -> poly1d: ...
199
+ @overload
200
+ def polyadd(
201
+ a1: _ArrayLikeComplex_co | _ArrayLikeObject_co,
202
+ a2: poly1d,
203
+ ) -> poly1d: ...
204
+ @overload
205
+ def polyadd(
206
+ a1: _ArrayLikeBool_co,
207
+ a2: _ArrayLikeBool_co,
208
+ ) -> NDArray[bool_]: ...
209
+ @overload
210
+ def polyadd(
211
+ a1: _ArrayLikeUInt_co,
212
+ a2: _ArrayLikeUInt_co,
213
+ ) -> NDArray[unsignedinteger[Any]]: ...
214
+ @overload
215
+ def polyadd(
216
+ a1: _ArrayLikeInt_co,
217
+ a2: _ArrayLikeInt_co,
218
+ ) -> NDArray[signedinteger[Any]]: ...
219
+ @overload
220
+ def polyadd(
221
+ a1: _ArrayLikeFloat_co,
222
+ a2: _ArrayLikeFloat_co,
223
+ ) -> NDArray[floating[Any]]: ...
224
+ @overload
225
+ def polyadd(
226
+ a1: _ArrayLikeComplex_co,
227
+ a2: _ArrayLikeComplex_co,
228
+ ) -> NDArray[complexfloating[Any, Any]]: ...
229
+ @overload
230
+ def polyadd(
231
+ a1: _ArrayLikeObject_co,
232
+ a2: _ArrayLikeObject_co,
233
+ ) -> NDArray[object_]: ...
234
+
235
+ @overload
236
+ def polysub(
237
+ a1: poly1d,
238
+ a2: _ArrayLikeComplex_co | _ArrayLikeObject_co,
239
+ ) -> poly1d: ...
240
+ @overload
241
+ def polysub(
242
+ a1: _ArrayLikeComplex_co | _ArrayLikeObject_co,
243
+ a2: poly1d,
244
+ ) -> poly1d: ...
245
+ @overload
246
+ def polysub(
247
+ a1: _ArrayLikeBool_co,
248
+ a2: _ArrayLikeBool_co,
249
+ ) -> NoReturn: ...
250
+ @overload
251
+ def polysub(
252
+ a1: _ArrayLikeUInt_co,
253
+ a2: _ArrayLikeUInt_co,
254
+ ) -> NDArray[unsignedinteger[Any]]: ...
255
+ @overload
256
+ def polysub(
257
+ a1: _ArrayLikeInt_co,
258
+ a2: _ArrayLikeInt_co,
259
+ ) -> NDArray[signedinteger[Any]]: ...
260
+ @overload
261
+ def polysub(
262
+ a1: _ArrayLikeFloat_co,
263
+ a2: _ArrayLikeFloat_co,
264
+ ) -> NDArray[floating[Any]]: ...
265
+ @overload
266
+ def polysub(
267
+ a1: _ArrayLikeComplex_co,
268
+ a2: _ArrayLikeComplex_co,
269
+ ) -> NDArray[complexfloating[Any, Any]]: ...
270
+ @overload
271
+ def polysub(
272
+ a1: _ArrayLikeObject_co,
273
+ a2: _ArrayLikeObject_co,
274
+ ) -> NDArray[object_]: ...
275
+
276
+ # NOTE: Not an alias, but they do have the same signature (that we can reuse)
277
+ polymul = polyadd
278
+
279
+ @overload
280
+ def polydiv(
281
+ u: poly1d,
282
+ v: _ArrayLikeComplex_co | _ArrayLikeObject_co,
283
+ ) -> _2Tup[poly1d]: ...
284
+ @overload
285
+ def polydiv(
286
+ u: _ArrayLikeComplex_co | _ArrayLikeObject_co,
287
+ v: poly1d,
288
+ ) -> _2Tup[poly1d]: ...
289
+ @overload
290
+ def polydiv(
291
+ u: _ArrayLikeFloat_co,
292
+ v: _ArrayLikeFloat_co,
293
+ ) -> _2Tup[NDArray[floating[Any]]]: ...
294
+ @overload
295
+ def polydiv(
296
+ u: _ArrayLikeComplex_co,
297
+ v: _ArrayLikeComplex_co,
298
+ ) -> _2Tup[NDArray[complexfloating[Any, Any]]]: ...
299
+ @overload
300
+ def polydiv(
301
+ u: _ArrayLikeObject_co,
302
+ v: _ArrayLikeObject_co,
303
+ ) -> _2Tup[NDArray[Any]]: ...
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/recfunctions.py ADDED
@@ -0,0 +1,1673 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Collection of utilities to manipulate structured arrays.
3
+
4
+ Most of these functions were initially implemented by John Hunter for
5
+ matplotlib. They have been rewritten and extended for convenience.
6
+
7
+ """
8
+ import itertools
9
+ import numpy as np
10
+ import numpy.ma as ma
11
+ from numpy import ndarray, recarray
12
+ from numpy.ma import MaskedArray
13
+ from numpy.ma.mrecords import MaskedRecords
14
+ from numpy.core.overrides import array_function_dispatch
15
+ from numpy.lib._iotools import _is_string_like
16
+
17
+ _check_fill_value = np.ma.core._check_fill_value
18
+
19
+
20
+ __all__ = [
21
+ 'append_fields', 'apply_along_fields', 'assign_fields_by_name',
22
+ 'drop_fields', 'find_duplicates', 'flatten_descr',
23
+ 'get_fieldstructure', 'get_names', 'get_names_flat',
24
+ 'join_by', 'merge_arrays', 'rec_append_fields',
25
+ 'rec_drop_fields', 'rec_join', 'recursive_fill_fields',
26
+ 'rename_fields', 'repack_fields', 'require_fields',
27
+ 'stack_arrays', 'structured_to_unstructured', 'unstructured_to_structured',
28
+ ]
29
+
30
+
31
+ def _recursive_fill_fields_dispatcher(input, output):
32
+ return (input, output)
33
+
34
+
35
+ @array_function_dispatch(_recursive_fill_fields_dispatcher)
36
+ def recursive_fill_fields(input, output):
37
+ """
38
+ Fills fields from output with fields from input,
39
+ with support for nested structures.
40
+
41
+ Parameters
42
+ ----------
43
+ input : ndarray
44
+ Input array.
45
+ output : ndarray
46
+ Output array.
47
+
48
+ Notes
49
+ -----
50
+ * `output` should be at least the same size as `input`
51
+
52
+ Examples
53
+ --------
54
+ >>> from numpy.lib import recfunctions as rfn
55
+ >>> a = np.array([(1, 10.), (2, 20.)], dtype=[('A', np.int64), ('B', np.float64)])
56
+ >>> b = np.zeros((3,), dtype=a.dtype)
57
+ >>> rfn.recursive_fill_fields(a, b)
58
+ array([(1, 10.), (2, 20.), (0, 0.)], dtype=[('A', '<i8'), ('B', '<f8')])
59
+
60
+ """
61
+ newdtype = output.dtype
62
+ for field in newdtype.names:
63
+ try:
64
+ current = input[field]
65
+ except ValueError:
66
+ continue
67
+ if current.dtype.names is not None:
68
+ recursive_fill_fields(current, output[field])
69
+ else:
70
+ output[field][:len(current)] = current
71
+ return output
72
+
73
+
74
+ def _get_fieldspec(dtype):
75
+ """
76
+ Produce a list of name/dtype pairs corresponding to the dtype fields
77
+
78
+ Similar to dtype.descr, but the second item of each tuple is a dtype, not a
79
+ string. As a result, this handles subarray dtypes
80
+
81
+ Can be passed to the dtype constructor to reconstruct the dtype, noting that
82
+ this (deliberately) discards field offsets.
83
+
84
+ Examples
85
+ --------
86
+ >>> dt = np.dtype([(('a', 'A'), np.int64), ('b', np.double, 3)])
87
+ >>> dt.descr
88
+ [(('a', 'A'), '<i8'), ('b', '<f8', (3,))]
89
+ >>> _get_fieldspec(dt)
90
+ [(('a', 'A'), dtype('int64')), ('b', dtype(('<f8', (3,))))]
91
+
92
+ """
93
+ if dtype.names is None:
94
+ # .descr returns a nameless field, so we should too
95
+ return [('', dtype)]
96
+ else:
97
+ fields = ((name, dtype.fields[name]) for name in dtype.names)
98
+ # keep any titles, if present
99
+ return [
100
+ (name if len(f) == 2 else (f[2], name), f[0])
101
+ for name, f in fields
102
+ ]
103
+
104
+
105
+ def get_names(adtype):
106
+ """
107
+ Returns the field names of the input datatype as a tuple. Input datatype
108
+ must have fields otherwise error is raised.
109
+
110
+ Parameters
111
+ ----------
112
+ adtype : dtype
113
+ Input datatype
114
+
115
+ Examples
116
+ --------
117
+ >>> from numpy.lib import recfunctions as rfn
118
+ >>> rfn.get_names(np.empty((1,), dtype=[('A', int)]).dtype)
119
+ ('A',)
120
+ >>> rfn.get_names(np.empty((1,), dtype=[('A',int), ('B', float)]).dtype)
121
+ ('A', 'B')
122
+ >>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])])
123
+ >>> rfn.get_names(adtype)
124
+ ('a', ('b', ('ba', 'bb')))
125
+ """
126
+ listnames = []
127
+ names = adtype.names
128
+ for name in names:
129
+ current = adtype[name]
130
+ if current.names is not None:
131
+ listnames.append((name, tuple(get_names(current))))
132
+ else:
133
+ listnames.append(name)
134
+ return tuple(listnames)
135
+
136
+
137
+ def get_names_flat(adtype):
138
+ """
139
+ Returns the field names of the input datatype as a tuple. Input datatype
140
+ must have fields otherwise error is raised.
141
+ Nested structure are flattened beforehand.
142
+
143
+ Parameters
144
+ ----------
145
+ adtype : dtype
146
+ Input datatype
147
+
148
+ Examples
149
+ --------
150
+ >>> from numpy.lib import recfunctions as rfn
151
+ >>> rfn.get_names_flat(np.empty((1,), dtype=[('A', int)]).dtype) is None
152
+ False
153
+ >>> rfn.get_names_flat(np.empty((1,), dtype=[('A',int), ('B', str)]).dtype)
154
+ ('A', 'B')
155
+ >>> adtype = np.dtype([('a', int), ('b', [('ba', int), ('bb', int)])])
156
+ >>> rfn.get_names_flat(adtype)
157
+ ('a', 'b', 'ba', 'bb')
158
+ """
159
+ listnames = []
160
+ names = adtype.names
161
+ for name in names:
162
+ listnames.append(name)
163
+ current = adtype[name]
164
+ if current.names is not None:
165
+ listnames.extend(get_names_flat(current))
166
+ return tuple(listnames)
167
+
168
+
169
+ def flatten_descr(ndtype):
170
+ """
171
+ Flatten a structured data-type description.
172
+
173
+ Examples
174
+ --------
175
+ >>> from numpy.lib import recfunctions as rfn
176
+ >>> ndtype = np.dtype([('a', '<i4'), ('b', [('ba', '<f8'), ('bb', '<i4')])])
177
+ >>> rfn.flatten_descr(ndtype)
178
+ (('a', dtype('int32')), ('ba', dtype('float64')), ('bb', dtype('int32')))
179
+
180
+ """
181
+ names = ndtype.names
182
+ if names is None:
183
+ return (('', ndtype),)
184
+ else:
185
+ descr = []
186
+ for field in names:
187
+ (typ, _) = ndtype.fields[field]
188
+ if typ.names is not None:
189
+ descr.extend(flatten_descr(typ))
190
+ else:
191
+ descr.append((field, typ))
192
+ return tuple(descr)
193
+
194
+
195
+ def _zip_dtype(seqarrays, flatten=False):
196
+ newdtype = []
197
+ if flatten:
198
+ for a in seqarrays:
199
+ newdtype.extend(flatten_descr(a.dtype))
200
+ else:
201
+ for a in seqarrays:
202
+ current = a.dtype
203
+ if current.names is not None and len(current.names) == 1:
204
+ # special case - dtypes of 1 field are flattened
205
+ newdtype.extend(_get_fieldspec(current))
206
+ else:
207
+ newdtype.append(('', current))
208
+ return np.dtype(newdtype)
209
+
210
+
211
+ def _zip_descr(seqarrays, flatten=False):
212
+ """
213
+ Combine the dtype description of a series of arrays.
214
+
215
+ Parameters
216
+ ----------
217
+ seqarrays : sequence of arrays
218
+ Sequence of arrays
219
+ flatten : {boolean}, optional
220
+ Whether to collapse nested descriptions.
221
+ """
222
+ return _zip_dtype(seqarrays, flatten=flatten).descr
223
+
224
+
225
+ def get_fieldstructure(adtype, lastname=None, parents=None,):
226
+ """
227
+ Returns a dictionary with fields indexing lists of their parent fields.
228
+
229
+ This function is used to simplify access to fields nested in other fields.
230
+
231
+ Parameters
232
+ ----------
233
+ adtype : np.dtype
234
+ Input datatype
235
+ lastname : optional
236
+ Last processed field name (used internally during recursion).
237
+ parents : dictionary
238
+ Dictionary of parent fields (used interbally during recursion).
239
+
240
+ Examples
241
+ --------
242
+ >>> from numpy.lib import recfunctions as rfn
243
+ >>> ndtype = np.dtype([('A', int),
244
+ ... ('B', [('BA', int),
245
+ ... ('BB', [('BBA', int), ('BBB', int)])])])
246
+ >>> rfn.get_fieldstructure(ndtype)
247
+ ... # XXX: possible regression, order of BBA and BBB is swapped
248
+ {'A': [], 'B': [], 'BA': ['B'], 'BB': ['B'], 'BBA': ['B', 'BB'], 'BBB': ['B', 'BB']}
249
+
250
+ """
251
+ if parents is None:
252
+ parents = {}
253
+ names = adtype.names
254
+ for name in names:
255
+ current = adtype[name]
256
+ if current.names is not None:
257
+ if lastname:
258
+ parents[name] = [lastname, ]
259
+ else:
260
+ parents[name] = []
261
+ parents.update(get_fieldstructure(current, name, parents))
262
+ else:
263
+ lastparent = [_ for _ in (parents.get(lastname, []) or [])]
264
+ if lastparent:
265
+ lastparent.append(lastname)
266
+ elif lastname:
267
+ lastparent = [lastname, ]
268
+ parents[name] = lastparent or []
269
+ return parents
270
+
271
+
272
+ def _izip_fields_flat(iterable):
273
+ """
274
+ Returns an iterator of concatenated fields from a sequence of arrays,
275
+ collapsing any nested structure.
276
+
277
+ """
278
+ for element in iterable:
279
+ if isinstance(element, np.void):
280
+ yield from _izip_fields_flat(tuple(element))
281
+ else:
282
+ yield element
283
+
284
+
285
+ def _izip_fields(iterable):
286
+ """
287
+ Returns an iterator of concatenated fields from a sequence of arrays.
288
+
289
+ """
290
+ for element in iterable:
291
+ if (hasattr(element, '__iter__') and
292
+ not isinstance(element, str)):
293
+ yield from _izip_fields(element)
294
+ elif isinstance(element, np.void) and len(tuple(element)) == 1:
295
+ # this statement is the same from the previous expression
296
+ yield from _izip_fields(element)
297
+ else:
298
+ yield element
299
+
300
+
301
+ def _izip_records(seqarrays, fill_value=None, flatten=True):
302
+ """
303
+ Returns an iterator of concatenated items from a sequence of arrays.
304
+
305
+ Parameters
306
+ ----------
307
+ seqarrays : sequence of arrays
308
+ Sequence of arrays.
309
+ fill_value : {None, integer}
310
+ Value used to pad shorter iterables.
311
+ flatten : {True, False},
312
+ Whether to
313
+ """
314
+
315
+ # Should we flatten the items, or just use a nested approach
316
+ if flatten:
317
+ zipfunc = _izip_fields_flat
318
+ else:
319
+ zipfunc = _izip_fields
320
+
321
+ for tup in itertools.zip_longest(*seqarrays, fillvalue=fill_value):
322
+ yield tuple(zipfunc(tup))
323
+
324
+
325
+ def _fix_output(output, usemask=True, asrecarray=False):
326
+ """
327
+ Private function: return a recarray, a ndarray, a MaskedArray
328
+ or a MaskedRecords depending on the input parameters
329
+ """
330
+ if not isinstance(output, MaskedArray):
331
+ usemask = False
332
+ if usemask:
333
+ if asrecarray:
334
+ output = output.view(MaskedRecords)
335
+ else:
336
+ output = ma.filled(output)
337
+ if asrecarray:
338
+ output = output.view(recarray)
339
+ return output
340
+
341
+
342
+ def _fix_defaults(output, defaults=None):
343
+ """
344
+ Update the fill_value and masked data of `output`
345
+ from the default given in a dictionary defaults.
346
+ """
347
+ names = output.dtype.names
348
+ (data, mask, fill_value) = (output.data, output.mask, output.fill_value)
349
+ for (k, v) in (defaults or {}).items():
350
+ if k in names:
351
+ fill_value[k] = v
352
+ data[k][mask[k]] = v
353
+ return output
354
+
355
+
356
+ def _merge_arrays_dispatcher(seqarrays, fill_value=None, flatten=None,
357
+ usemask=None, asrecarray=None):
358
+ return seqarrays
359
+
360
+
361
+ @array_function_dispatch(_merge_arrays_dispatcher)
362
+ def merge_arrays(seqarrays, fill_value=-1, flatten=False,
363
+ usemask=False, asrecarray=False):
364
+ """
365
+ Merge arrays field by field.
366
+
367
+ Parameters
368
+ ----------
369
+ seqarrays : sequence of ndarrays
370
+ Sequence of arrays
371
+ fill_value : {float}, optional
372
+ Filling value used to pad missing data on the shorter arrays.
373
+ flatten : {False, True}, optional
374
+ Whether to collapse nested fields.
375
+ usemask : {False, True}, optional
376
+ Whether to return a masked array or not.
377
+ asrecarray : {False, True}, optional
378
+ Whether to return a recarray (MaskedRecords) or not.
379
+
380
+ Examples
381
+ --------
382
+ >>> from numpy.lib import recfunctions as rfn
383
+ >>> rfn.merge_arrays((np.array([1, 2]), np.array([10., 20., 30.])))
384
+ array([( 1, 10.), ( 2, 20.), (-1, 30.)],
385
+ dtype=[('f0', '<i8'), ('f1', '<f8')])
386
+
387
+ >>> rfn.merge_arrays((np.array([1, 2], dtype=np.int64),
388
+ ... np.array([10., 20., 30.])), usemask=False)
389
+ array([(1, 10.0), (2, 20.0), (-1, 30.0)],
390
+ dtype=[('f0', '<i8'), ('f1', '<f8')])
391
+ >>> rfn.merge_arrays((np.array([1, 2]).view([('a', np.int64)]),
392
+ ... np.array([10., 20., 30.])),
393
+ ... usemask=False, asrecarray=True)
394
+ rec.array([( 1, 10.), ( 2, 20.), (-1, 30.)],
395
+ dtype=[('a', '<i8'), ('f1', '<f8')])
396
+
397
+ Notes
398
+ -----
399
+ * Without a mask, the missing value will be filled with something,
400
+ depending on what its corresponding type:
401
+
402
+ * ``-1`` for integers
403
+ * ``-1.0`` for floating point numbers
404
+ * ``'-'`` for characters
405
+ * ``'-1'`` for strings
406
+ * ``True`` for boolean values
407
+ * XXX: I just obtained these values empirically
408
+ """
409
+ # Only one item in the input sequence ?
410
+ if (len(seqarrays) == 1):
411
+ seqarrays = np.asanyarray(seqarrays[0])
412
+ # Do we have a single ndarray as input ?
413
+ if isinstance(seqarrays, (ndarray, np.void)):
414
+ seqdtype = seqarrays.dtype
415
+ # Make sure we have named fields
416
+ if seqdtype.names is None:
417
+ seqdtype = np.dtype([('', seqdtype)])
418
+ if not flatten or _zip_dtype((seqarrays,), flatten=True) == seqdtype:
419
+ # Minimal processing needed: just make sure everything's a-ok
420
+ seqarrays = seqarrays.ravel()
421
+ # Find what type of array we must return
422
+ if usemask:
423
+ if asrecarray:
424
+ seqtype = MaskedRecords
425
+ else:
426
+ seqtype = MaskedArray
427
+ elif asrecarray:
428
+ seqtype = recarray
429
+ else:
430
+ seqtype = ndarray
431
+ return seqarrays.view(dtype=seqdtype, type=seqtype)
432
+ else:
433
+ seqarrays = (seqarrays,)
434
+ else:
435
+ # Make sure we have arrays in the input sequence
436
+ seqarrays = [np.asanyarray(_m) for _m in seqarrays]
437
+ # Find the sizes of the inputs and their maximum
438
+ sizes = tuple(a.size for a in seqarrays)
439
+ maxlength = max(sizes)
440
+ # Get the dtype of the output (flattening if needed)
441
+ newdtype = _zip_dtype(seqarrays, flatten=flatten)
442
+ # Initialize the sequences for data and mask
443
+ seqdata = []
444
+ seqmask = []
445
+ # If we expect some kind of MaskedArray, make a special loop.
446
+ if usemask:
447
+ for (a, n) in zip(seqarrays, sizes):
448
+ nbmissing = (maxlength - n)
449
+ # Get the data and mask
450
+ data = a.ravel().__array__()
451
+ mask = ma.getmaskarray(a).ravel()
452
+ # Get the filling value (if needed)
453
+ if nbmissing:
454
+ fval = _check_fill_value(fill_value, a.dtype)
455
+ if isinstance(fval, (ndarray, np.void)):
456
+ if len(fval.dtype) == 1:
457
+ fval = fval.item()[0]
458
+ fmsk = True
459
+ else:
460
+ fval = np.array(fval, dtype=a.dtype, ndmin=1)
461
+ fmsk = np.ones((1,), dtype=mask.dtype)
462
+ else:
463
+ fval = None
464
+ fmsk = True
465
+ # Store an iterator padding the input to the expected length
466
+ seqdata.append(itertools.chain(data, [fval] * nbmissing))
467
+ seqmask.append(itertools.chain(mask, [fmsk] * nbmissing))
468
+ # Create an iterator for the data
469
+ data = tuple(_izip_records(seqdata, flatten=flatten))
470
+ output = ma.array(np.fromiter(data, dtype=newdtype, count=maxlength),
471
+ mask=list(_izip_records(seqmask, flatten=flatten)))
472
+ if asrecarray:
473
+ output = output.view(MaskedRecords)
474
+ else:
475
+ # Same as before, without the mask we don't need...
476
+ for (a, n) in zip(seqarrays, sizes):
477
+ nbmissing = (maxlength - n)
478
+ data = a.ravel().__array__()
479
+ if nbmissing:
480
+ fval = _check_fill_value(fill_value, a.dtype)
481
+ if isinstance(fval, (ndarray, np.void)):
482
+ if len(fval.dtype) == 1:
483
+ fval = fval.item()[0]
484
+ else:
485
+ fval = np.array(fval, dtype=a.dtype, ndmin=1)
486
+ else:
487
+ fval = None
488
+ seqdata.append(itertools.chain(data, [fval] * nbmissing))
489
+ output = np.fromiter(tuple(_izip_records(seqdata, flatten=flatten)),
490
+ dtype=newdtype, count=maxlength)
491
+ if asrecarray:
492
+ output = output.view(recarray)
493
+ # And we're done...
494
+ return output
495
+
496
+
497
+ def _drop_fields_dispatcher(base, drop_names, usemask=None, asrecarray=None):
498
+ return (base,)
499
+
500
+
501
+ @array_function_dispatch(_drop_fields_dispatcher)
502
+ def drop_fields(base, drop_names, usemask=True, asrecarray=False):
503
+ """
504
+ Return a new array with fields in `drop_names` dropped.
505
+
506
+ Nested fields are supported.
507
+
508
+ .. versionchanged:: 1.18.0
509
+ `drop_fields` returns an array with 0 fields if all fields are dropped,
510
+ rather than returning ``None`` as it did previously.
511
+
512
+ Parameters
513
+ ----------
514
+ base : array
515
+ Input array
516
+ drop_names : string or sequence
517
+ String or sequence of strings corresponding to the names of the
518
+ fields to drop.
519
+ usemask : {False, True}, optional
520
+ Whether to return a masked array or not.
521
+ asrecarray : string or sequence, optional
522
+ Whether to return a recarray or a mrecarray (`asrecarray=True`) or
523
+ a plain ndarray or masked array with flexible dtype. The default
524
+ is False.
525
+
526
+ Examples
527
+ --------
528
+ >>> from numpy.lib import recfunctions as rfn
529
+ >>> a = np.array([(1, (2, 3.0)), (4, (5, 6.0))],
530
+ ... dtype=[('a', np.int64), ('b', [('ba', np.double), ('bb', np.int64)])])
531
+ >>> rfn.drop_fields(a, 'a')
532
+ array([((2., 3),), ((5., 6),)],
533
+ dtype=[('b', [('ba', '<f8'), ('bb', '<i8')])])
534
+ >>> rfn.drop_fields(a, 'ba')
535
+ array([(1, (3,)), (4, (6,))], dtype=[('a', '<i8'), ('b', [('bb', '<i8')])])
536
+ >>> rfn.drop_fields(a, ['ba', 'bb'])
537
+ array([(1,), (4,)], dtype=[('a', '<i8')])
538
+ """
539
+ if _is_string_like(drop_names):
540
+ drop_names = [drop_names]
541
+ else:
542
+ drop_names = set(drop_names)
543
+
544
+ def _drop_descr(ndtype, drop_names):
545
+ names = ndtype.names
546
+ newdtype = []
547
+ for name in names:
548
+ current = ndtype[name]
549
+ if name in drop_names:
550
+ continue
551
+ if current.names is not None:
552
+ descr = _drop_descr(current, drop_names)
553
+ if descr:
554
+ newdtype.append((name, descr))
555
+ else:
556
+ newdtype.append((name, current))
557
+ return newdtype
558
+
559
+ newdtype = _drop_descr(base.dtype, drop_names)
560
+
561
+ output = np.empty(base.shape, dtype=newdtype)
562
+ output = recursive_fill_fields(base, output)
563
+ return _fix_output(output, usemask=usemask, asrecarray=asrecarray)
564
+
565
+
566
+ def _keep_fields(base, keep_names, usemask=True, asrecarray=False):
567
+ """
568
+ Return a new array keeping only the fields in `keep_names`,
569
+ and preserving the order of those fields.
570
+
571
+ Parameters
572
+ ----------
573
+ base : array
574
+ Input array
575
+ keep_names : string or sequence
576
+ String or sequence of strings corresponding to the names of the
577
+ fields to keep. Order of the names will be preserved.
578
+ usemask : {False, True}, optional
579
+ Whether to return a masked array or not.
580
+ asrecarray : string or sequence, optional
581
+ Whether to return a recarray or a mrecarray (`asrecarray=True`) or
582
+ a plain ndarray or masked array with flexible dtype. The default
583
+ is False.
584
+ """
585
+ newdtype = [(n, base.dtype[n]) for n in keep_names]
586
+ output = np.empty(base.shape, dtype=newdtype)
587
+ output = recursive_fill_fields(base, output)
588
+ return _fix_output(output, usemask=usemask, asrecarray=asrecarray)
589
+
590
+
591
+ def _rec_drop_fields_dispatcher(base, drop_names):
592
+ return (base,)
593
+
594
+
595
+ @array_function_dispatch(_rec_drop_fields_dispatcher)
596
+ def rec_drop_fields(base, drop_names):
597
+ """
598
+ Returns a new numpy.recarray with fields in `drop_names` dropped.
599
+ """
600
+ return drop_fields(base, drop_names, usemask=False, asrecarray=True)
601
+
602
+
603
+ def _rename_fields_dispatcher(base, namemapper):
604
+ return (base,)
605
+
606
+
607
+ @array_function_dispatch(_rename_fields_dispatcher)
608
+ def rename_fields(base, namemapper):
609
+ """
610
+ Rename the fields from a flexible-datatype ndarray or recarray.
611
+
612
+ Nested fields are supported.
613
+
614
+ Parameters
615
+ ----------
616
+ base : ndarray
617
+ Input array whose fields must be modified.
618
+ namemapper : dictionary
619
+ Dictionary mapping old field names to their new version.
620
+
621
+ Examples
622
+ --------
623
+ >>> from numpy.lib import recfunctions as rfn
624
+ >>> a = np.array([(1, (2, [3.0, 30.])), (4, (5, [6.0, 60.]))],
625
+ ... dtype=[('a', int),('b', [('ba', float), ('bb', (float, 2))])])
626
+ >>> rfn.rename_fields(a, {'a':'A', 'bb':'BB'})
627
+ array([(1, (2., [ 3., 30.])), (4, (5., [ 6., 60.]))],
628
+ dtype=[('A', '<i8'), ('b', [('ba', '<f8'), ('BB', '<f8', (2,))])])
629
+
630
+ """
631
+ def _recursive_rename_fields(ndtype, namemapper):
632
+ newdtype = []
633
+ for name in ndtype.names:
634
+ newname = namemapper.get(name, name)
635
+ current = ndtype[name]
636
+ if current.names is not None:
637
+ newdtype.append(
638
+ (newname, _recursive_rename_fields(current, namemapper))
639
+ )
640
+ else:
641
+ newdtype.append((newname, current))
642
+ return newdtype
643
+ newdtype = _recursive_rename_fields(base.dtype, namemapper)
644
+ return base.view(newdtype)
645
+
646
+
647
+ def _append_fields_dispatcher(base, names, data, dtypes=None,
648
+ fill_value=None, usemask=None, asrecarray=None):
649
+ yield base
650
+ yield from data
651
+
652
+
653
+ @array_function_dispatch(_append_fields_dispatcher)
654
+ def append_fields(base, names, data, dtypes=None,
655
+ fill_value=-1, usemask=True, asrecarray=False):
656
+ """
657
+ Add new fields to an existing array.
658
+
659
+ The names of the fields are given with the `names` arguments,
660
+ the corresponding values with the `data` arguments.
661
+ If a single field is appended, `names`, `data` and `dtypes` do not have
662
+ to be lists but just values.
663
+
664
+ Parameters
665
+ ----------
666
+ base : array
667
+ Input array to extend.
668
+ names : string, sequence
669
+ String or sequence of strings corresponding to the names
670
+ of the new fields.
671
+ data : array or sequence of arrays
672
+ Array or sequence of arrays storing the fields to add to the base.
673
+ dtypes : sequence of datatypes, optional
674
+ Datatype or sequence of datatypes.
675
+ If None, the datatypes are estimated from the `data`.
676
+ fill_value : {float}, optional
677
+ Filling value used to pad missing data on the shorter arrays.
678
+ usemask : {False, True}, optional
679
+ Whether to return a masked array or not.
680
+ asrecarray : {False, True}, optional
681
+ Whether to return a recarray (MaskedRecords) or not.
682
+
683
+ """
684
+ # Check the names
685
+ if isinstance(names, (tuple, list)):
686
+ if len(names) != len(data):
687
+ msg = "The number of arrays does not match the number of names"
688
+ raise ValueError(msg)
689
+ elif isinstance(names, str):
690
+ names = [names, ]
691
+ data = [data, ]
692
+ #
693
+ if dtypes is None:
694
+ data = [np.array(a, copy=False, subok=True) for a in data]
695
+ data = [a.view([(name, a.dtype)]) for (name, a) in zip(names, data)]
696
+ else:
697
+ if not isinstance(dtypes, (tuple, list)):
698
+ dtypes = [dtypes, ]
699
+ if len(data) != len(dtypes):
700
+ if len(dtypes) == 1:
701
+ dtypes = dtypes * len(data)
702
+ else:
703
+ msg = "The dtypes argument must be None, a dtype, or a list."
704
+ raise ValueError(msg)
705
+ data = [np.array(a, copy=False, subok=True, dtype=d).view([(n, d)])
706
+ for (a, n, d) in zip(data, names, dtypes)]
707
+ #
708
+ base = merge_arrays(base, usemask=usemask, fill_value=fill_value)
709
+ if len(data) > 1:
710
+ data = merge_arrays(data, flatten=True, usemask=usemask,
711
+ fill_value=fill_value)
712
+ else:
713
+ data = data.pop()
714
+ #
715
+ output = ma.masked_all(
716
+ max(len(base), len(data)),
717
+ dtype=_get_fieldspec(base.dtype) + _get_fieldspec(data.dtype))
718
+ output = recursive_fill_fields(base, output)
719
+ output = recursive_fill_fields(data, output)
720
+ #
721
+ return _fix_output(output, usemask=usemask, asrecarray=asrecarray)
722
+
723
+
724
+ def _rec_append_fields_dispatcher(base, names, data, dtypes=None):
725
+ yield base
726
+ yield from data
727
+
728
+
729
+ @array_function_dispatch(_rec_append_fields_dispatcher)
730
+ def rec_append_fields(base, names, data, dtypes=None):
731
+ """
732
+ Add new fields to an existing array.
733
+
734
+ The names of the fields are given with the `names` arguments,
735
+ the corresponding values with the `data` arguments.
736
+ If a single field is appended, `names`, `data` and `dtypes` do not have
737
+ to be lists but just values.
738
+
739
+ Parameters
740
+ ----------
741
+ base : array
742
+ Input array to extend.
743
+ names : string, sequence
744
+ String or sequence of strings corresponding to the names
745
+ of the new fields.
746
+ data : array or sequence of arrays
747
+ Array or sequence of arrays storing the fields to add to the base.
748
+ dtypes : sequence of datatypes, optional
749
+ Datatype or sequence of datatypes.
750
+ If None, the datatypes are estimated from the `data`.
751
+
752
+ See Also
753
+ --------
754
+ append_fields
755
+
756
+ Returns
757
+ -------
758
+ appended_array : np.recarray
759
+ """
760
+ return append_fields(base, names, data=data, dtypes=dtypes,
761
+ asrecarray=True, usemask=False)
762
+
763
+
764
+ def _repack_fields_dispatcher(a, align=None, recurse=None):
765
+ return (a,)
766
+
767
+
768
+ @array_function_dispatch(_repack_fields_dispatcher)
769
+ def repack_fields(a, align=False, recurse=False):
770
+ """
771
+ Re-pack the fields of a structured array or dtype in memory.
772
+
773
+ The memory layout of structured datatypes allows fields at arbitrary
774
+ byte offsets. This means the fields can be separated by padding bytes,
775
+ their offsets can be non-monotonically increasing, and they can overlap.
776
+
777
+ This method removes any overlaps and reorders the fields in memory so they
778
+ have increasing byte offsets, and adds or removes padding bytes depending
779
+ on the `align` option, which behaves like the `align` option to
780
+ `numpy.dtype`.
781
+
782
+ If `align=False`, this method produces a "packed" memory layout in which
783
+ each field starts at the byte the previous field ended, and any padding
784
+ bytes are removed.
785
+
786
+ If `align=True`, this methods produces an "aligned" memory layout in which
787
+ each field's offset is a multiple of its alignment, and the total itemsize
788
+ is a multiple of the largest alignment, by adding padding bytes as needed.
789
+
790
+ Parameters
791
+ ----------
792
+ a : ndarray or dtype
793
+ array or dtype for which to repack the fields.
794
+ align : boolean
795
+ If true, use an "aligned" memory layout, otherwise use a "packed" layout.
796
+ recurse : boolean
797
+ If True, also repack nested structures.
798
+
799
+ Returns
800
+ -------
801
+ repacked : ndarray or dtype
802
+ Copy of `a` with fields repacked, or `a` itself if no repacking was
803
+ needed.
804
+
805
+ Examples
806
+ --------
807
+
808
+ >>> from numpy.lib import recfunctions as rfn
809
+ >>> def print_offsets(d):
810
+ ... print("offsets:", [d.fields[name][1] for name in d.names])
811
+ ... print("itemsize:", d.itemsize)
812
+ ...
813
+ >>> dt = np.dtype('u1, <i8, <f8', align=True)
814
+ >>> dt
815
+ dtype({'names': ['f0', 'f1', 'f2'], 'formats': ['u1', '<i8', '<f8'], \
816
+ 'offsets': [0, 8, 16], 'itemsize': 24}, align=True)
817
+ >>> print_offsets(dt)
818
+ offsets: [0, 8, 16]
819
+ itemsize: 24
820
+ >>> packed_dt = rfn.repack_fields(dt)
821
+ >>> packed_dt
822
+ dtype([('f0', 'u1'), ('f1', '<i8'), ('f2', '<f8')])
823
+ >>> print_offsets(packed_dt)
824
+ offsets: [0, 1, 9]
825
+ itemsize: 17
826
+
827
+ """
828
+ if not isinstance(a, np.dtype):
829
+ dt = repack_fields(a.dtype, align=align, recurse=recurse)
830
+ return a.astype(dt, copy=False)
831
+
832
+ if a.names is None:
833
+ return a
834
+
835
+ fieldinfo = []
836
+ for name in a.names:
837
+ tup = a.fields[name]
838
+ if recurse:
839
+ fmt = repack_fields(tup[0], align=align, recurse=True)
840
+ else:
841
+ fmt = tup[0]
842
+
843
+ if len(tup) == 3:
844
+ name = (tup[2], name)
845
+
846
+ fieldinfo.append((name, fmt))
847
+
848
+ dt = np.dtype(fieldinfo, align=align)
849
+ return np.dtype((a.type, dt))
850
+
851
+ def _get_fields_and_offsets(dt, offset=0):
852
+ """
853
+ Returns a flat list of (dtype, count, offset) tuples of all the
854
+ scalar fields in the dtype "dt", including nested fields, in left
855
+ to right order.
856
+ """
857
+
858
+ # counts up elements in subarrays, including nested subarrays, and returns
859
+ # base dtype and count
860
+ def count_elem(dt):
861
+ count = 1
862
+ while dt.shape != ():
863
+ for size in dt.shape:
864
+ count *= size
865
+ dt = dt.base
866
+ return dt, count
867
+
868
+ fields = []
869
+ for name in dt.names:
870
+ field = dt.fields[name]
871
+ f_dt, f_offset = field[0], field[1]
872
+ f_dt, n = count_elem(f_dt)
873
+
874
+ if f_dt.names is None:
875
+ fields.append((np.dtype((f_dt, (n,))), n, f_offset + offset))
876
+ else:
877
+ subfields = _get_fields_and_offsets(f_dt, f_offset + offset)
878
+ size = f_dt.itemsize
879
+
880
+ for i in range(n):
881
+ if i == 0:
882
+ # optimization: avoid list comprehension if no subarray
883
+ fields.extend(subfields)
884
+ else:
885
+ fields.extend([(d, c, o + i*size) for d, c, o in subfields])
886
+ return fields
887
+
888
+ def _common_stride(offsets, counts, itemsize):
889
+ """
890
+ Returns the stride between the fields, or None if the stride is not
891
+ constant. The values in "counts" designate the lengths of
892
+ subarrays. Subarrays are treated as many contiguous fields, with
893
+ always positive stride.
894
+ """
895
+ if len(offsets) <= 1:
896
+ return itemsize
897
+
898
+ negative = offsets[1] < offsets[0] # negative stride
899
+ if negative:
900
+ # reverse, so offsets will be ascending
901
+ it = zip(reversed(offsets), reversed(counts))
902
+ else:
903
+ it = zip(offsets, counts)
904
+
905
+ prev_offset = None
906
+ stride = None
907
+ for offset, count in it:
908
+ if count != 1: # subarray: always c-contiguous
909
+ if negative:
910
+ return None # subarrays can never have a negative stride
911
+ if stride is None:
912
+ stride = itemsize
913
+ if stride != itemsize:
914
+ return None
915
+ end_offset = offset + (count - 1) * itemsize
916
+ else:
917
+ end_offset = offset
918
+
919
+ if prev_offset is not None:
920
+ new_stride = offset - prev_offset
921
+ if stride is None:
922
+ stride = new_stride
923
+ if stride != new_stride:
924
+ return None
925
+
926
+ prev_offset = end_offset
927
+
928
+ if negative:
929
+ return -stride
930
+ return stride
931
+
932
+
933
+ def _structured_to_unstructured_dispatcher(arr, dtype=None, copy=None,
934
+ casting=None):
935
+ return (arr,)
936
+
937
+ @array_function_dispatch(_structured_to_unstructured_dispatcher)
938
+ def structured_to_unstructured(arr, dtype=None, copy=False, casting='unsafe'):
939
+ """
940
+ Converts an n-D structured array into an (n+1)-D unstructured array.
941
+
942
+ The new array will have a new last dimension equal in size to the
943
+ number of field-elements of the input array. If not supplied, the output
944
+ datatype is determined from the numpy type promotion rules applied to all
945
+ the field datatypes.
946
+
947
+ Nested fields, as well as each element of any subarray fields, all count
948
+ as a single field-elements.
949
+
950
+ Parameters
951
+ ----------
952
+ arr : ndarray
953
+ Structured array or dtype to convert. Cannot contain object datatype.
954
+ dtype : dtype, optional
955
+ The dtype of the output unstructured array.
956
+ copy : bool, optional
957
+ If true, always return a copy. If false, a view is returned if
958
+ possible, such as when the `dtype` and strides of the fields are
959
+ suitable and the array subtype is one of `np.ndarray`, `np.recarray`
960
+ or `np.memmap`.
961
+
962
+ .. versionchanged:: 1.25.0
963
+ A view can now be returned if the fields are separated by a
964
+ uniform stride.
965
+
966
+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
967
+ See casting argument of `numpy.ndarray.astype`. Controls what kind of
968
+ data casting may occur.
969
+
970
+ Returns
971
+ -------
972
+ unstructured : ndarray
973
+ Unstructured array with one more dimension.
974
+
975
+ Examples
976
+ --------
977
+
978
+ >>> from numpy.lib import recfunctions as rfn
979
+ >>> a = np.zeros(4, dtype=[('a', 'i4'), ('b', 'f4,u2'), ('c', 'f4', 2)])
980
+ >>> a
981
+ array([(0, (0., 0), [0., 0.]), (0, (0., 0), [0., 0.]),
982
+ (0, (0., 0), [0., 0.]), (0, (0., 0), [0., 0.])],
983
+ dtype=[('a', '<i4'), ('b', [('f0', '<f4'), ('f1', '<u2')]), ('c', '<f4', (2,))])
984
+ >>> rfn.structured_to_unstructured(a)
985
+ array([[0., 0., 0., 0., 0.],
986
+ [0., 0., 0., 0., 0.],
987
+ [0., 0., 0., 0., 0.],
988
+ [0., 0., 0., 0., 0.]])
989
+
990
+ >>> b = np.array([(1, 2, 5), (4, 5, 7), (7, 8 ,11), (10, 11, 12)],
991
+ ... dtype=[('x', 'i4'), ('y', 'f4'), ('z', 'f8')])
992
+ >>> np.mean(rfn.structured_to_unstructured(b[['x', 'z']]), axis=-1)
993
+ array([ 3. , 5.5, 9. , 11. ])
994
+
995
+ """
996
+ if arr.dtype.names is None:
997
+ raise ValueError('arr must be a structured array')
998
+
999
+ fields = _get_fields_and_offsets(arr.dtype)
1000
+ n_fields = len(fields)
1001
+ if n_fields == 0 and dtype is None:
1002
+ raise ValueError("arr has no fields. Unable to guess dtype")
1003
+ elif n_fields == 0:
1004
+ # too many bugs elsewhere for this to work now
1005
+ raise NotImplementedError("arr with no fields is not supported")
1006
+
1007
+ dts, counts, offsets = zip(*fields)
1008
+ names = ['f{}'.format(n) for n in range(n_fields)]
1009
+
1010
+ if dtype is None:
1011
+ out_dtype = np.result_type(*[dt.base for dt in dts])
1012
+ else:
1013
+ out_dtype = np.dtype(dtype)
1014
+
1015
+ # Use a series of views and casts to convert to an unstructured array:
1016
+
1017
+ # first view using flattened fields (doesn't work for object arrays)
1018
+ # Note: dts may include a shape for subarrays
1019
+ flattened_fields = np.dtype({'names': names,
1020
+ 'formats': dts,
1021
+ 'offsets': offsets,
1022
+ 'itemsize': arr.dtype.itemsize})
1023
+ arr = arr.view(flattened_fields)
1024
+
1025
+ # we only allow a few types to be unstructured by manipulating the
1026
+ # strides, because we know it won't work with, for example, np.matrix nor
1027
+ # np.ma.MaskedArray.
1028
+ can_view = type(arr) in (np.ndarray, np.recarray, np.memmap)
1029
+ if (not copy) and can_view and all(dt.base == out_dtype for dt in dts):
1030
+ # all elements have the right dtype already; if they have a common
1031
+ # stride, we can just return a view
1032
+ common_stride = _common_stride(offsets, counts, out_dtype.itemsize)
1033
+ if common_stride is not None:
1034
+ wrap = arr.__array_wrap__
1035
+
1036
+ new_shape = arr.shape + (sum(counts), out_dtype.itemsize)
1037
+ new_strides = arr.strides + (abs(common_stride), 1)
1038
+
1039
+ arr = arr[..., np.newaxis].view(np.uint8) # view as bytes
1040
+ arr = arr[..., min(offsets):] # remove the leading unused data
1041
+ arr = np.lib.stride_tricks.as_strided(arr,
1042
+ new_shape,
1043
+ new_strides,
1044
+ subok=True)
1045
+
1046
+ # cast and drop the last dimension again
1047
+ arr = arr.view(out_dtype)[..., 0]
1048
+
1049
+ if common_stride < 0:
1050
+ arr = arr[..., ::-1] # reverse, if the stride was negative
1051
+ if type(arr) is not type(wrap.__self__):
1052
+ # Some types (e.g. recarray) turn into an ndarray along the
1053
+ # way, so we have to wrap it again in order to match the
1054
+ # behavior with copy=True.
1055
+ arr = wrap(arr)
1056
+ return arr
1057
+
1058
+ # next cast to a packed format with all fields converted to new dtype
1059
+ packed_fields = np.dtype({'names': names,
1060
+ 'formats': [(out_dtype, dt.shape) for dt in dts]})
1061
+ arr = arr.astype(packed_fields, copy=copy, casting=casting)
1062
+
1063
+ # finally is it safe to view the packed fields as the unstructured type
1064
+ return arr.view((out_dtype, (sum(counts),)))
1065
+
1066
+
1067
+ def _unstructured_to_structured_dispatcher(arr, dtype=None, names=None,
1068
+ align=None, copy=None, casting=None):
1069
+ return (arr,)
1070
+
1071
+ @array_function_dispatch(_unstructured_to_structured_dispatcher)
1072
+ def unstructured_to_structured(arr, dtype=None, names=None, align=False,
1073
+ copy=False, casting='unsafe'):
1074
+ """
1075
+ Converts an n-D unstructured array into an (n-1)-D structured array.
1076
+
1077
+ The last dimension of the input array is converted into a structure, with
1078
+ number of field-elements equal to the size of the last dimension of the
1079
+ input array. By default all output fields have the input array's dtype, but
1080
+ an output structured dtype with an equal number of fields-elements can be
1081
+ supplied instead.
1082
+
1083
+ Nested fields, as well as each element of any subarray fields, all count
1084
+ towards the number of field-elements.
1085
+
1086
+ Parameters
1087
+ ----------
1088
+ arr : ndarray
1089
+ Unstructured array or dtype to convert.
1090
+ dtype : dtype, optional
1091
+ The structured dtype of the output array
1092
+ names : list of strings, optional
1093
+ If dtype is not supplied, this specifies the field names for the output
1094
+ dtype, in order. The field dtypes will be the same as the input array.
1095
+ align : boolean, optional
1096
+ Whether to create an aligned memory layout.
1097
+ copy : bool, optional
1098
+ See copy argument to `numpy.ndarray.astype`. If true, always return a
1099
+ copy. If false, and `dtype` requirements are satisfied, a view is
1100
+ returned.
1101
+ casting : {'no', 'equiv', 'safe', 'same_kind', 'unsafe'}, optional
1102
+ See casting argument of `numpy.ndarray.astype`. Controls what kind of
1103
+ data casting may occur.
1104
+
1105
+ Returns
1106
+ -------
1107
+ structured : ndarray
1108
+ Structured array with fewer dimensions.
1109
+
1110
+ Examples
1111
+ --------
1112
+
1113
+ >>> from numpy.lib import recfunctions as rfn
1114
+ >>> dt = np.dtype([('a', 'i4'), ('b', 'f4,u2'), ('c', 'f4', 2)])
1115
+ >>> a = np.arange(20).reshape((4,5))
1116
+ >>> a
1117
+ array([[ 0, 1, 2, 3, 4],
1118
+ [ 5, 6, 7, 8, 9],
1119
+ [10, 11, 12, 13, 14],
1120
+ [15, 16, 17, 18, 19]])
1121
+ >>> rfn.unstructured_to_structured(a, dt)
1122
+ array([( 0, ( 1., 2), [ 3., 4.]), ( 5, ( 6., 7), [ 8., 9.]),
1123
+ (10, (11., 12), [13., 14.]), (15, (16., 17), [18., 19.])],
1124
+ dtype=[('a', '<i4'), ('b', [('f0', '<f4'), ('f1', '<u2')]), ('c', '<f4', (2,))])
1125
+
1126
+ """
1127
+ if arr.shape == ():
1128
+ raise ValueError('arr must have at least one dimension')
1129
+ n_elem = arr.shape[-1]
1130
+ if n_elem == 0:
1131
+ # too many bugs elsewhere for this to work now
1132
+ raise NotImplementedError("last axis with size 0 is not supported")
1133
+
1134
+ if dtype is None:
1135
+ if names is None:
1136
+ names = ['f{}'.format(n) for n in range(n_elem)]
1137
+ out_dtype = np.dtype([(n, arr.dtype) for n in names], align=align)
1138
+ fields = _get_fields_and_offsets(out_dtype)
1139
+ dts, counts, offsets = zip(*fields)
1140
+ else:
1141
+ if names is not None:
1142
+ raise ValueError("don't supply both dtype and names")
1143
+ # if dtype is the args of np.dtype, construct it
1144
+ dtype = np.dtype(dtype)
1145
+ # sanity check of the input dtype
1146
+ fields = _get_fields_and_offsets(dtype)
1147
+ if len(fields) == 0:
1148
+ dts, counts, offsets = [], [], []
1149
+ else:
1150
+ dts, counts, offsets = zip(*fields)
1151
+
1152
+ if n_elem != sum(counts):
1153
+ raise ValueError('The length of the last dimension of arr must '
1154
+ 'be equal to the number of fields in dtype')
1155
+ out_dtype = dtype
1156
+ if align and not out_dtype.isalignedstruct:
1157
+ raise ValueError("align was True but dtype is not aligned")
1158
+
1159
+ names = ['f{}'.format(n) for n in range(len(fields))]
1160
+
1161
+ # Use a series of views and casts to convert to a structured array:
1162
+
1163
+ # first view as a packed structured array of one dtype
1164
+ packed_fields = np.dtype({'names': names,
1165
+ 'formats': [(arr.dtype, dt.shape) for dt in dts]})
1166
+ arr = np.ascontiguousarray(arr).view(packed_fields)
1167
+
1168
+ # next cast to an unpacked but flattened format with varied dtypes
1169
+ flattened_fields = np.dtype({'names': names,
1170
+ 'formats': dts,
1171
+ 'offsets': offsets,
1172
+ 'itemsize': out_dtype.itemsize})
1173
+ arr = arr.astype(flattened_fields, copy=copy, casting=casting)
1174
+
1175
+ # finally view as the final nested dtype and remove the last axis
1176
+ return arr.view(out_dtype)[..., 0]
1177
+
1178
+ def _apply_along_fields_dispatcher(func, arr):
1179
+ return (arr,)
1180
+
1181
+ @array_function_dispatch(_apply_along_fields_dispatcher)
1182
+ def apply_along_fields(func, arr):
1183
+ """
1184
+ Apply function 'func' as a reduction across fields of a structured array.
1185
+
1186
+ This is similar to `apply_along_axis`, but treats the fields of a
1187
+ structured array as an extra axis. The fields are all first cast to a
1188
+ common type following the type-promotion rules from `numpy.result_type`
1189
+ applied to the field's dtypes.
1190
+
1191
+ Parameters
1192
+ ----------
1193
+ func : function
1194
+ Function to apply on the "field" dimension. This function must
1195
+ support an `axis` argument, like np.mean, np.sum, etc.
1196
+ arr : ndarray
1197
+ Structured array for which to apply func.
1198
+
1199
+ Returns
1200
+ -------
1201
+ out : ndarray
1202
+ Result of the recution operation
1203
+
1204
+ Examples
1205
+ --------
1206
+
1207
+ >>> from numpy.lib import recfunctions as rfn
1208
+ >>> b = np.array([(1, 2, 5), (4, 5, 7), (7, 8 ,11), (10, 11, 12)],
1209
+ ... dtype=[('x', 'i4'), ('y', 'f4'), ('z', 'f8')])
1210
+ >>> rfn.apply_along_fields(np.mean, b)
1211
+ array([ 2.66666667, 5.33333333, 8.66666667, 11. ])
1212
+ >>> rfn.apply_along_fields(np.mean, b[['x', 'z']])
1213
+ array([ 3. , 5.5, 9. , 11. ])
1214
+
1215
+ """
1216
+ if arr.dtype.names is None:
1217
+ raise ValueError('arr must be a structured array')
1218
+
1219
+ uarr = structured_to_unstructured(arr)
1220
+ return func(uarr, axis=-1)
1221
+ # works and avoids axis requirement, but very, very slow:
1222
+ #return np.apply_along_axis(func, -1, uarr)
1223
+
1224
+ def _assign_fields_by_name_dispatcher(dst, src, zero_unassigned=None):
1225
+ return dst, src
1226
+
1227
+ @array_function_dispatch(_assign_fields_by_name_dispatcher)
1228
+ def assign_fields_by_name(dst, src, zero_unassigned=True):
1229
+ """
1230
+ Assigns values from one structured array to another by field name.
1231
+
1232
+ Normally in numpy >= 1.14, assignment of one structured array to another
1233
+ copies fields "by position", meaning that the first field from the src is
1234
+ copied to the first field of the dst, and so on, regardless of field name.
1235
+
1236
+ This function instead copies "by field name", such that fields in the dst
1237
+ are assigned from the identically named field in the src. This applies
1238
+ recursively for nested structures. This is how structure assignment worked
1239
+ in numpy >= 1.6 to <= 1.13.
1240
+
1241
+ Parameters
1242
+ ----------
1243
+ dst : ndarray
1244
+ src : ndarray
1245
+ The source and destination arrays during assignment.
1246
+ zero_unassigned : bool, optional
1247
+ If True, fields in the dst for which there was no matching
1248
+ field in the src are filled with the value 0 (zero). This
1249
+ was the behavior of numpy <= 1.13. If False, those fields
1250
+ are not modified.
1251
+ """
1252
+
1253
+ if dst.dtype.names is None:
1254
+ dst[...] = src
1255
+ return
1256
+
1257
+ for name in dst.dtype.names:
1258
+ if name not in src.dtype.names:
1259
+ if zero_unassigned:
1260
+ dst[name] = 0
1261
+ else:
1262
+ assign_fields_by_name(dst[name], src[name],
1263
+ zero_unassigned)
1264
+
1265
+ def _require_fields_dispatcher(array, required_dtype):
1266
+ return (array,)
1267
+
1268
+ @array_function_dispatch(_require_fields_dispatcher)
1269
+ def require_fields(array, required_dtype):
1270
+ """
1271
+ Casts a structured array to a new dtype using assignment by field-name.
1272
+
1273
+ This function assigns from the old to the new array by name, so the
1274
+ value of a field in the output array is the value of the field with the
1275
+ same name in the source array. This has the effect of creating a new
1276
+ ndarray containing only the fields "required" by the required_dtype.
1277
+
1278
+ If a field name in the required_dtype does not exist in the
1279
+ input array, that field is created and set to 0 in the output array.
1280
+
1281
+ Parameters
1282
+ ----------
1283
+ a : ndarray
1284
+ array to cast
1285
+ required_dtype : dtype
1286
+ datatype for output array
1287
+
1288
+ Returns
1289
+ -------
1290
+ out : ndarray
1291
+ array with the new dtype, with field values copied from the fields in
1292
+ the input array with the same name
1293
+
1294
+ Examples
1295
+ --------
1296
+
1297
+ >>> from numpy.lib import recfunctions as rfn
1298
+ >>> a = np.ones(4, dtype=[('a', 'i4'), ('b', 'f8'), ('c', 'u1')])
1299
+ >>> rfn.require_fields(a, [('b', 'f4'), ('c', 'u1')])
1300
+ array([(1., 1), (1., 1), (1., 1), (1., 1)],
1301
+ dtype=[('b', '<f4'), ('c', 'u1')])
1302
+ >>> rfn.require_fields(a, [('b', 'f4'), ('newf', 'u1')])
1303
+ array([(1., 0), (1., 0), (1., 0), (1., 0)],
1304
+ dtype=[('b', '<f4'), ('newf', 'u1')])
1305
+
1306
+ """
1307
+ out = np.empty(array.shape, dtype=required_dtype)
1308
+ assign_fields_by_name(out, array)
1309
+ return out
1310
+
1311
+
1312
+ def _stack_arrays_dispatcher(arrays, defaults=None, usemask=None,
1313
+ asrecarray=None, autoconvert=None):
1314
+ return arrays
1315
+
1316
+
1317
+ @array_function_dispatch(_stack_arrays_dispatcher)
1318
+ def stack_arrays(arrays, defaults=None, usemask=True, asrecarray=False,
1319
+ autoconvert=False):
1320
+ """
1321
+ Superposes arrays fields by fields
1322
+
1323
+ Parameters
1324
+ ----------
1325
+ arrays : array or sequence
1326
+ Sequence of input arrays.
1327
+ defaults : dictionary, optional
1328
+ Dictionary mapping field names to the corresponding default values.
1329
+ usemask : {True, False}, optional
1330
+ Whether to return a MaskedArray (or MaskedRecords is
1331
+ `asrecarray==True`) or a ndarray.
1332
+ asrecarray : {False, True}, optional
1333
+ Whether to return a recarray (or MaskedRecords if `usemask==True`)
1334
+ or just a flexible-type ndarray.
1335
+ autoconvert : {False, True}, optional
1336
+ Whether automatically cast the type of the field to the maximum.
1337
+
1338
+ Examples
1339
+ --------
1340
+ >>> from numpy.lib import recfunctions as rfn
1341
+ >>> x = np.array([1, 2,])
1342
+ >>> rfn.stack_arrays(x) is x
1343
+ True
1344
+ >>> z = np.array([('A', 1), ('B', 2)], dtype=[('A', '|S3'), ('B', float)])
1345
+ >>> zz = np.array([('a', 10., 100.), ('b', 20., 200.), ('c', 30., 300.)],
1346
+ ... dtype=[('A', '|S3'), ('B', np.double), ('C', np.double)])
1347
+ >>> test = rfn.stack_arrays((z,zz))
1348
+ >>> test
1349
+ masked_array(data=[(b'A', 1.0, --), (b'B', 2.0, --), (b'a', 10.0, 100.0),
1350
+ (b'b', 20.0, 200.0), (b'c', 30.0, 300.0)],
1351
+ mask=[(False, False, True), (False, False, True),
1352
+ (False, False, False), (False, False, False),
1353
+ (False, False, False)],
1354
+ fill_value=(b'N/A', 1.e+20, 1.e+20),
1355
+ dtype=[('A', 'S3'), ('B', '<f8'), ('C', '<f8')])
1356
+
1357
+ """
1358
+ if isinstance(arrays, ndarray):
1359
+ return arrays
1360
+ elif len(arrays) == 1:
1361
+ return arrays[0]
1362
+ seqarrays = [np.asanyarray(a).ravel() for a in arrays]
1363
+ nrecords = [len(a) for a in seqarrays]
1364
+ ndtype = [a.dtype for a in seqarrays]
1365
+ fldnames = [d.names for d in ndtype]
1366
+ #
1367
+ dtype_l = ndtype[0]
1368
+ newdescr = _get_fieldspec(dtype_l)
1369
+ names = [n for n, d in newdescr]
1370
+ for dtype_n in ndtype[1:]:
1371
+ for fname, fdtype in _get_fieldspec(dtype_n):
1372
+ if fname not in names:
1373
+ newdescr.append((fname, fdtype))
1374
+ names.append(fname)
1375
+ else:
1376
+ nameidx = names.index(fname)
1377
+ _, cdtype = newdescr[nameidx]
1378
+ if autoconvert:
1379
+ newdescr[nameidx] = (fname, max(fdtype, cdtype))
1380
+ elif fdtype != cdtype:
1381
+ raise TypeError("Incompatible type '%s' <> '%s'" %
1382
+ (cdtype, fdtype))
1383
+ # Only one field: use concatenate
1384
+ if len(newdescr) == 1:
1385
+ output = ma.concatenate(seqarrays)
1386
+ else:
1387
+ #
1388
+ output = ma.masked_all((np.sum(nrecords),), newdescr)
1389
+ offset = np.cumsum(np.r_[0, nrecords])
1390
+ seen = []
1391
+ for (a, n, i, j) in zip(seqarrays, fldnames, offset[:-1], offset[1:]):
1392
+ names = a.dtype.names
1393
+ if names is None:
1394
+ output['f%i' % len(seen)][i:j] = a
1395
+ else:
1396
+ for name in n:
1397
+ output[name][i:j] = a[name]
1398
+ if name not in seen:
1399
+ seen.append(name)
1400
+ #
1401
+ return _fix_output(_fix_defaults(output, defaults),
1402
+ usemask=usemask, asrecarray=asrecarray)
1403
+
1404
+
1405
+ def _find_duplicates_dispatcher(
1406
+ a, key=None, ignoremask=None, return_index=None):
1407
+ return (a,)
1408
+
1409
+
1410
+ @array_function_dispatch(_find_duplicates_dispatcher)
1411
+ def find_duplicates(a, key=None, ignoremask=True, return_index=False):
1412
+ """
1413
+ Find the duplicates in a structured array along a given key
1414
+
1415
+ Parameters
1416
+ ----------
1417
+ a : array-like
1418
+ Input array
1419
+ key : {string, None}, optional
1420
+ Name of the fields along which to check the duplicates.
1421
+ If None, the search is performed by records
1422
+ ignoremask : {True, False}, optional
1423
+ Whether masked data should be discarded or considered as duplicates.
1424
+ return_index : {False, True}, optional
1425
+ Whether to return the indices of the duplicated values.
1426
+
1427
+ Examples
1428
+ --------
1429
+ >>> from numpy.lib import recfunctions as rfn
1430
+ >>> ndtype = [('a', int)]
1431
+ >>> a = np.ma.array([1, 1, 1, 2, 2, 3, 3],
1432
+ ... mask=[0, 0, 1, 0, 0, 0, 1]).view(ndtype)
1433
+ >>> rfn.find_duplicates(a, ignoremask=True, return_index=True)
1434
+ (masked_array(data=[(1,), (1,), (2,), (2,)],
1435
+ mask=[(False,), (False,), (False,), (False,)],
1436
+ fill_value=(999999,),
1437
+ dtype=[('a', '<i8')]), array([0, 1, 3, 4]))
1438
+ """
1439
+ a = np.asanyarray(a).ravel()
1440
+ # Get a dictionary of fields
1441
+ fields = get_fieldstructure(a.dtype)
1442
+ # Get the sorting data (by selecting the corresponding field)
1443
+ base = a
1444
+ if key:
1445
+ for f in fields[key]:
1446
+ base = base[f]
1447
+ base = base[key]
1448
+ # Get the sorting indices and the sorted data
1449
+ sortidx = base.argsort()
1450
+ sortedbase = base[sortidx]
1451
+ sorteddata = sortedbase.filled()
1452
+ # Compare the sorting data
1453
+ flag = (sorteddata[:-1] == sorteddata[1:])
1454
+ # If masked data must be ignored, set the flag to false where needed
1455
+ if ignoremask:
1456
+ sortedmask = sortedbase.recordmask
1457
+ flag[sortedmask[1:]] = False
1458
+ flag = np.concatenate(([False], flag))
1459
+ # We need to take the point on the left as well (else we're missing it)
1460
+ flag[:-1] = flag[:-1] + flag[1:]
1461
+ duplicates = a[sortidx][flag]
1462
+ if return_index:
1463
+ return (duplicates, sortidx[flag])
1464
+ else:
1465
+ return duplicates
1466
+
1467
+
1468
+ def _join_by_dispatcher(
1469
+ key, r1, r2, jointype=None, r1postfix=None, r2postfix=None,
1470
+ defaults=None, usemask=None, asrecarray=None):
1471
+ return (r1, r2)
1472
+
1473
+
1474
+ @array_function_dispatch(_join_by_dispatcher)
1475
+ def join_by(key, r1, r2, jointype='inner', r1postfix='1', r2postfix='2',
1476
+ defaults=None, usemask=True, asrecarray=False):
1477
+ """
1478
+ Join arrays `r1` and `r2` on key `key`.
1479
+
1480
+ The key should be either a string or a sequence of string corresponding
1481
+ to the fields used to join the array. An exception is raised if the
1482
+ `key` field cannot be found in the two input arrays. Neither `r1` nor
1483
+ `r2` should have any duplicates along `key`: the presence of duplicates
1484
+ will make the output quite unreliable. Note that duplicates are not
1485
+ looked for by the algorithm.
1486
+
1487
+ Parameters
1488
+ ----------
1489
+ key : {string, sequence}
1490
+ A string or a sequence of strings corresponding to the fields used
1491
+ for comparison.
1492
+ r1, r2 : arrays
1493
+ Structured arrays.
1494
+ jointype : {'inner', 'outer', 'leftouter'}, optional
1495
+ If 'inner', returns the elements common to both r1 and r2.
1496
+ If 'outer', returns the common elements as well as the elements of
1497
+ r1 not in r2 and the elements of not in r2.
1498
+ If 'leftouter', returns the common elements and the elements of r1
1499
+ not in r2.
1500
+ r1postfix : string, optional
1501
+ String appended to the names of the fields of r1 that are present
1502
+ in r2 but absent of the key.
1503
+ r2postfix : string, optional
1504
+ String appended to the names of the fields of r2 that are present
1505
+ in r1 but absent of the key.
1506
+ defaults : {dictionary}, optional
1507
+ Dictionary mapping field names to the corresponding default values.
1508
+ usemask : {True, False}, optional
1509
+ Whether to return a MaskedArray (or MaskedRecords is
1510
+ `asrecarray==True`) or a ndarray.
1511
+ asrecarray : {False, True}, optional
1512
+ Whether to return a recarray (or MaskedRecords if `usemask==True`)
1513
+ or just a flexible-type ndarray.
1514
+
1515
+ Notes
1516
+ -----
1517
+ * The output is sorted along the key.
1518
+ * A temporary array is formed by dropping the fields not in the key for
1519
+ the two arrays and concatenating the result. This array is then
1520
+ sorted, and the common entries selected. The output is constructed by
1521
+ filling the fields with the selected entries. Matching is not
1522
+ preserved if there are some duplicates...
1523
+
1524
+ """
1525
+ # Check jointype
1526
+ if jointype not in ('inner', 'outer', 'leftouter'):
1527
+ raise ValueError(
1528
+ "The 'jointype' argument should be in 'inner', "
1529
+ "'outer' or 'leftouter' (got '%s' instead)" % jointype
1530
+ )
1531
+ # If we have a single key, put it in a tuple
1532
+ if isinstance(key, str):
1533
+ key = (key,)
1534
+
1535
+ # Check the keys
1536
+ if len(set(key)) != len(key):
1537
+ dup = next(x for n,x in enumerate(key) if x in key[n+1:])
1538
+ raise ValueError("duplicate join key %r" % dup)
1539
+ for name in key:
1540
+ if name not in r1.dtype.names:
1541
+ raise ValueError('r1 does not have key field %r' % name)
1542
+ if name not in r2.dtype.names:
1543
+ raise ValueError('r2 does not have key field %r' % name)
1544
+
1545
+ # Make sure we work with ravelled arrays
1546
+ r1 = r1.ravel()
1547
+ r2 = r2.ravel()
1548
+ # Fixme: nb2 below is never used. Commenting out for pyflakes.
1549
+ # (nb1, nb2) = (len(r1), len(r2))
1550
+ nb1 = len(r1)
1551
+ (r1names, r2names) = (r1.dtype.names, r2.dtype.names)
1552
+
1553
+ # Check the names for collision
1554
+ collisions = (set(r1names) & set(r2names)) - set(key)
1555
+ if collisions and not (r1postfix or r2postfix):
1556
+ msg = "r1 and r2 contain common names, r1postfix and r2postfix "
1557
+ msg += "can't both be empty"
1558
+ raise ValueError(msg)
1559
+
1560
+ # Make temporary arrays of just the keys
1561
+ # (use order of keys in `r1` for back-compatibility)
1562
+ key1 = [ n for n in r1names if n in key ]
1563
+ r1k = _keep_fields(r1, key1)
1564
+ r2k = _keep_fields(r2, key1)
1565
+
1566
+ # Concatenate the two arrays for comparison
1567
+ aux = ma.concatenate((r1k, r2k))
1568
+ idx_sort = aux.argsort(order=key)
1569
+ aux = aux[idx_sort]
1570
+ #
1571
+ # Get the common keys
1572
+ flag_in = ma.concatenate(([False], aux[1:] == aux[:-1]))
1573
+ flag_in[:-1] = flag_in[1:] + flag_in[:-1]
1574
+ idx_in = idx_sort[flag_in]
1575
+ idx_1 = idx_in[(idx_in < nb1)]
1576
+ idx_2 = idx_in[(idx_in >= nb1)] - nb1
1577
+ (r1cmn, r2cmn) = (len(idx_1), len(idx_2))
1578
+ if jointype == 'inner':
1579
+ (r1spc, r2spc) = (0, 0)
1580
+ elif jointype == 'outer':
1581
+ idx_out = idx_sort[~flag_in]
1582
+ idx_1 = np.concatenate((idx_1, idx_out[(idx_out < nb1)]))
1583
+ idx_2 = np.concatenate((idx_2, idx_out[(idx_out >= nb1)] - nb1))
1584
+ (r1spc, r2spc) = (len(idx_1) - r1cmn, len(idx_2) - r2cmn)
1585
+ elif jointype == 'leftouter':
1586
+ idx_out = idx_sort[~flag_in]
1587
+ idx_1 = np.concatenate((idx_1, idx_out[(idx_out < nb1)]))
1588
+ (r1spc, r2spc) = (len(idx_1) - r1cmn, 0)
1589
+ # Select the entries from each input
1590
+ (s1, s2) = (r1[idx_1], r2[idx_2])
1591
+ #
1592
+ # Build the new description of the output array .......
1593
+ # Start with the key fields
1594
+ ndtype = _get_fieldspec(r1k.dtype)
1595
+
1596
+ # Add the fields from r1
1597
+ for fname, fdtype in _get_fieldspec(r1.dtype):
1598
+ if fname not in key:
1599
+ ndtype.append((fname, fdtype))
1600
+
1601
+ # Add the fields from r2
1602
+ for fname, fdtype in _get_fieldspec(r2.dtype):
1603
+ # Have we seen the current name already ?
1604
+ # we need to rebuild this list every time
1605
+ names = list(name for name, dtype in ndtype)
1606
+ try:
1607
+ nameidx = names.index(fname)
1608
+ except ValueError:
1609
+ #... we haven't: just add the description to the current list
1610
+ ndtype.append((fname, fdtype))
1611
+ else:
1612
+ # collision
1613
+ _, cdtype = ndtype[nameidx]
1614
+ if fname in key:
1615
+ # The current field is part of the key: take the largest dtype
1616
+ ndtype[nameidx] = (fname, max(fdtype, cdtype))
1617
+ else:
1618
+ # The current field is not part of the key: add the suffixes,
1619
+ # and place the new field adjacent to the old one
1620
+ ndtype[nameidx:nameidx + 1] = [
1621
+ (fname + r1postfix, cdtype),
1622
+ (fname + r2postfix, fdtype)
1623
+ ]
1624
+ # Rebuild a dtype from the new fields
1625
+ ndtype = np.dtype(ndtype)
1626
+ # Find the largest nb of common fields :
1627
+ # r1cmn and r2cmn should be equal, but...
1628
+ cmn = max(r1cmn, r2cmn)
1629
+ # Construct an empty array
1630
+ output = ma.masked_all((cmn + r1spc + r2spc,), dtype=ndtype)
1631
+ names = output.dtype.names
1632
+ for f in r1names:
1633
+ selected = s1[f]
1634
+ if f not in names or (f in r2names and not r2postfix and f not in key):
1635
+ f += r1postfix
1636
+ current = output[f]
1637
+ current[:r1cmn] = selected[:r1cmn]
1638
+ if jointype in ('outer', 'leftouter'):
1639
+ current[cmn:cmn + r1spc] = selected[r1cmn:]
1640
+ for f in r2names:
1641
+ selected = s2[f]
1642
+ if f not in names or (f in r1names and not r1postfix and f not in key):
1643
+ f += r2postfix
1644
+ current = output[f]
1645
+ current[:r2cmn] = selected[:r2cmn]
1646
+ if (jointype == 'outer') and r2spc:
1647
+ current[-r2spc:] = selected[r2cmn:]
1648
+ # Sort and finalize the output
1649
+ output.sort(order=key)
1650
+ kwargs = dict(usemask=usemask, asrecarray=asrecarray)
1651
+ return _fix_output(_fix_defaults(output, defaults), **kwargs)
1652
+
1653
+
1654
+ def _rec_join_dispatcher(
1655
+ key, r1, r2, jointype=None, r1postfix=None, r2postfix=None,
1656
+ defaults=None):
1657
+ return (r1, r2)
1658
+
1659
+
1660
+ @array_function_dispatch(_rec_join_dispatcher)
1661
+ def rec_join(key, r1, r2, jointype='inner', r1postfix='1', r2postfix='2',
1662
+ defaults=None):
1663
+ """
1664
+ Join arrays `r1` and `r2` on keys.
1665
+ Alternative to join_by, that always returns a np.recarray.
1666
+
1667
+ See Also
1668
+ --------
1669
+ join_by : equivalent function
1670
+ """
1671
+ kwargs = dict(jointype=jointype, r1postfix=r1postfix, r2postfix=r2postfix,
1672
+ defaults=defaults, usemask=False, asrecarray=True)
1673
+ return join_by(key, r1, r2, **kwargs)
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/scimath.py ADDED
@@ -0,0 +1,625 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Wrapper functions to more user-friendly calling of certain math functions
3
+ whose output data-type is different than the input data-type in certain
4
+ domains of the input.
5
+
6
+ For example, for functions like `log` with branch cuts, the versions in this
7
+ module provide the mathematically valid answers in the complex plane::
8
+
9
+ >>> import math
10
+ >>> np.emath.log(-math.exp(1)) == (1+1j*math.pi)
11
+ True
12
+
13
+ Similarly, `sqrt`, other base logarithms, `power` and trig functions are
14
+ correctly handled. See their respective docstrings for specific examples.
15
+
16
+ Functions
17
+ ---------
18
+
19
+ .. autosummary::
20
+ :toctree: generated/
21
+
22
+ sqrt
23
+ log
24
+ log2
25
+ logn
26
+ log10
27
+ power
28
+ arccos
29
+ arcsin
30
+ arctanh
31
+
32
+ """
33
+ import numpy.core.numeric as nx
34
+ import numpy.core.numerictypes as nt
35
+ from numpy.core.numeric import asarray, any
36
+ from numpy.core.overrides import array_function_dispatch
37
+ from numpy.lib.type_check import isreal
38
+
39
+
40
+ __all__ = [
41
+ 'sqrt', 'log', 'log2', 'logn', 'log10', 'power', 'arccos', 'arcsin',
42
+ 'arctanh'
43
+ ]
44
+
45
+
46
+ _ln2 = nx.log(2.0)
47
+
48
+
49
+ def _tocomplex(arr):
50
+ """Convert its input `arr` to a complex array.
51
+
52
+ The input is returned as a complex array of the smallest type that will fit
53
+ the original data: types like single, byte, short, etc. become csingle,
54
+ while others become cdouble.
55
+
56
+ A copy of the input is always made.
57
+
58
+ Parameters
59
+ ----------
60
+ arr : array
61
+
62
+ Returns
63
+ -------
64
+ array
65
+ An array with the same input data as the input but in complex form.
66
+
67
+ Examples
68
+ --------
69
+
70
+ First, consider an input of type short:
71
+
72
+ >>> a = np.array([1,2,3],np.short)
73
+
74
+ >>> ac = np.lib.scimath._tocomplex(a); ac
75
+ array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64)
76
+
77
+ >>> ac.dtype
78
+ dtype('complex64')
79
+
80
+ If the input is of type double, the output is correspondingly of the
81
+ complex double type as well:
82
+
83
+ >>> b = np.array([1,2,3],np.double)
84
+
85
+ >>> bc = np.lib.scimath._tocomplex(b); bc
86
+ array([1.+0.j, 2.+0.j, 3.+0.j])
87
+
88
+ >>> bc.dtype
89
+ dtype('complex128')
90
+
91
+ Note that even if the input was complex to begin with, a copy is still
92
+ made, since the astype() method always copies:
93
+
94
+ >>> c = np.array([1,2,3],np.csingle)
95
+
96
+ >>> cc = np.lib.scimath._tocomplex(c); cc
97
+ array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64)
98
+
99
+ >>> c *= 2; c
100
+ array([2.+0.j, 4.+0.j, 6.+0.j], dtype=complex64)
101
+
102
+ >>> cc
103
+ array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64)
104
+ """
105
+ if issubclass(arr.dtype.type, (nt.single, nt.byte, nt.short, nt.ubyte,
106
+ nt.ushort, nt.csingle)):
107
+ return arr.astype(nt.csingle)
108
+ else:
109
+ return arr.astype(nt.cdouble)
110
+
111
+
112
+ def _fix_real_lt_zero(x):
113
+ """Convert `x` to complex if it has real, negative components.
114
+
115
+ Otherwise, output is just the array version of the input (via asarray).
116
+
117
+ Parameters
118
+ ----------
119
+ x : array_like
120
+
121
+ Returns
122
+ -------
123
+ array
124
+
125
+ Examples
126
+ --------
127
+ >>> np.lib.scimath._fix_real_lt_zero([1,2])
128
+ array([1, 2])
129
+
130
+ >>> np.lib.scimath._fix_real_lt_zero([-1,2])
131
+ array([-1.+0.j, 2.+0.j])
132
+
133
+ """
134
+ x = asarray(x)
135
+ if any(isreal(x) & (x < 0)):
136
+ x = _tocomplex(x)
137
+ return x
138
+
139
+
140
+ def _fix_int_lt_zero(x):
141
+ """Convert `x` to double if it has real, negative components.
142
+
143
+ Otherwise, output is just the array version of the input (via asarray).
144
+
145
+ Parameters
146
+ ----------
147
+ x : array_like
148
+
149
+ Returns
150
+ -------
151
+ array
152
+
153
+ Examples
154
+ --------
155
+ >>> np.lib.scimath._fix_int_lt_zero([1,2])
156
+ array([1, 2])
157
+
158
+ >>> np.lib.scimath._fix_int_lt_zero([-1,2])
159
+ array([-1., 2.])
160
+ """
161
+ x = asarray(x)
162
+ if any(isreal(x) & (x < 0)):
163
+ x = x * 1.0
164
+ return x
165
+
166
+
167
+ def _fix_real_abs_gt_1(x):
168
+ """Convert `x` to complex if it has real components x_i with abs(x_i)>1.
169
+
170
+ Otherwise, output is just the array version of the input (via asarray).
171
+
172
+ Parameters
173
+ ----------
174
+ x : array_like
175
+
176
+ Returns
177
+ -------
178
+ array
179
+
180
+ Examples
181
+ --------
182
+ >>> np.lib.scimath._fix_real_abs_gt_1([0,1])
183
+ array([0, 1])
184
+
185
+ >>> np.lib.scimath._fix_real_abs_gt_1([0,2])
186
+ array([0.+0.j, 2.+0.j])
187
+ """
188
+ x = asarray(x)
189
+ if any(isreal(x) & (abs(x) > 1)):
190
+ x = _tocomplex(x)
191
+ return x
192
+
193
+
194
+ def _unary_dispatcher(x):
195
+ return (x,)
196
+
197
+
198
+ @array_function_dispatch(_unary_dispatcher)
199
+ def sqrt(x):
200
+ """
201
+ Compute the square root of x.
202
+
203
+ For negative input elements, a complex value is returned
204
+ (unlike `numpy.sqrt` which returns NaN).
205
+
206
+ Parameters
207
+ ----------
208
+ x : array_like
209
+ The input value(s).
210
+
211
+ Returns
212
+ -------
213
+ out : ndarray or scalar
214
+ The square root of `x`. If `x` was a scalar, so is `out`,
215
+ otherwise an array is returned.
216
+
217
+ See Also
218
+ --------
219
+ numpy.sqrt
220
+
221
+ Examples
222
+ --------
223
+ For real, non-negative inputs this works just like `numpy.sqrt`:
224
+
225
+ >>> np.emath.sqrt(1)
226
+ 1.0
227
+ >>> np.emath.sqrt([1, 4])
228
+ array([1., 2.])
229
+
230
+ But it automatically handles negative inputs:
231
+
232
+ >>> np.emath.sqrt(-1)
233
+ 1j
234
+ >>> np.emath.sqrt([-1,4])
235
+ array([0.+1.j, 2.+0.j])
236
+
237
+ Different results are expected because:
238
+ floating point 0.0 and -0.0 are distinct.
239
+
240
+ For more control, explicitly use complex() as follows:
241
+
242
+ >>> np.emath.sqrt(complex(-4.0, 0.0))
243
+ 2j
244
+ >>> np.emath.sqrt(complex(-4.0, -0.0))
245
+ -2j
246
+ """
247
+ x = _fix_real_lt_zero(x)
248
+ return nx.sqrt(x)
249
+
250
+
251
+ @array_function_dispatch(_unary_dispatcher)
252
+ def log(x):
253
+ """
254
+ Compute the natural logarithm of `x`.
255
+
256
+ Return the "principal value" (for a description of this, see `numpy.log`)
257
+ of :math:`log_e(x)`. For real `x > 0`, this is a real number (``log(0)``
258
+ returns ``-inf`` and ``log(np.inf)`` returns ``inf``). Otherwise, the
259
+ complex principle value is returned.
260
+
261
+ Parameters
262
+ ----------
263
+ x : array_like
264
+ The value(s) whose log is (are) required.
265
+
266
+ Returns
267
+ -------
268
+ out : ndarray or scalar
269
+ The log of the `x` value(s). If `x` was a scalar, so is `out`,
270
+ otherwise an array is returned.
271
+
272
+ See Also
273
+ --------
274
+ numpy.log
275
+
276
+ Notes
277
+ -----
278
+ For a log() that returns ``NAN`` when real `x < 0`, use `numpy.log`
279
+ (note, however, that otherwise `numpy.log` and this `log` are identical,
280
+ i.e., both return ``-inf`` for `x = 0`, ``inf`` for `x = inf`, and,
281
+ notably, the complex principle value if ``x.imag != 0``).
282
+
283
+ Examples
284
+ --------
285
+ >>> np.emath.log(np.exp(1))
286
+ 1.0
287
+
288
+ Negative arguments are handled "correctly" (recall that
289
+ ``exp(log(x)) == x`` does *not* hold for real ``x < 0``):
290
+
291
+ >>> np.emath.log(-np.exp(1)) == (1 + np.pi * 1j)
292
+ True
293
+
294
+ """
295
+ x = _fix_real_lt_zero(x)
296
+ return nx.log(x)
297
+
298
+
299
+ @array_function_dispatch(_unary_dispatcher)
300
+ def log10(x):
301
+ """
302
+ Compute the logarithm base 10 of `x`.
303
+
304
+ Return the "principal value" (for a description of this, see
305
+ `numpy.log10`) of :math:`log_{10}(x)`. For real `x > 0`, this
306
+ is a real number (``log10(0)`` returns ``-inf`` and ``log10(np.inf)``
307
+ returns ``inf``). Otherwise, the complex principle value is returned.
308
+
309
+ Parameters
310
+ ----------
311
+ x : array_like or scalar
312
+ The value(s) whose log base 10 is (are) required.
313
+
314
+ Returns
315
+ -------
316
+ out : ndarray or scalar
317
+ The log base 10 of the `x` value(s). If `x` was a scalar, so is `out`,
318
+ otherwise an array object is returned.
319
+
320
+ See Also
321
+ --------
322
+ numpy.log10
323
+
324
+ Notes
325
+ -----
326
+ For a log10() that returns ``NAN`` when real `x < 0`, use `numpy.log10`
327
+ (note, however, that otherwise `numpy.log10` and this `log10` are
328
+ identical, i.e., both return ``-inf`` for `x = 0`, ``inf`` for `x = inf`,
329
+ and, notably, the complex principle value if ``x.imag != 0``).
330
+
331
+ Examples
332
+ --------
333
+
334
+ (We set the printing precision so the example can be auto-tested)
335
+
336
+ >>> np.set_printoptions(precision=4)
337
+
338
+ >>> np.emath.log10(10**1)
339
+ 1.0
340
+
341
+ >>> np.emath.log10([-10**1, -10**2, 10**2])
342
+ array([1.+1.3644j, 2.+1.3644j, 2.+0.j ])
343
+
344
+ """
345
+ x = _fix_real_lt_zero(x)
346
+ return nx.log10(x)
347
+
348
+
349
+ def _logn_dispatcher(n, x):
350
+ return (n, x,)
351
+
352
+
353
+ @array_function_dispatch(_logn_dispatcher)
354
+ def logn(n, x):
355
+ """
356
+ Take log base n of x.
357
+
358
+ If `x` contains negative inputs, the answer is computed and returned in the
359
+ complex domain.
360
+
361
+ Parameters
362
+ ----------
363
+ n : array_like
364
+ The integer base(s) in which the log is taken.
365
+ x : array_like
366
+ The value(s) whose log base `n` is (are) required.
367
+
368
+ Returns
369
+ -------
370
+ out : ndarray or scalar
371
+ The log base `n` of the `x` value(s). If `x` was a scalar, so is
372
+ `out`, otherwise an array is returned.
373
+
374
+ Examples
375
+ --------
376
+ >>> np.set_printoptions(precision=4)
377
+
378
+ >>> np.emath.logn(2, [4, 8])
379
+ array([2., 3.])
380
+ >>> np.emath.logn(2, [-4, -8, 8])
381
+ array([2.+4.5324j, 3.+4.5324j, 3.+0.j ])
382
+
383
+ """
384
+ x = _fix_real_lt_zero(x)
385
+ n = _fix_real_lt_zero(n)
386
+ return nx.log(x)/nx.log(n)
387
+
388
+
389
+ @array_function_dispatch(_unary_dispatcher)
390
+ def log2(x):
391
+ """
392
+ Compute the logarithm base 2 of `x`.
393
+
394
+ Return the "principal value" (for a description of this, see
395
+ `numpy.log2`) of :math:`log_2(x)`. For real `x > 0`, this is
396
+ a real number (``log2(0)`` returns ``-inf`` and ``log2(np.inf)`` returns
397
+ ``inf``). Otherwise, the complex principle value is returned.
398
+
399
+ Parameters
400
+ ----------
401
+ x : array_like
402
+ The value(s) whose log base 2 is (are) required.
403
+
404
+ Returns
405
+ -------
406
+ out : ndarray or scalar
407
+ The log base 2 of the `x` value(s). If `x` was a scalar, so is `out`,
408
+ otherwise an array is returned.
409
+
410
+ See Also
411
+ --------
412
+ numpy.log2
413
+
414
+ Notes
415
+ -----
416
+ For a log2() that returns ``NAN`` when real `x < 0`, use `numpy.log2`
417
+ (note, however, that otherwise `numpy.log2` and this `log2` are
418
+ identical, i.e., both return ``-inf`` for `x = 0`, ``inf`` for `x = inf`,
419
+ and, notably, the complex principle value if ``x.imag != 0``).
420
+
421
+ Examples
422
+ --------
423
+ We set the printing precision so the example can be auto-tested:
424
+
425
+ >>> np.set_printoptions(precision=4)
426
+
427
+ >>> np.emath.log2(8)
428
+ 3.0
429
+ >>> np.emath.log2([-4, -8, 8])
430
+ array([2.+4.5324j, 3.+4.5324j, 3.+0.j ])
431
+
432
+ """
433
+ x = _fix_real_lt_zero(x)
434
+ return nx.log2(x)
435
+
436
+
437
+ def _power_dispatcher(x, p):
438
+ return (x, p)
439
+
440
+
441
+ @array_function_dispatch(_power_dispatcher)
442
+ def power(x, p):
443
+ """
444
+ Return x to the power p, (x**p).
445
+
446
+ If `x` contains negative values, the output is converted to the
447
+ complex domain.
448
+
449
+ Parameters
450
+ ----------
451
+ x : array_like
452
+ The input value(s).
453
+ p : array_like of ints
454
+ The power(s) to which `x` is raised. If `x` contains multiple values,
455
+ `p` has to either be a scalar, or contain the same number of values
456
+ as `x`. In the latter case, the result is
457
+ ``x[0]**p[0], x[1]**p[1], ...``.
458
+
459
+ Returns
460
+ -------
461
+ out : ndarray or scalar
462
+ The result of ``x**p``. If `x` and `p` are scalars, so is `out`,
463
+ otherwise an array is returned.
464
+
465
+ See Also
466
+ --------
467
+ numpy.power
468
+
469
+ Examples
470
+ --------
471
+ >>> np.set_printoptions(precision=4)
472
+
473
+ >>> np.emath.power([2, 4], 2)
474
+ array([ 4, 16])
475
+ >>> np.emath.power([2, 4], -2)
476
+ array([0.25 , 0.0625])
477
+ >>> np.emath.power([-2, 4], 2)
478
+ array([ 4.-0.j, 16.+0.j])
479
+
480
+ """
481
+ x = _fix_real_lt_zero(x)
482
+ p = _fix_int_lt_zero(p)
483
+ return nx.power(x, p)
484
+
485
+
486
+ @array_function_dispatch(_unary_dispatcher)
487
+ def arccos(x):
488
+ """
489
+ Compute the inverse cosine of x.
490
+
491
+ Return the "principal value" (for a description of this, see
492
+ `numpy.arccos`) of the inverse cosine of `x`. For real `x` such that
493
+ `abs(x) <= 1`, this is a real number in the closed interval
494
+ :math:`[0, \\pi]`. Otherwise, the complex principle value is returned.
495
+
496
+ Parameters
497
+ ----------
498
+ x : array_like or scalar
499
+ The value(s) whose arccos is (are) required.
500
+
501
+ Returns
502
+ -------
503
+ out : ndarray or scalar
504
+ The inverse cosine(s) of the `x` value(s). If `x` was a scalar, so
505
+ is `out`, otherwise an array object is returned.
506
+
507
+ See Also
508
+ --------
509
+ numpy.arccos
510
+
511
+ Notes
512
+ -----
513
+ For an arccos() that returns ``NAN`` when real `x` is not in the
514
+ interval ``[-1,1]``, use `numpy.arccos`.
515
+
516
+ Examples
517
+ --------
518
+ >>> np.set_printoptions(precision=4)
519
+
520
+ >>> np.emath.arccos(1) # a scalar is returned
521
+ 0.0
522
+
523
+ >>> np.emath.arccos([1,2])
524
+ array([0.-0.j , 0.-1.317j])
525
+
526
+ """
527
+ x = _fix_real_abs_gt_1(x)
528
+ return nx.arccos(x)
529
+
530
+
531
+ @array_function_dispatch(_unary_dispatcher)
532
+ def arcsin(x):
533
+ """
534
+ Compute the inverse sine of x.
535
+
536
+ Return the "principal value" (for a description of this, see
537
+ `numpy.arcsin`) of the inverse sine of `x`. For real `x` such that
538
+ `abs(x) <= 1`, this is a real number in the closed interval
539
+ :math:`[-\\pi/2, \\pi/2]`. Otherwise, the complex principle value is
540
+ returned.
541
+
542
+ Parameters
543
+ ----------
544
+ x : array_like or scalar
545
+ The value(s) whose arcsin is (are) required.
546
+
547
+ Returns
548
+ -------
549
+ out : ndarray or scalar
550
+ The inverse sine(s) of the `x` value(s). If `x` was a scalar, so
551
+ is `out`, otherwise an array object is returned.
552
+
553
+ See Also
554
+ --------
555
+ numpy.arcsin
556
+
557
+ Notes
558
+ -----
559
+ For an arcsin() that returns ``NAN`` when real `x` is not in the
560
+ interval ``[-1,1]``, use `numpy.arcsin`.
561
+
562
+ Examples
563
+ --------
564
+ >>> np.set_printoptions(precision=4)
565
+
566
+ >>> np.emath.arcsin(0)
567
+ 0.0
568
+
569
+ >>> np.emath.arcsin([0,1])
570
+ array([0. , 1.5708])
571
+
572
+ """
573
+ x = _fix_real_abs_gt_1(x)
574
+ return nx.arcsin(x)
575
+
576
+
577
+ @array_function_dispatch(_unary_dispatcher)
578
+ def arctanh(x):
579
+ """
580
+ Compute the inverse hyperbolic tangent of `x`.
581
+
582
+ Return the "principal value" (for a description of this, see
583
+ `numpy.arctanh`) of ``arctanh(x)``. For real `x` such that
584
+ ``abs(x) < 1``, this is a real number. If `abs(x) > 1`, or if `x` is
585
+ complex, the result is complex. Finally, `x = 1` returns``inf`` and
586
+ ``x=-1`` returns ``-inf``.
587
+
588
+ Parameters
589
+ ----------
590
+ x : array_like
591
+ The value(s) whose arctanh is (are) required.
592
+
593
+ Returns
594
+ -------
595
+ out : ndarray or scalar
596
+ The inverse hyperbolic tangent(s) of the `x` value(s). If `x` was
597
+ a scalar so is `out`, otherwise an array is returned.
598
+
599
+
600
+ See Also
601
+ --------
602
+ numpy.arctanh
603
+
604
+ Notes
605
+ -----
606
+ For an arctanh() that returns ``NAN`` when real `x` is not in the
607
+ interval ``(-1,1)``, use `numpy.arctanh` (this latter, however, does
608
+ return +/-inf for ``x = +/-1``).
609
+
610
+ Examples
611
+ --------
612
+ >>> np.set_printoptions(precision=4)
613
+
614
+ >>> from numpy.testing import suppress_warnings
615
+ >>> with suppress_warnings() as sup:
616
+ ... sup.filter(RuntimeWarning)
617
+ ... np.emath.arctanh(np.eye(2))
618
+ array([[inf, 0.],
619
+ [ 0., inf]])
620
+ >>> np.emath.arctanh([1j])
621
+ array([0.+0.7854j])
622
+
623
+ """
624
+ x = _fix_real_abs_gt_1(x)
625
+ return nx.arctanh(x)
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/shape_base.py ADDED
@@ -0,0 +1,1274 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import functools
2
+
3
+ import numpy.core.numeric as _nx
4
+ from numpy.core.numeric import asarray, zeros, array, asanyarray
5
+ from numpy.core.fromnumeric import reshape, transpose
6
+ from numpy.core.multiarray import normalize_axis_index
7
+ from numpy.core import overrides
8
+ from numpy.core import vstack, atleast_3d
9
+ from numpy.core.numeric import normalize_axis_tuple
10
+ from numpy.core.shape_base import _arrays_for_stack_dispatcher
11
+ from numpy.lib.index_tricks import ndindex
12
+ from numpy.matrixlib.defmatrix import matrix # this raises all the right alarm bells
13
+
14
+
15
+ __all__ = [
16
+ 'column_stack', 'row_stack', 'dstack', 'array_split', 'split',
17
+ 'hsplit', 'vsplit', 'dsplit', 'apply_over_axes', 'expand_dims',
18
+ 'apply_along_axis', 'kron', 'tile', 'get_array_wrap', 'take_along_axis',
19
+ 'put_along_axis'
20
+ ]
21
+
22
+
23
+ array_function_dispatch = functools.partial(
24
+ overrides.array_function_dispatch, module='numpy')
25
+
26
+
27
+ def _make_along_axis_idx(arr_shape, indices, axis):
28
+ # compute dimensions to iterate over
29
+ if not _nx.issubdtype(indices.dtype, _nx.integer):
30
+ raise IndexError('`indices` must be an integer array')
31
+ if len(arr_shape) != indices.ndim:
32
+ raise ValueError(
33
+ "`indices` and `arr` must have the same number of dimensions")
34
+ shape_ones = (1,) * indices.ndim
35
+ dest_dims = list(range(axis)) + [None] + list(range(axis+1, indices.ndim))
36
+
37
+ # build a fancy index, consisting of orthogonal aranges, with the
38
+ # requested index inserted at the right location
39
+ fancy_index = []
40
+ for dim, n in zip(dest_dims, arr_shape):
41
+ if dim is None:
42
+ fancy_index.append(indices)
43
+ else:
44
+ ind_shape = shape_ones[:dim] + (-1,) + shape_ones[dim+1:]
45
+ fancy_index.append(_nx.arange(n).reshape(ind_shape))
46
+
47
+ return tuple(fancy_index)
48
+
49
+
50
+ def _take_along_axis_dispatcher(arr, indices, axis):
51
+ return (arr, indices)
52
+
53
+
54
+ @array_function_dispatch(_take_along_axis_dispatcher)
55
+ def take_along_axis(arr, indices, axis):
56
+ """
57
+ Take values from the input array by matching 1d index and data slices.
58
+
59
+ This iterates over matching 1d slices oriented along the specified axis in
60
+ the index and data arrays, and uses the former to look up values in the
61
+ latter. These slices can be different lengths.
62
+
63
+ Functions returning an index along an axis, like `argsort` and
64
+ `argpartition`, produce suitable indices for this function.
65
+
66
+ .. versionadded:: 1.15.0
67
+
68
+ Parameters
69
+ ----------
70
+ arr : ndarray (Ni..., M, Nk...)
71
+ Source array
72
+ indices : ndarray (Ni..., J, Nk...)
73
+ Indices to take along each 1d slice of `arr`. This must match the
74
+ dimension of arr, but dimensions Ni and Nj only need to broadcast
75
+ against `arr`.
76
+ axis : int
77
+ The axis to take 1d slices along. If axis is None, the input array is
78
+ treated as if it had first been flattened to 1d, for consistency with
79
+ `sort` and `argsort`.
80
+
81
+ Returns
82
+ -------
83
+ out: ndarray (Ni..., J, Nk...)
84
+ The indexed result.
85
+
86
+ Notes
87
+ -----
88
+ This is equivalent to (but faster than) the following use of `ndindex` and
89
+ `s_`, which sets each of ``ii`` and ``kk`` to a tuple of indices::
90
+
91
+ Ni, M, Nk = a.shape[:axis], a.shape[axis], a.shape[axis+1:]
92
+ J = indices.shape[axis] # Need not equal M
93
+ out = np.empty(Ni + (J,) + Nk)
94
+
95
+ for ii in ndindex(Ni):
96
+ for kk in ndindex(Nk):
97
+ a_1d = a [ii + s_[:,] + kk]
98
+ indices_1d = indices[ii + s_[:,] + kk]
99
+ out_1d = out [ii + s_[:,] + kk]
100
+ for j in range(J):
101
+ out_1d[j] = a_1d[indices_1d[j]]
102
+
103
+ Equivalently, eliminating the inner loop, the last two lines would be::
104
+
105
+ out_1d[:] = a_1d[indices_1d]
106
+
107
+ See Also
108
+ --------
109
+ take : Take along an axis, using the same indices for every 1d slice
110
+ put_along_axis :
111
+ Put values into the destination array by matching 1d index and data slices
112
+
113
+ Examples
114
+ --------
115
+
116
+ For this sample array
117
+
118
+ >>> a = np.array([[10, 30, 20], [60, 40, 50]])
119
+
120
+ We can sort either by using sort directly, or argsort and this function
121
+
122
+ >>> np.sort(a, axis=1)
123
+ array([[10, 20, 30],
124
+ [40, 50, 60]])
125
+ >>> ai = np.argsort(a, axis=1)
126
+ >>> ai
127
+ array([[0, 2, 1],
128
+ [1, 2, 0]])
129
+ >>> np.take_along_axis(a, ai, axis=1)
130
+ array([[10, 20, 30],
131
+ [40, 50, 60]])
132
+
133
+ The same works for max and min, if you maintain the trivial dimension
134
+ with ``keepdims``:
135
+
136
+ >>> np.max(a, axis=1, keepdims=True)
137
+ array([[30],
138
+ [60]])
139
+ >>> ai = np.argmax(a, axis=1, keepdims=True)
140
+ >>> ai
141
+ array([[1],
142
+ [0]])
143
+ >>> np.take_along_axis(a, ai, axis=1)
144
+ array([[30],
145
+ [60]])
146
+
147
+ If we want to get the max and min at the same time, we can stack the
148
+ indices first
149
+
150
+ >>> ai_min = np.argmin(a, axis=1, keepdims=True)
151
+ >>> ai_max = np.argmax(a, axis=1, keepdims=True)
152
+ >>> ai = np.concatenate([ai_min, ai_max], axis=1)
153
+ >>> ai
154
+ array([[0, 1],
155
+ [1, 0]])
156
+ >>> np.take_along_axis(a, ai, axis=1)
157
+ array([[10, 30],
158
+ [40, 60]])
159
+ """
160
+ # normalize inputs
161
+ if axis is None:
162
+ arr = arr.flat
163
+ arr_shape = (len(arr),) # flatiter has no .shape
164
+ axis = 0
165
+ else:
166
+ axis = normalize_axis_index(axis, arr.ndim)
167
+ arr_shape = arr.shape
168
+
169
+ # use the fancy index
170
+ return arr[_make_along_axis_idx(arr_shape, indices, axis)]
171
+
172
+
173
+ def _put_along_axis_dispatcher(arr, indices, values, axis):
174
+ return (arr, indices, values)
175
+
176
+
177
+ @array_function_dispatch(_put_along_axis_dispatcher)
178
+ def put_along_axis(arr, indices, values, axis):
179
+ """
180
+ Put values into the destination array by matching 1d index and data slices.
181
+
182
+ This iterates over matching 1d slices oriented along the specified axis in
183
+ the index and data arrays, and uses the former to place values into the
184
+ latter. These slices can be different lengths.
185
+
186
+ Functions returning an index along an axis, like `argsort` and
187
+ `argpartition`, produce suitable indices for this function.
188
+
189
+ .. versionadded:: 1.15.0
190
+
191
+ Parameters
192
+ ----------
193
+ arr : ndarray (Ni..., M, Nk...)
194
+ Destination array.
195
+ indices : ndarray (Ni..., J, Nk...)
196
+ Indices to change along each 1d slice of `arr`. This must match the
197
+ dimension of arr, but dimensions in Ni and Nj may be 1 to broadcast
198
+ against `arr`.
199
+ values : array_like (Ni..., J, Nk...)
200
+ values to insert at those indices. Its shape and dimension are
201
+ broadcast to match that of `indices`.
202
+ axis : int
203
+ The axis to take 1d slices along. If axis is None, the destination
204
+ array is treated as if a flattened 1d view had been created of it.
205
+
206
+ Notes
207
+ -----
208
+ This is equivalent to (but faster than) the following use of `ndindex` and
209
+ `s_`, which sets each of ``ii`` and ``kk`` to a tuple of indices::
210
+
211
+ Ni, M, Nk = a.shape[:axis], a.shape[axis], a.shape[axis+1:]
212
+ J = indices.shape[axis] # Need not equal M
213
+
214
+ for ii in ndindex(Ni):
215
+ for kk in ndindex(Nk):
216
+ a_1d = a [ii + s_[:,] + kk]
217
+ indices_1d = indices[ii + s_[:,] + kk]
218
+ values_1d = values [ii + s_[:,] + kk]
219
+ for j in range(J):
220
+ a_1d[indices_1d[j]] = values_1d[j]
221
+
222
+ Equivalently, eliminating the inner loop, the last two lines would be::
223
+
224
+ a_1d[indices_1d] = values_1d
225
+
226
+ See Also
227
+ --------
228
+ take_along_axis :
229
+ Take values from the input array by matching 1d index and data slices
230
+
231
+ Examples
232
+ --------
233
+
234
+ For this sample array
235
+
236
+ >>> a = np.array([[10, 30, 20], [60, 40, 50]])
237
+
238
+ We can replace the maximum values with:
239
+
240
+ >>> ai = np.argmax(a, axis=1, keepdims=True)
241
+ >>> ai
242
+ array([[1],
243
+ [0]])
244
+ >>> np.put_along_axis(a, ai, 99, axis=1)
245
+ >>> a
246
+ array([[10, 99, 20],
247
+ [99, 40, 50]])
248
+
249
+ """
250
+ # normalize inputs
251
+ if axis is None:
252
+ arr = arr.flat
253
+ axis = 0
254
+ arr_shape = (len(arr),) # flatiter has no .shape
255
+ else:
256
+ axis = normalize_axis_index(axis, arr.ndim)
257
+ arr_shape = arr.shape
258
+
259
+ # use the fancy index
260
+ arr[_make_along_axis_idx(arr_shape, indices, axis)] = values
261
+
262
+
263
+ def _apply_along_axis_dispatcher(func1d, axis, arr, *args, **kwargs):
264
+ return (arr,)
265
+
266
+
267
+ @array_function_dispatch(_apply_along_axis_dispatcher)
268
+ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
269
+ """
270
+ Apply a function to 1-D slices along the given axis.
271
+
272
+ Execute `func1d(a, *args, **kwargs)` where `func1d` operates on 1-D arrays
273
+ and `a` is a 1-D slice of `arr` along `axis`.
274
+
275
+ This is equivalent to (but faster than) the following use of `ndindex` and
276
+ `s_`, which sets each of ``ii``, ``jj``, and ``kk`` to a tuple of indices::
277
+
278
+ Ni, Nk = a.shape[:axis], a.shape[axis+1:]
279
+ for ii in ndindex(Ni):
280
+ for kk in ndindex(Nk):
281
+ f = func1d(arr[ii + s_[:,] + kk])
282
+ Nj = f.shape
283
+ for jj in ndindex(Nj):
284
+ out[ii + jj + kk] = f[jj]
285
+
286
+ Equivalently, eliminating the inner loop, this can be expressed as::
287
+
288
+ Ni, Nk = a.shape[:axis], a.shape[axis+1:]
289
+ for ii in ndindex(Ni):
290
+ for kk in ndindex(Nk):
291
+ out[ii + s_[...,] + kk] = func1d(arr[ii + s_[:,] + kk])
292
+
293
+ Parameters
294
+ ----------
295
+ func1d : function (M,) -> (Nj...)
296
+ This function should accept 1-D arrays. It is applied to 1-D
297
+ slices of `arr` along the specified axis.
298
+ axis : integer
299
+ Axis along which `arr` is sliced.
300
+ arr : ndarray (Ni..., M, Nk...)
301
+ Input array.
302
+ args : any
303
+ Additional arguments to `func1d`.
304
+ kwargs : any
305
+ Additional named arguments to `func1d`.
306
+
307
+ .. versionadded:: 1.9.0
308
+
309
+
310
+ Returns
311
+ -------
312
+ out : ndarray (Ni..., Nj..., Nk...)
313
+ The output array. The shape of `out` is identical to the shape of
314
+ `arr`, except along the `axis` dimension. This axis is removed, and
315
+ replaced with new dimensions equal to the shape of the return value
316
+ of `func1d`. So if `func1d` returns a scalar `out` will have one
317
+ fewer dimensions than `arr`.
318
+
319
+ See Also
320
+ --------
321
+ apply_over_axes : Apply a function repeatedly over multiple axes.
322
+
323
+ Examples
324
+ --------
325
+ >>> def my_func(a):
326
+ ... \"\"\"Average first and last element of a 1-D array\"\"\"
327
+ ... return (a[0] + a[-1]) * 0.5
328
+ >>> b = np.array([[1,2,3], [4,5,6], [7,8,9]])
329
+ >>> np.apply_along_axis(my_func, 0, b)
330
+ array([4., 5., 6.])
331
+ >>> np.apply_along_axis(my_func, 1, b)
332
+ array([2., 5., 8.])
333
+
334
+ For a function that returns a 1D array, the number of dimensions in
335
+ `outarr` is the same as `arr`.
336
+
337
+ >>> b = np.array([[8,1,7], [4,3,9], [5,2,6]])
338
+ >>> np.apply_along_axis(sorted, 1, b)
339
+ array([[1, 7, 8],
340
+ [3, 4, 9],
341
+ [2, 5, 6]])
342
+
343
+ For a function that returns a higher dimensional array, those dimensions
344
+ are inserted in place of the `axis` dimension.
345
+
346
+ >>> b = np.array([[1,2,3], [4,5,6], [7,8,9]])
347
+ >>> np.apply_along_axis(np.diag, -1, b)
348
+ array([[[1, 0, 0],
349
+ [0, 2, 0],
350
+ [0, 0, 3]],
351
+ [[4, 0, 0],
352
+ [0, 5, 0],
353
+ [0, 0, 6]],
354
+ [[7, 0, 0],
355
+ [0, 8, 0],
356
+ [0, 0, 9]]])
357
+ """
358
+ # handle negative axes
359
+ arr = asanyarray(arr)
360
+ nd = arr.ndim
361
+ axis = normalize_axis_index(axis, nd)
362
+
363
+ # arr, with the iteration axis at the end
364
+ in_dims = list(range(nd))
365
+ inarr_view = transpose(arr, in_dims[:axis] + in_dims[axis+1:] + [axis])
366
+
367
+ # compute indices for the iteration axes, and append a trailing ellipsis to
368
+ # prevent 0d arrays decaying to scalars, which fixes gh-8642
369
+ inds = ndindex(inarr_view.shape[:-1])
370
+ inds = (ind + (Ellipsis,) for ind in inds)
371
+
372
+ # invoke the function on the first item
373
+ try:
374
+ ind0 = next(inds)
375
+ except StopIteration:
376
+ raise ValueError(
377
+ 'Cannot apply_along_axis when any iteration dimensions are 0'
378
+ ) from None
379
+ res = asanyarray(func1d(inarr_view[ind0], *args, **kwargs))
380
+
381
+ # build a buffer for storing evaluations of func1d.
382
+ # remove the requested axis, and add the new ones on the end.
383
+ # laid out so that each write is contiguous.
384
+ # for a tuple index inds, buff[inds] = func1d(inarr_view[inds])
385
+ buff = zeros(inarr_view.shape[:-1] + res.shape, res.dtype)
386
+
387
+ # permutation of axes such that out = buff.transpose(buff_permute)
388
+ buff_dims = list(range(buff.ndim))
389
+ buff_permute = (
390
+ buff_dims[0 : axis] +
391
+ buff_dims[buff.ndim-res.ndim : buff.ndim] +
392
+ buff_dims[axis : buff.ndim-res.ndim]
393
+ )
394
+
395
+ # matrices have a nasty __array_prepare__ and __array_wrap__
396
+ if not isinstance(res, matrix):
397
+ buff = res.__array_prepare__(buff)
398
+
399
+ # save the first result, then compute and save all remaining results
400
+ buff[ind0] = res
401
+ for ind in inds:
402
+ buff[ind] = asanyarray(func1d(inarr_view[ind], *args, **kwargs))
403
+
404
+ if not isinstance(res, matrix):
405
+ # wrap the array, to preserve subclasses
406
+ buff = res.__array_wrap__(buff)
407
+
408
+ # finally, rotate the inserted axes back to where they belong
409
+ return transpose(buff, buff_permute)
410
+
411
+ else:
412
+ # matrices have to be transposed first, because they collapse dimensions!
413
+ out_arr = transpose(buff, buff_permute)
414
+ return res.__array_wrap__(out_arr)
415
+
416
+
417
+ def _apply_over_axes_dispatcher(func, a, axes):
418
+ return (a,)
419
+
420
+
421
+ @array_function_dispatch(_apply_over_axes_dispatcher)
422
+ def apply_over_axes(func, a, axes):
423
+ """
424
+ Apply a function repeatedly over multiple axes.
425
+
426
+ `func` is called as `res = func(a, axis)`, where `axis` is the first
427
+ element of `axes`. The result `res` of the function call must have
428
+ either the same dimensions as `a` or one less dimension. If `res`
429
+ has one less dimension than `a`, a dimension is inserted before
430
+ `axis`. The call to `func` is then repeated for each axis in `axes`,
431
+ with `res` as the first argument.
432
+
433
+ Parameters
434
+ ----------
435
+ func : function
436
+ This function must take two arguments, `func(a, axis)`.
437
+ a : array_like
438
+ Input array.
439
+ axes : array_like
440
+ Axes over which `func` is applied; the elements must be integers.
441
+
442
+ Returns
443
+ -------
444
+ apply_over_axis : ndarray
445
+ The output array. The number of dimensions is the same as `a`,
446
+ but the shape can be different. This depends on whether `func`
447
+ changes the shape of its output with respect to its input.
448
+
449
+ See Also
450
+ --------
451
+ apply_along_axis :
452
+ Apply a function to 1-D slices of an array along the given axis.
453
+
454
+ Notes
455
+ -----
456
+ This function is equivalent to tuple axis arguments to reorderable ufuncs
457
+ with keepdims=True. Tuple axis arguments to ufuncs have been available since
458
+ version 1.7.0.
459
+
460
+ Examples
461
+ --------
462
+ >>> a = np.arange(24).reshape(2,3,4)
463
+ >>> a
464
+ array([[[ 0, 1, 2, 3],
465
+ [ 4, 5, 6, 7],
466
+ [ 8, 9, 10, 11]],
467
+ [[12, 13, 14, 15],
468
+ [16, 17, 18, 19],
469
+ [20, 21, 22, 23]]])
470
+
471
+ Sum over axes 0 and 2. The result has same number of dimensions
472
+ as the original array:
473
+
474
+ >>> np.apply_over_axes(np.sum, a, [0,2])
475
+ array([[[ 60],
476
+ [ 92],
477
+ [124]]])
478
+
479
+ Tuple axis arguments to ufuncs are equivalent:
480
+
481
+ >>> np.sum(a, axis=(0,2), keepdims=True)
482
+ array([[[ 60],
483
+ [ 92],
484
+ [124]]])
485
+
486
+ """
487
+ val = asarray(a)
488
+ N = a.ndim
489
+ if array(axes).ndim == 0:
490
+ axes = (axes,)
491
+ for axis in axes:
492
+ if axis < 0:
493
+ axis = N + axis
494
+ args = (val, axis)
495
+ res = func(*args)
496
+ if res.ndim == val.ndim:
497
+ val = res
498
+ else:
499
+ res = expand_dims(res, axis)
500
+ if res.ndim == val.ndim:
501
+ val = res
502
+ else:
503
+ raise ValueError("function is not returning "
504
+ "an array of the correct shape")
505
+ return val
506
+
507
+
508
+ def _expand_dims_dispatcher(a, axis):
509
+ return (a,)
510
+
511
+
512
+ @array_function_dispatch(_expand_dims_dispatcher)
513
+ def expand_dims(a, axis):
514
+ """
515
+ Expand the shape of an array.
516
+
517
+ Insert a new axis that will appear at the `axis` position in the expanded
518
+ array shape.
519
+
520
+ Parameters
521
+ ----------
522
+ a : array_like
523
+ Input array.
524
+ axis : int or tuple of ints
525
+ Position in the expanded axes where the new axis (or axes) is placed.
526
+
527
+ .. deprecated:: 1.13.0
528
+ Passing an axis where ``axis > a.ndim`` will be treated as
529
+ ``axis == a.ndim``, and passing ``axis < -a.ndim - 1`` will
530
+ be treated as ``axis == 0``. This behavior is deprecated.
531
+
532
+ .. versionchanged:: 1.18.0
533
+ A tuple of axes is now supported. Out of range axes as
534
+ described above are now forbidden and raise an `AxisError`.
535
+
536
+ Returns
537
+ -------
538
+ result : ndarray
539
+ View of `a` with the number of dimensions increased.
540
+
541
+ See Also
542
+ --------
543
+ squeeze : The inverse operation, removing singleton dimensions
544
+ reshape : Insert, remove, and combine dimensions, and resize existing ones
545
+ doc.indexing, atleast_1d, atleast_2d, atleast_3d
546
+
547
+ Examples
548
+ --------
549
+ >>> x = np.array([1, 2])
550
+ >>> x.shape
551
+ (2,)
552
+
553
+ The following is equivalent to ``x[np.newaxis, :]`` or ``x[np.newaxis]``:
554
+
555
+ >>> y = np.expand_dims(x, axis=0)
556
+ >>> y
557
+ array([[1, 2]])
558
+ >>> y.shape
559
+ (1, 2)
560
+
561
+ The following is equivalent to ``x[:, np.newaxis]``:
562
+
563
+ >>> y = np.expand_dims(x, axis=1)
564
+ >>> y
565
+ array([[1],
566
+ [2]])
567
+ >>> y.shape
568
+ (2, 1)
569
+
570
+ ``axis`` may also be a tuple:
571
+
572
+ >>> y = np.expand_dims(x, axis=(0, 1))
573
+ >>> y
574
+ array([[[1, 2]]])
575
+
576
+ >>> y = np.expand_dims(x, axis=(2, 0))
577
+ >>> y
578
+ array([[[1],
579
+ [2]]])
580
+
581
+ Note that some examples may use ``None`` instead of ``np.newaxis``. These
582
+ are the same objects:
583
+
584
+ >>> np.newaxis is None
585
+ True
586
+
587
+ """
588
+ if isinstance(a, matrix):
589
+ a = asarray(a)
590
+ else:
591
+ a = asanyarray(a)
592
+
593
+ if type(axis) not in (tuple, list):
594
+ axis = (axis,)
595
+
596
+ out_ndim = len(axis) + a.ndim
597
+ axis = normalize_axis_tuple(axis, out_ndim)
598
+
599
+ shape_it = iter(a.shape)
600
+ shape = [1 if ax in axis else next(shape_it) for ax in range(out_ndim)]
601
+
602
+ return a.reshape(shape)
603
+
604
+
605
+ row_stack = vstack
606
+
607
+
608
+ def _column_stack_dispatcher(tup):
609
+ return _arrays_for_stack_dispatcher(tup)
610
+
611
+
612
+ @array_function_dispatch(_column_stack_dispatcher)
613
+ def column_stack(tup):
614
+ """
615
+ Stack 1-D arrays as columns into a 2-D array.
616
+
617
+ Take a sequence of 1-D arrays and stack them as columns
618
+ to make a single 2-D array. 2-D arrays are stacked as-is,
619
+ just like with `hstack`. 1-D arrays are turned into 2-D columns
620
+ first.
621
+
622
+ Parameters
623
+ ----------
624
+ tup : sequence of 1-D or 2-D arrays.
625
+ Arrays to stack. All of them must have the same first dimension.
626
+
627
+ Returns
628
+ -------
629
+ stacked : 2-D array
630
+ The array formed by stacking the given arrays.
631
+
632
+ See Also
633
+ --------
634
+ stack, hstack, vstack, concatenate
635
+
636
+ Examples
637
+ --------
638
+ >>> a = np.array((1,2,3))
639
+ >>> b = np.array((2,3,4))
640
+ >>> np.column_stack((a,b))
641
+ array([[1, 2],
642
+ [2, 3],
643
+ [3, 4]])
644
+
645
+ """
646
+ arrays = []
647
+ for v in tup:
648
+ arr = asanyarray(v)
649
+ if arr.ndim < 2:
650
+ arr = array(arr, copy=False, subok=True, ndmin=2).T
651
+ arrays.append(arr)
652
+ return _nx.concatenate(arrays, 1)
653
+
654
+
655
+ def _dstack_dispatcher(tup):
656
+ return _arrays_for_stack_dispatcher(tup)
657
+
658
+
659
+ @array_function_dispatch(_dstack_dispatcher)
660
+ def dstack(tup):
661
+ """
662
+ Stack arrays in sequence depth wise (along third axis).
663
+
664
+ This is equivalent to concatenation along the third axis after 2-D arrays
665
+ of shape `(M,N)` have been reshaped to `(M,N,1)` and 1-D arrays of shape
666
+ `(N,)` have been reshaped to `(1,N,1)`. Rebuilds arrays divided by
667
+ `dsplit`.
668
+
669
+ This function makes most sense for arrays with up to 3 dimensions. For
670
+ instance, for pixel-data with a height (first axis), width (second axis),
671
+ and r/g/b channels (third axis). The functions `concatenate`, `stack` and
672
+ `block` provide more general stacking and concatenation operations.
673
+
674
+ Parameters
675
+ ----------
676
+ tup : sequence of arrays
677
+ The arrays must have the same shape along all but the third axis.
678
+ 1-D or 2-D arrays must have the same shape.
679
+
680
+ Returns
681
+ -------
682
+ stacked : ndarray
683
+ The array formed by stacking the given arrays, will be at least 3-D.
684
+
685
+ See Also
686
+ --------
687
+ concatenate : Join a sequence of arrays along an existing axis.
688
+ stack : Join a sequence of arrays along a new axis.
689
+ block : Assemble an nd-array from nested lists of blocks.
690
+ vstack : Stack arrays in sequence vertically (row wise).
691
+ hstack : Stack arrays in sequence horizontally (column wise).
692
+ column_stack : Stack 1-D arrays as columns into a 2-D array.
693
+ dsplit : Split array along third axis.
694
+
695
+ Examples
696
+ --------
697
+ >>> a = np.array((1,2,3))
698
+ >>> b = np.array((2,3,4))
699
+ >>> np.dstack((a,b))
700
+ array([[[1, 2],
701
+ [2, 3],
702
+ [3, 4]]])
703
+
704
+ >>> a = np.array([[1],[2],[3]])
705
+ >>> b = np.array([[2],[3],[4]])
706
+ >>> np.dstack((a,b))
707
+ array([[[1, 2]],
708
+ [[2, 3]],
709
+ [[3, 4]]])
710
+
711
+ """
712
+ arrs = atleast_3d(*tup)
713
+ if not isinstance(arrs, list):
714
+ arrs = [arrs]
715
+ return _nx.concatenate(arrs, 2)
716
+
717
+
718
+ def _replace_zero_by_x_arrays(sub_arys):
719
+ for i in range(len(sub_arys)):
720
+ if _nx.ndim(sub_arys[i]) == 0:
721
+ sub_arys[i] = _nx.empty(0, dtype=sub_arys[i].dtype)
722
+ elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]), 0)):
723
+ sub_arys[i] = _nx.empty(0, dtype=sub_arys[i].dtype)
724
+ return sub_arys
725
+
726
+
727
+ def _array_split_dispatcher(ary, indices_or_sections, axis=None):
728
+ return (ary, indices_or_sections)
729
+
730
+
731
+ @array_function_dispatch(_array_split_dispatcher)
732
+ def array_split(ary, indices_or_sections, axis=0):
733
+ """
734
+ Split an array into multiple sub-arrays.
735
+
736
+ Please refer to the ``split`` documentation. The only difference
737
+ between these functions is that ``array_split`` allows
738
+ `indices_or_sections` to be an integer that does *not* equally
739
+ divide the axis. For an array of length l that should be split
740
+ into n sections, it returns l % n sub-arrays of size l//n + 1
741
+ and the rest of size l//n.
742
+
743
+ See Also
744
+ --------
745
+ split : Split array into multiple sub-arrays of equal size.
746
+
747
+ Examples
748
+ --------
749
+ >>> x = np.arange(8.0)
750
+ >>> np.array_split(x, 3)
751
+ [array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7.])]
752
+
753
+ >>> x = np.arange(9)
754
+ >>> np.array_split(x, 4)
755
+ [array([0, 1, 2]), array([3, 4]), array([5, 6]), array([7, 8])]
756
+
757
+ """
758
+ try:
759
+ Ntotal = ary.shape[axis]
760
+ except AttributeError:
761
+ Ntotal = len(ary)
762
+ try:
763
+ # handle array case.
764
+ Nsections = len(indices_or_sections) + 1
765
+ div_points = [0] + list(indices_or_sections) + [Ntotal]
766
+ except TypeError:
767
+ # indices_or_sections is a scalar, not an array.
768
+ Nsections = int(indices_or_sections)
769
+ if Nsections <= 0:
770
+ raise ValueError('number sections must be larger than 0.') from None
771
+ Neach_section, extras = divmod(Ntotal, Nsections)
772
+ section_sizes = ([0] +
773
+ extras * [Neach_section+1] +
774
+ (Nsections-extras) * [Neach_section])
775
+ div_points = _nx.array(section_sizes, dtype=_nx.intp).cumsum()
776
+
777
+ sub_arys = []
778
+ sary = _nx.swapaxes(ary, axis, 0)
779
+ for i in range(Nsections):
780
+ st = div_points[i]
781
+ end = div_points[i + 1]
782
+ sub_arys.append(_nx.swapaxes(sary[st:end], axis, 0))
783
+
784
+ return sub_arys
785
+
786
+
787
+ def _split_dispatcher(ary, indices_or_sections, axis=None):
788
+ return (ary, indices_or_sections)
789
+
790
+
791
+ @array_function_dispatch(_split_dispatcher)
792
+ def split(ary, indices_or_sections, axis=0):
793
+ """
794
+ Split an array into multiple sub-arrays as views into `ary`.
795
+
796
+ Parameters
797
+ ----------
798
+ ary : ndarray
799
+ Array to be divided into sub-arrays.
800
+ indices_or_sections : int or 1-D array
801
+ If `indices_or_sections` is an integer, N, the array will be divided
802
+ into N equal arrays along `axis`. If such a split is not possible,
803
+ an error is raised.
804
+
805
+ If `indices_or_sections` is a 1-D array of sorted integers, the entries
806
+ indicate where along `axis` the array is split. For example,
807
+ ``[2, 3]`` would, for ``axis=0``, result in
808
+
809
+ - ary[:2]
810
+ - ary[2:3]
811
+ - ary[3:]
812
+
813
+ If an index exceeds the dimension of the array along `axis`,
814
+ an empty sub-array is returned correspondingly.
815
+ axis : int, optional
816
+ The axis along which to split, default is 0.
817
+
818
+ Returns
819
+ -------
820
+ sub-arrays : list of ndarrays
821
+ A list of sub-arrays as views into `ary`.
822
+
823
+ Raises
824
+ ------
825
+ ValueError
826
+ If `indices_or_sections` is given as an integer, but
827
+ a split does not result in equal division.
828
+
829
+ See Also
830
+ --------
831
+ array_split : Split an array into multiple sub-arrays of equal or
832
+ near-equal size. Does not raise an exception if
833
+ an equal division cannot be made.
834
+ hsplit : Split array into multiple sub-arrays horizontally (column-wise).
835
+ vsplit : Split array into multiple sub-arrays vertically (row wise).
836
+ dsplit : Split array into multiple sub-arrays along the 3rd axis (depth).
837
+ concatenate : Join a sequence of arrays along an existing axis.
838
+ stack : Join a sequence of arrays along a new axis.
839
+ hstack : Stack arrays in sequence horizontally (column wise).
840
+ vstack : Stack arrays in sequence vertically (row wise).
841
+ dstack : Stack arrays in sequence depth wise (along third dimension).
842
+
843
+ Examples
844
+ --------
845
+ >>> x = np.arange(9.0)
846
+ >>> np.split(x, 3)
847
+ [array([0., 1., 2.]), array([3., 4., 5.]), array([6., 7., 8.])]
848
+
849
+ >>> x = np.arange(8.0)
850
+ >>> np.split(x, [3, 5, 6, 10])
851
+ [array([0., 1., 2.]),
852
+ array([3., 4.]),
853
+ array([5.]),
854
+ array([6., 7.]),
855
+ array([], dtype=float64)]
856
+
857
+ """
858
+ try:
859
+ len(indices_or_sections)
860
+ except TypeError:
861
+ sections = indices_or_sections
862
+ N = ary.shape[axis]
863
+ if N % sections:
864
+ raise ValueError(
865
+ 'array split does not result in an equal division') from None
866
+ return array_split(ary, indices_or_sections, axis)
867
+
868
+
869
+ def _hvdsplit_dispatcher(ary, indices_or_sections):
870
+ return (ary, indices_or_sections)
871
+
872
+
873
+ @array_function_dispatch(_hvdsplit_dispatcher)
874
+ def hsplit(ary, indices_or_sections):
875
+ """
876
+ Split an array into multiple sub-arrays horizontally (column-wise).
877
+
878
+ Please refer to the `split` documentation. `hsplit` is equivalent
879
+ to `split` with ``axis=1``, the array is always split along the second
880
+ axis except for 1-D arrays, where it is split at ``axis=0``.
881
+
882
+ See Also
883
+ --------
884
+ split : Split an array into multiple sub-arrays of equal size.
885
+
886
+ Examples
887
+ --------
888
+ >>> x = np.arange(16.0).reshape(4, 4)
889
+ >>> x
890
+ array([[ 0., 1., 2., 3.],
891
+ [ 4., 5., 6., 7.],
892
+ [ 8., 9., 10., 11.],
893
+ [12., 13., 14., 15.]])
894
+ >>> np.hsplit(x, 2)
895
+ [array([[ 0., 1.],
896
+ [ 4., 5.],
897
+ [ 8., 9.],
898
+ [12., 13.]]),
899
+ array([[ 2., 3.],
900
+ [ 6., 7.],
901
+ [10., 11.],
902
+ [14., 15.]])]
903
+ >>> np.hsplit(x, np.array([3, 6]))
904
+ [array([[ 0., 1., 2.],
905
+ [ 4., 5., 6.],
906
+ [ 8., 9., 10.],
907
+ [12., 13., 14.]]),
908
+ array([[ 3.],
909
+ [ 7.],
910
+ [11.],
911
+ [15.]]),
912
+ array([], shape=(4, 0), dtype=float64)]
913
+
914
+ With a higher dimensional array the split is still along the second axis.
915
+
916
+ >>> x = np.arange(8.0).reshape(2, 2, 2)
917
+ >>> x
918
+ array([[[0., 1.],
919
+ [2., 3.]],
920
+ [[4., 5.],
921
+ [6., 7.]]])
922
+ >>> np.hsplit(x, 2)
923
+ [array([[[0., 1.]],
924
+ [[4., 5.]]]),
925
+ array([[[2., 3.]],
926
+ [[6., 7.]]])]
927
+
928
+ With a 1-D array, the split is along axis 0.
929
+
930
+ >>> x = np.array([0, 1, 2, 3, 4, 5])
931
+ >>> np.hsplit(x, 2)
932
+ [array([0, 1, 2]), array([3, 4, 5])]
933
+
934
+ """
935
+ if _nx.ndim(ary) == 0:
936
+ raise ValueError('hsplit only works on arrays of 1 or more dimensions')
937
+ if ary.ndim > 1:
938
+ return split(ary, indices_or_sections, 1)
939
+ else:
940
+ return split(ary, indices_or_sections, 0)
941
+
942
+
943
+ @array_function_dispatch(_hvdsplit_dispatcher)
944
+ def vsplit(ary, indices_or_sections):
945
+ """
946
+ Split an array into multiple sub-arrays vertically (row-wise).
947
+
948
+ Please refer to the ``split`` documentation. ``vsplit`` is equivalent
949
+ to ``split`` with `axis=0` (default), the array is always split along the
950
+ first axis regardless of the array dimension.
951
+
952
+ See Also
953
+ --------
954
+ split : Split an array into multiple sub-arrays of equal size.
955
+
956
+ Examples
957
+ --------
958
+ >>> x = np.arange(16.0).reshape(4, 4)
959
+ >>> x
960
+ array([[ 0., 1., 2., 3.],
961
+ [ 4., 5., 6., 7.],
962
+ [ 8., 9., 10., 11.],
963
+ [12., 13., 14., 15.]])
964
+ >>> np.vsplit(x, 2)
965
+ [array([[0., 1., 2., 3.],
966
+ [4., 5., 6., 7.]]), array([[ 8., 9., 10., 11.],
967
+ [12., 13., 14., 15.]])]
968
+ >>> np.vsplit(x, np.array([3, 6]))
969
+ [array([[ 0., 1., 2., 3.],
970
+ [ 4., 5., 6., 7.],
971
+ [ 8., 9., 10., 11.]]), array([[12., 13., 14., 15.]]), array([], shape=(0, 4), dtype=float64)]
972
+
973
+ With a higher dimensional array the split is still along the first axis.
974
+
975
+ >>> x = np.arange(8.0).reshape(2, 2, 2)
976
+ >>> x
977
+ array([[[0., 1.],
978
+ [2., 3.]],
979
+ [[4., 5.],
980
+ [6., 7.]]])
981
+ >>> np.vsplit(x, 2)
982
+ [array([[[0., 1.],
983
+ [2., 3.]]]), array([[[4., 5.],
984
+ [6., 7.]]])]
985
+
986
+ """
987
+ if _nx.ndim(ary) < 2:
988
+ raise ValueError('vsplit only works on arrays of 2 or more dimensions')
989
+ return split(ary, indices_or_sections, 0)
990
+
991
+
992
+ @array_function_dispatch(_hvdsplit_dispatcher)
993
+ def dsplit(ary, indices_or_sections):
994
+ """
995
+ Split array into multiple sub-arrays along the 3rd axis (depth).
996
+
997
+ Please refer to the `split` documentation. `dsplit` is equivalent
998
+ to `split` with ``axis=2``, the array is always split along the third
999
+ axis provided the array dimension is greater than or equal to 3.
1000
+
1001
+ See Also
1002
+ --------
1003
+ split : Split an array into multiple sub-arrays of equal size.
1004
+
1005
+ Examples
1006
+ --------
1007
+ >>> x = np.arange(16.0).reshape(2, 2, 4)
1008
+ >>> x
1009
+ array([[[ 0., 1., 2., 3.],
1010
+ [ 4., 5., 6., 7.]],
1011
+ [[ 8., 9., 10., 11.],
1012
+ [12., 13., 14., 15.]]])
1013
+ >>> np.dsplit(x, 2)
1014
+ [array([[[ 0., 1.],
1015
+ [ 4., 5.]],
1016
+ [[ 8., 9.],
1017
+ [12., 13.]]]), array([[[ 2., 3.],
1018
+ [ 6., 7.]],
1019
+ [[10., 11.],
1020
+ [14., 15.]]])]
1021
+ >>> np.dsplit(x, np.array([3, 6]))
1022
+ [array([[[ 0., 1., 2.],
1023
+ [ 4., 5., 6.]],
1024
+ [[ 8., 9., 10.],
1025
+ [12., 13., 14.]]]),
1026
+ array([[[ 3.],
1027
+ [ 7.]],
1028
+ [[11.],
1029
+ [15.]]]),
1030
+ array([], shape=(2, 2, 0), dtype=float64)]
1031
+ """
1032
+ if _nx.ndim(ary) < 3:
1033
+ raise ValueError('dsplit only works on arrays of 3 or more dimensions')
1034
+ return split(ary, indices_or_sections, 2)
1035
+
1036
+
1037
+ def get_array_prepare(*args):
1038
+ """Find the wrapper for the array with the highest priority.
1039
+
1040
+ In case of ties, leftmost wins. If no wrapper is found, return None
1041
+ """
1042
+ wrappers = sorted((getattr(x, '__array_priority__', 0), -i,
1043
+ x.__array_prepare__) for i, x in enumerate(args)
1044
+ if hasattr(x, '__array_prepare__'))
1045
+ if wrappers:
1046
+ return wrappers[-1][-1]
1047
+ return None
1048
+
1049
+
1050
+ def get_array_wrap(*args):
1051
+ """Find the wrapper for the array with the highest priority.
1052
+
1053
+ In case of ties, leftmost wins. If no wrapper is found, return None
1054
+ """
1055
+ wrappers = sorted((getattr(x, '__array_priority__', 0), -i,
1056
+ x.__array_wrap__) for i, x in enumerate(args)
1057
+ if hasattr(x, '__array_wrap__'))
1058
+ if wrappers:
1059
+ return wrappers[-1][-1]
1060
+ return None
1061
+
1062
+
1063
+ def _kron_dispatcher(a, b):
1064
+ return (a, b)
1065
+
1066
+
1067
+ @array_function_dispatch(_kron_dispatcher)
1068
+ def kron(a, b):
1069
+ """
1070
+ Kronecker product of two arrays.
1071
+
1072
+ Computes the Kronecker product, a composite array made of blocks of the
1073
+ second array scaled by the first.
1074
+
1075
+ Parameters
1076
+ ----------
1077
+ a, b : array_like
1078
+
1079
+ Returns
1080
+ -------
1081
+ out : ndarray
1082
+
1083
+ See Also
1084
+ --------
1085
+ outer : The outer product
1086
+
1087
+ Notes
1088
+ -----
1089
+ The function assumes that the number of dimensions of `a` and `b`
1090
+ are the same, if necessary prepending the smallest with ones.
1091
+ If ``a.shape = (r0,r1,..,rN)`` and ``b.shape = (s0,s1,...,sN)``,
1092
+ the Kronecker product has shape ``(r0*s0, r1*s1, ..., rN*SN)``.
1093
+ The elements are products of elements from `a` and `b`, organized
1094
+ explicitly by::
1095
+
1096
+ kron(a,b)[k0,k1,...,kN] = a[i0,i1,...,iN] * b[j0,j1,...,jN]
1097
+
1098
+ where::
1099
+
1100
+ kt = it * st + jt, t = 0,...,N
1101
+
1102
+ In the common 2-D case (N=1), the block structure can be visualized::
1103
+
1104
+ [[ a[0,0]*b, a[0,1]*b, ... , a[0,-1]*b ],
1105
+ [ ... ... ],
1106
+ [ a[-1,0]*b, a[-1,1]*b, ... , a[-1,-1]*b ]]
1107
+
1108
+
1109
+ Examples
1110
+ --------
1111
+ >>> np.kron([1,10,100], [5,6,7])
1112
+ array([ 5, 6, 7, ..., 500, 600, 700])
1113
+ >>> np.kron([5,6,7], [1,10,100])
1114
+ array([ 5, 50, 500, ..., 7, 70, 700])
1115
+
1116
+ >>> np.kron(np.eye(2), np.ones((2,2)))
1117
+ array([[1., 1., 0., 0.],
1118
+ [1., 1., 0., 0.],
1119
+ [0., 0., 1., 1.],
1120
+ [0., 0., 1., 1.]])
1121
+
1122
+ >>> a = np.arange(100).reshape((2,5,2,5))
1123
+ >>> b = np.arange(24).reshape((2,3,4))
1124
+ >>> c = np.kron(a,b)
1125
+ >>> c.shape
1126
+ (2, 10, 6, 20)
1127
+ >>> I = (1,3,0,2)
1128
+ >>> J = (0,2,1)
1129
+ >>> J1 = (0,) + J # extend to ndim=4
1130
+ >>> S1 = (1,) + b.shape
1131
+ >>> K = tuple(np.array(I) * np.array(S1) + np.array(J1))
1132
+ >>> c[K] == a[I]*b[J]
1133
+ True
1134
+
1135
+ """
1136
+ # Working:
1137
+ # 1. Equalise the shapes by prepending smaller array with 1s
1138
+ # 2. Expand shapes of both the arrays by adding new axes at
1139
+ # odd positions for 1st array and even positions for 2nd
1140
+ # 3. Compute the product of the modified array
1141
+ # 4. The inner most array elements now contain the rows of
1142
+ # the Kronecker product
1143
+ # 5. Reshape the result to kron's shape, which is same as
1144
+ # product of shapes of the two arrays.
1145
+ b = asanyarray(b)
1146
+ a = array(a, copy=False, subok=True, ndmin=b.ndim)
1147
+ is_any_mat = isinstance(a, matrix) or isinstance(b, matrix)
1148
+ ndb, nda = b.ndim, a.ndim
1149
+ nd = max(ndb, nda)
1150
+
1151
+ if (nda == 0 or ndb == 0):
1152
+ return _nx.multiply(a, b)
1153
+
1154
+ as_ = a.shape
1155
+ bs = b.shape
1156
+ if not a.flags.contiguous:
1157
+ a = reshape(a, as_)
1158
+ if not b.flags.contiguous:
1159
+ b = reshape(b, bs)
1160
+
1161
+ # Equalise the shapes by prepending smaller one with 1s
1162
+ as_ = (1,)*max(0, ndb-nda) + as_
1163
+ bs = (1,)*max(0, nda-ndb) + bs
1164
+
1165
+ # Insert empty dimensions
1166
+ a_arr = expand_dims(a, axis=tuple(range(ndb-nda)))
1167
+ b_arr = expand_dims(b, axis=tuple(range(nda-ndb)))
1168
+
1169
+ # Compute the product
1170
+ a_arr = expand_dims(a_arr, axis=tuple(range(1, nd*2, 2)))
1171
+ b_arr = expand_dims(b_arr, axis=tuple(range(0, nd*2, 2)))
1172
+ # In case of `mat`, convert result to `array`
1173
+ result = _nx.multiply(a_arr, b_arr, subok=(not is_any_mat))
1174
+
1175
+ # Reshape back
1176
+ result = result.reshape(_nx.multiply(as_, bs))
1177
+
1178
+ return result if not is_any_mat else matrix(result, copy=False)
1179
+
1180
+
1181
+ def _tile_dispatcher(A, reps):
1182
+ return (A, reps)
1183
+
1184
+
1185
+ @array_function_dispatch(_tile_dispatcher)
1186
+ def tile(A, reps):
1187
+ """
1188
+ Construct an array by repeating A the number of times given by reps.
1189
+
1190
+ If `reps` has length ``d``, the result will have dimension of
1191
+ ``max(d, A.ndim)``.
1192
+
1193
+ If ``A.ndim < d``, `A` is promoted to be d-dimensional by prepending new
1194
+ axes. So a shape (3,) array is promoted to (1, 3) for 2-D replication,
1195
+ or shape (1, 1, 3) for 3-D replication. If this is not the desired
1196
+ behavior, promote `A` to d-dimensions manually before calling this
1197
+ function.
1198
+
1199
+ If ``A.ndim > d``, `reps` is promoted to `A`.ndim by pre-pending 1's to it.
1200
+ Thus for an `A` of shape (2, 3, 4, 5), a `reps` of (2, 2) is treated as
1201
+ (1, 1, 2, 2).
1202
+
1203
+ Note : Although tile may be used for broadcasting, it is strongly
1204
+ recommended to use numpy's broadcasting operations and functions.
1205
+
1206
+ Parameters
1207
+ ----------
1208
+ A : array_like
1209
+ The input array.
1210
+ reps : array_like
1211
+ The number of repetitions of `A` along each axis.
1212
+
1213
+ Returns
1214
+ -------
1215
+ c : ndarray
1216
+ The tiled output array.
1217
+
1218
+ See Also
1219
+ --------
1220
+ repeat : Repeat elements of an array.
1221
+ broadcast_to : Broadcast an array to a new shape
1222
+
1223
+ Examples
1224
+ --------
1225
+ >>> a = np.array([0, 1, 2])
1226
+ >>> np.tile(a, 2)
1227
+ array([0, 1, 2, 0, 1, 2])
1228
+ >>> np.tile(a, (2, 2))
1229
+ array([[0, 1, 2, 0, 1, 2],
1230
+ [0, 1, 2, 0, 1, 2]])
1231
+ >>> np.tile(a, (2, 1, 2))
1232
+ array([[[0, 1, 2, 0, 1, 2]],
1233
+ [[0, 1, 2, 0, 1, 2]]])
1234
+
1235
+ >>> b = np.array([[1, 2], [3, 4]])
1236
+ >>> np.tile(b, 2)
1237
+ array([[1, 2, 1, 2],
1238
+ [3, 4, 3, 4]])
1239
+ >>> np.tile(b, (2, 1))
1240
+ array([[1, 2],
1241
+ [3, 4],
1242
+ [1, 2],
1243
+ [3, 4]])
1244
+
1245
+ >>> c = np.array([1,2,3,4])
1246
+ >>> np.tile(c,(4,1))
1247
+ array([[1, 2, 3, 4],
1248
+ [1, 2, 3, 4],
1249
+ [1, 2, 3, 4],
1250
+ [1, 2, 3, 4]])
1251
+ """
1252
+ try:
1253
+ tup = tuple(reps)
1254
+ except TypeError:
1255
+ tup = (reps,)
1256
+ d = len(tup)
1257
+ if all(x == 1 for x in tup) and isinstance(A, _nx.ndarray):
1258
+ # Fixes the problem that the function does not make a copy if A is a
1259
+ # numpy array and the repetitions are 1 in all dimensions
1260
+ return _nx.array(A, copy=True, subok=True, ndmin=d)
1261
+ else:
1262
+ # Note that no copy of zero-sized arrays is made. However since they
1263
+ # have no data there is no risk of an inadvertent overwrite.
1264
+ c = _nx.array(A, copy=False, subok=True, ndmin=d)
1265
+ if (d < c.ndim):
1266
+ tup = (1,)*(c.ndim-d) + tup
1267
+ shape_out = tuple(s*t for s, t in zip(c.shape, tup))
1268
+ n = c.size
1269
+ if n > 0:
1270
+ for dim_in, nrep in zip(c.shape, tup):
1271
+ if nrep != 1:
1272
+ c = c.reshape(-1, n).repeat(nrep, 0)
1273
+ n //= dim_in
1274
+ return c.reshape(shape_out)
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/stride_tricks.pyi ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from collections.abc import Iterable
2
+ from typing import Any, TypeVar, overload, SupportsIndex
3
+
4
+ from numpy import generic
5
+ from numpy._typing import (
6
+ NDArray,
7
+ ArrayLike,
8
+ _ShapeLike,
9
+ _Shape,
10
+ _ArrayLike
11
+ )
12
+
13
+ _SCT = TypeVar("_SCT", bound=generic)
14
+
15
+ __all__: list[str]
16
+
17
+ class DummyArray:
18
+ __array_interface__: dict[str, Any]
19
+ base: None | NDArray[Any]
20
+ def __init__(
21
+ self,
22
+ interface: dict[str, Any],
23
+ base: None | NDArray[Any] = ...,
24
+ ) -> None: ...
25
+
26
+ @overload
27
+ def as_strided(
28
+ x: _ArrayLike[_SCT],
29
+ shape: None | Iterable[int] = ...,
30
+ strides: None | Iterable[int] = ...,
31
+ subok: bool = ...,
32
+ writeable: bool = ...,
33
+ ) -> NDArray[_SCT]: ...
34
+ @overload
35
+ def as_strided(
36
+ x: ArrayLike,
37
+ shape: None | Iterable[int] = ...,
38
+ strides: None | Iterable[int] = ...,
39
+ subok: bool = ...,
40
+ writeable: bool = ...,
41
+ ) -> NDArray[Any]: ...
42
+
43
+ @overload
44
+ def sliding_window_view(
45
+ x: _ArrayLike[_SCT],
46
+ window_shape: int | Iterable[int],
47
+ axis: None | SupportsIndex = ...,
48
+ *,
49
+ subok: bool = ...,
50
+ writeable: bool = ...,
51
+ ) -> NDArray[_SCT]: ...
52
+ @overload
53
+ def sliding_window_view(
54
+ x: ArrayLike,
55
+ window_shape: int | Iterable[int],
56
+ axis: None | SupportsIndex = ...,
57
+ *,
58
+ subok: bool = ...,
59
+ writeable: bool = ...,
60
+ ) -> NDArray[Any]: ...
61
+
62
+ @overload
63
+ def broadcast_to(
64
+ array: _ArrayLike[_SCT],
65
+ shape: int | Iterable[int],
66
+ subok: bool = ...,
67
+ ) -> NDArray[_SCT]: ...
68
+ @overload
69
+ def broadcast_to(
70
+ array: ArrayLike,
71
+ shape: int | Iterable[int],
72
+ subok: bool = ...,
73
+ ) -> NDArray[Any]: ...
74
+
75
+ def broadcast_shapes(*args: _ShapeLike) -> _Shape: ...
76
+
77
+ def broadcast_arrays(
78
+ *args: ArrayLike,
79
+ subok: bool = ...,
80
+ ) -> list[NDArray[Any]]: ...
LTA_openwebtext_dualt/mini_owt_logdirichlet/.venv_qwen35_uv/lib/python3.12/site-packages/numpy/lib/type_check.py ADDED
@@ -0,0 +1,735 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Automatically adapted for numpy Sep 19, 2005 by convertcode.py
2
+
3
+ """
4
+ import functools
5
+
6
+ __all__ = ['iscomplexobj', 'isrealobj', 'imag', 'iscomplex',
7
+ 'isreal', 'nan_to_num', 'real', 'real_if_close',
8
+ 'typename', 'asfarray', 'mintypecode',
9
+ 'common_type']
10
+
11
+ from .._utils import set_module
12
+ import numpy.core.numeric as _nx
13
+ from numpy.core.numeric import asarray, asanyarray, isnan, zeros
14
+ from numpy.core import overrides, getlimits
15
+ from .ufunclike import isneginf, isposinf
16
+
17
+
18
+ array_function_dispatch = functools.partial(
19
+ overrides.array_function_dispatch, module='numpy')
20
+
21
+
22
+ _typecodes_by_elsize = 'GDFgdfQqLlIiHhBb?'
23
+
24
+
25
+ @set_module('numpy')
26
+ def mintypecode(typechars, typeset='GDFgdf', default='d'):
27
+ """
28
+ Return the character for the minimum-size type to which given types can
29
+ be safely cast.
30
+
31
+ The returned type character must represent the smallest size dtype such
32
+ that an array of the returned type can handle the data from an array of
33
+ all types in `typechars` (or if `typechars` is an array, then its
34
+ dtype.char).
35
+
36
+ Parameters
37
+ ----------
38
+ typechars : list of str or array_like
39
+ If a list of strings, each string should represent a dtype.
40
+ If array_like, the character representation of the array dtype is used.
41
+ typeset : str or list of str, optional
42
+ The set of characters that the returned character is chosen from.
43
+ The default set is 'GDFgdf'.
44
+ default : str, optional
45
+ The default character, this is returned if none of the characters in
46
+ `typechars` matches a character in `typeset`.
47
+
48
+ Returns
49
+ -------
50
+ typechar : str
51
+ The character representing the minimum-size type that was found.
52
+
53
+ See Also
54
+ --------
55
+ dtype, sctype2char, maximum_sctype
56
+
57
+ Examples
58
+ --------
59
+ >>> np.mintypecode(['d', 'f', 'S'])
60
+ 'd'
61
+ >>> x = np.array([1.1, 2-3.j])
62
+ >>> np.mintypecode(x)
63
+ 'D'
64
+
65
+ >>> np.mintypecode('abceh', default='G')
66
+ 'G'
67
+
68
+ """
69
+ typecodes = ((isinstance(t, str) and t) or asarray(t).dtype.char
70
+ for t in typechars)
71
+ intersection = set(t for t in typecodes if t in typeset)
72
+ if not intersection:
73
+ return default
74
+ if 'F' in intersection and 'd' in intersection:
75
+ return 'D'
76
+ return min(intersection, key=_typecodes_by_elsize.index)
77
+
78
+
79
+ def _asfarray_dispatcher(a, dtype=None):
80
+ return (a,)
81
+
82
+
83
+ @array_function_dispatch(_asfarray_dispatcher)
84
+ def asfarray(a, dtype=_nx.float_):
85
+ """
86
+ Return an array converted to a float type.
87
+
88
+ Parameters
89
+ ----------
90
+ a : array_like
91
+ The input array.
92
+ dtype : str or dtype object, optional
93
+ Float type code to coerce input array `a`. If `dtype` is one of the
94
+ 'int' dtypes, it is replaced with float64.
95
+
96
+ Returns
97
+ -------
98
+ out : ndarray
99
+ The input `a` as a float ndarray.
100
+
101
+ Examples
102
+ --------
103
+ >>> np.asfarray([2, 3])
104
+ array([2., 3.])
105
+ >>> np.asfarray([2, 3], dtype='float')
106
+ array([2., 3.])
107
+ >>> np.asfarray([2, 3], dtype='int8')
108
+ array([2., 3.])
109
+
110
+ """
111
+ if not _nx.issubdtype(dtype, _nx.inexact):
112
+ dtype = _nx.float_
113
+ return asarray(a, dtype=dtype)
114
+
115
+
116
+ def _real_dispatcher(val):
117
+ return (val,)
118
+
119
+
120
+ @array_function_dispatch(_real_dispatcher)
121
+ def real(val):
122
+ """
123
+ Return the real part of the complex argument.
124
+
125
+ Parameters
126
+ ----------
127
+ val : array_like
128
+ Input array.
129
+
130
+ Returns
131
+ -------
132
+ out : ndarray or scalar
133
+ The real component of the complex argument. If `val` is real, the type
134
+ of `val` is used for the output. If `val` has complex elements, the
135
+ returned type is float.
136
+
137
+ See Also
138
+ --------
139
+ real_if_close, imag, angle
140
+
141
+ Examples
142
+ --------
143
+ >>> a = np.array([1+2j, 3+4j, 5+6j])
144
+ >>> a.real
145
+ array([1., 3., 5.])
146
+ >>> a.real = 9
147
+ >>> a
148
+ array([9.+2.j, 9.+4.j, 9.+6.j])
149
+ >>> a.real = np.array([9, 8, 7])
150
+ >>> a
151
+ array([9.+2.j, 8.+4.j, 7.+6.j])
152
+ >>> np.real(1 + 1j)
153
+ 1.0
154
+
155
+ """
156
+ try:
157
+ return val.real
158
+ except AttributeError:
159
+ return asanyarray(val).real
160
+
161
+
162
+ def _imag_dispatcher(val):
163
+ return (val,)
164
+
165
+
166
+ @array_function_dispatch(_imag_dispatcher)
167
+ def imag(val):
168
+ """
169
+ Return the imaginary part of the complex argument.
170
+
171
+ Parameters
172
+ ----------
173
+ val : array_like
174
+ Input array.
175
+
176
+ Returns
177
+ -------
178
+ out : ndarray or scalar
179
+ The imaginary component of the complex argument. If `val` is real,
180
+ the type of `val` is used for the output. If `val` has complex
181
+ elements, the returned type is float.
182
+
183
+ See Also
184
+ --------
185
+ real, angle, real_if_close
186
+
187
+ Examples
188
+ --------
189
+ >>> a = np.array([1+2j, 3+4j, 5+6j])
190
+ >>> a.imag
191
+ array([2., 4., 6.])
192
+ >>> a.imag = np.array([8, 10, 12])
193
+ >>> a
194
+ array([1. +8.j, 3.+10.j, 5.+12.j])
195
+ >>> np.imag(1 + 1j)
196
+ 1.0
197
+
198
+ """
199
+ try:
200
+ return val.imag
201
+ except AttributeError:
202
+ return asanyarray(val).imag
203
+
204
+
205
+ def _is_type_dispatcher(x):
206
+ return (x,)
207
+
208
+
209
+ @array_function_dispatch(_is_type_dispatcher)
210
+ def iscomplex(x):
211
+ """
212
+ Returns a bool array, where True if input element is complex.
213
+
214
+ What is tested is whether the input has a non-zero imaginary part, not if
215
+ the input type is complex.
216
+
217
+ Parameters
218
+ ----------
219
+ x : array_like
220
+ Input array.
221
+
222
+ Returns
223
+ -------
224
+ out : ndarray of bools
225
+ Output array.
226
+
227
+ See Also
228
+ --------
229
+ isreal
230
+ iscomplexobj : Return True if x is a complex type or an array of complex
231
+ numbers.
232
+
233
+ Examples
234
+ --------
235
+ >>> np.iscomplex([1+1j, 1+0j, 4.5, 3, 2, 2j])
236
+ array([ True, False, False, False, False, True])
237
+
238
+ """
239
+ ax = asanyarray(x)
240
+ if issubclass(ax.dtype.type, _nx.complexfloating):
241
+ return ax.imag != 0
242
+ res = zeros(ax.shape, bool)
243
+ return res[()] # convert to scalar if needed
244
+
245
+
246
+ @array_function_dispatch(_is_type_dispatcher)
247
+ def isreal(x):
248
+ """
249
+ Returns a bool array, where True if input element is real.
250
+
251
+ If element has complex type with zero complex part, the return value
252
+ for that element is True.
253
+
254
+ Parameters
255
+ ----------
256
+ x : array_like
257
+ Input array.
258
+
259
+ Returns
260
+ -------
261
+ out : ndarray, bool
262
+ Boolean array of same shape as `x`.
263
+
264
+ Notes
265
+ -----
266
+ `isreal` may behave unexpectedly for string or object arrays (see examples)
267
+
268
+ See Also
269
+ --------
270
+ iscomplex
271
+ isrealobj : Return True if x is not a complex type.
272
+
273
+ Examples
274
+ --------
275
+ >>> a = np.array([1+1j, 1+0j, 4.5, 3, 2, 2j], dtype=complex)
276
+ >>> np.isreal(a)
277
+ array([False, True, True, True, True, False])
278
+
279
+ The function does not work on string arrays.
280
+
281
+ >>> a = np.array([2j, "a"], dtype="U")
282
+ >>> np.isreal(a) # Warns about non-elementwise comparison
283
+ False
284
+
285
+ Returns True for all elements in input array of ``dtype=object`` even if
286
+ any of the elements is complex.
287
+
288
+ >>> a = np.array([1, "2", 3+4j], dtype=object)
289
+ >>> np.isreal(a)
290
+ array([ True, True, True])
291
+
292
+ isreal should not be used with object arrays
293
+
294
+ >>> a = np.array([1+2j, 2+1j], dtype=object)
295
+ >>> np.isreal(a)
296
+ array([ True, True])
297
+
298
+ """
299
+ return imag(x) == 0
300
+
301
+
302
+ @array_function_dispatch(_is_type_dispatcher)
303
+ def iscomplexobj(x):
304
+ """
305
+ Check for a complex type or an array of complex numbers.
306
+
307
+ The type of the input is checked, not the value. Even if the input
308
+ has an imaginary part equal to zero, `iscomplexobj` evaluates to True.
309
+
310
+ Parameters
311
+ ----------
312
+ x : any
313
+ The input can be of any type and shape.
314
+
315
+ Returns
316
+ -------
317
+ iscomplexobj : bool
318
+ The return value, True if `x` is of a complex type or has at least
319
+ one complex element.
320
+
321
+ See Also
322
+ --------
323
+ isrealobj, iscomplex
324
+
325
+ Examples
326
+ --------
327
+ >>> np.iscomplexobj(1)
328
+ False
329
+ >>> np.iscomplexobj(1+0j)
330
+ True
331
+ >>> np.iscomplexobj([3, 1+0j, True])
332
+ True
333
+
334
+ """
335
+ try:
336
+ dtype = x.dtype
337
+ type_ = dtype.type
338
+ except AttributeError:
339
+ type_ = asarray(x).dtype.type
340
+ return issubclass(type_, _nx.complexfloating)
341
+
342
+
343
+ @array_function_dispatch(_is_type_dispatcher)
344
+ def isrealobj(x):
345
+ """
346
+ Return True if x is a not complex type or an array of complex numbers.
347
+
348
+ The type of the input is checked, not the value. So even if the input
349
+ has an imaginary part equal to zero, `isrealobj` evaluates to False
350
+ if the data type is complex.
351
+
352
+ Parameters
353
+ ----------
354
+ x : any
355
+ The input can be of any type and shape.
356
+
357
+ Returns
358
+ -------
359
+ y : bool
360
+ The return value, False if `x` is of a complex type.
361
+
362
+ See Also
363
+ --------
364
+ iscomplexobj, isreal
365
+
366
+ Notes
367
+ -----
368
+ The function is only meant for arrays with numerical values but it
369
+ accepts all other objects. Since it assumes array input, the return
370
+ value of other objects may be True.
371
+
372
+ >>> np.isrealobj('A string')
373
+ True
374
+ >>> np.isrealobj(False)
375
+ True
376
+ >>> np.isrealobj(None)
377
+ True
378
+
379
+ Examples
380
+ --------
381
+ >>> np.isrealobj(1)
382
+ True
383
+ >>> np.isrealobj(1+0j)
384
+ False
385
+ >>> np.isrealobj([3, 1+0j, True])
386
+ False
387
+
388
+ """
389
+ return not iscomplexobj(x)
390
+
391
+ #-----------------------------------------------------------------------------
392
+
393
+ def _getmaxmin(t):
394
+ from numpy.core import getlimits
395
+ f = getlimits.finfo(t)
396
+ return f.max, f.min
397
+
398
+
399
+ def _nan_to_num_dispatcher(x, copy=None, nan=None, posinf=None, neginf=None):
400
+ return (x,)
401
+
402
+
403
+ @array_function_dispatch(_nan_to_num_dispatcher)
404
+ def nan_to_num(x, copy=True, nan=0.0, posinf=None, neginf=None):
405
+ """
406
+ Replace NaN with zero and infinity with large finite numbers (default
407
+ behaviour) or with the numbers defined by the user using the `nan`,
408
+ `posinf` and/or `neginf` keywords.
409
+
410
+ If `x` is inexact, NaN is replaced by zero or by the user defined value in
411
+ `nan` keyword, infinity is replaced by the largest finite floating point
412
+ values representable by ``x.dtype`` or by the user defined value in
413
+ `posinf` keyword and -infinity is replaced by the most negative finite
414
+ floating point values representable by ``x.dtype`` or by the user defined
415
+ value in `neginf` keyword.
416
+
417
+ For complex dtypes, the above is applied to each of the real and
418
+ imaginary components of `x` separately.
419
+
420
+ If `x` is not inexact, then no replacements are made.
421
+
422
+ Parameters
423
+ ----------
424
+ x : scalar or array_like
425
+ Input data.
426
+ copy : bool, optional
427
+ Whether to create a copy of `x` (True) or to replace values
428
+ in-place (False). The in-place operation only occurs if
429
+ casting to an array does not require a copy.
430
+ Default is True.
431
+
432
+ .. versionadded:: 1.13
433
+ nan : int, float, optional
434
+ Value to be used to fill NaN values. If no value is passed
435
+ then NaN values will be replaced with 0.0.
436
+
437
+ .. versionadded:: 1.17
438
+ posinf : int, float, optional
439
+ Value to be used to fill positive infinity values. If no value is
440
+ passed then positive infinity values will be replaced with a very
441
+ large number.
442
+
443
+ .. versionadded:: 1.17
444
+ neginf : int, float, optional
445
+ Value to be used to fill negative infinity values. If no value is
446
+ passed then negative infinity values will be replaced with a very
447
+ small (or negative) number.
448
+
449
+ .. versionadded:: 1.17
450
+
451
+
452
+
453
+ Returns
454
+ -------
455
+ out : ndarray
456
+ `x`, with the non-finite values replaced. If `copy` is False, this may
457
+ be `x` itself.
458
+
459
+ See Also
460
+ --------
461
+ isinf : Shows which elements are positive or negative infinity.
462
+ isneginf : Shows which elements are negative infinity.
463
+ isposinf : Shows which elements are positive infinity.
464
+ isnan : Shows which elements are Not a Number (NaN).
465
+ isfinite : Shows which elements are finite (not NaN, not infinity)
466
+
467
+ Notes
468
+ -----
469
+ NumPy uses the IEEE Standard for Binary Floating-Point for Arithmetic
470
+ (IEEE 754). This means that Not a Number is not equivalent to infinity.
471
+
472
+ Examples
473
+ --------
474
+ >>> np.nan_to_num(np.inf)
475
+ 1.7976931348623157e+308
476
+ >>> np.nan_to_num(-np.inf)
477
+ -1.7976931348623157e+308
478
+ >>> np.nan_to_num(np.nan)
479
+ 0.0
480
+ >>> x = np.array([np.inf, -np.inf, np.nan, -128, 128])
481
+ >>> np.nan_to_num(x)
482
+ array([ 1.79769313e+308, -1.79769313e+308, 0.00000000e+000, # may vary
483
+ -1.28000000e+002, 1.28000000e+002])
484
+ >>> np.nan_to_num(x, nan=-9999, posinf=33333333, neginf=33333333)
485
+ array([ 3.3333333e+07, 3.3333333e+07, -9.9990000e+03,
486
+ -1.2800000e+02, 1.2800000e+02])
487
+ >>> y = np.array([complex(np.inf, np.nan), np.nan, complex(np.nan, np.inf)])
488
+ array([ 1.79769313e+308, -1.79769313e+308, 0.00000000e+000, # may vary
489
+ -1.28000000e+002, 1.28000000e+002])
490
+ >>> np.nan_to_num(y)
491
+ array([ 1.79769313e+308 +0.00000000e+000j, # may vary
492
+ 0.00000000e+000 +0.00000000e+000j,
493
+ 0.00000000e+000 +1.79769313e+308j])
494
+ >>> np.nan_to_num(y, nan=111111, posinf=222222)
495
+ array([222222.+111111.j, 111111. +0.j, 111111.+222222.j])
496
+ """
497
+ x = _nx.array(x, subok=True, copy=copy)
498
+ xtype = x.dtype.type
499
+
500
+ isscalar = (x.ndim == 0)
501
+
502
+ if not issubclass(xtype, _nx.inexact):
503
+ return x[()] if isscalar else x
504
+
505
+ iscomplex = issubclass(xtype, _nx.complexfloating)
506
+
507
+ dest = (x.real, x.imag) if iscomplex else (x,)
508
+ maxf, minf = _getmaxmin(x.real.dtype)
509
+ if posinf is not None:
510
+ maxf = posinf
511
+ if neginf is not None:
512
+ minf = neginf
513
+ for d in dest:
514
+ idx_nan = isnan(d)
515
+ idx_posinf = isposinf(d)
516
+ idx_neginf = isneginf(d)
517
+ _nx.copyto(d, nan, where=idx_nan)
518
+ _nx.copyto(d, maxf, where=idx_posinf)
519
+ _nx.copyto(d, minf, where=idx_neginf)
520
+ return x[()] if isscalar else x
521
+
522
+ #-----------------------------------------------------------------------------
523
+
524
+ def _real_if_close_dispatcher(a, tol=None):
525
+ return (a,)
526
+
527
+
528
+ @array_function_dispatch(_real_if_close_dispatcher)
529
+ def real_if_close(a, tol=100):
530
+ """
531
+ If input is complex with all imaginary parts close to zero, return
532
+ real parts.
533
+
534
+ "Close to zero" is defined as `tol` * (machine epsilon of the type for
535
+ `a`).
536
+
537
+ Parameters
538
+ ----------
539
+ a : array_like
540
+ Input array.
541
+ tol : float
542
+ Tolerance in machine epsilons for the complex part of the elements
543
+ in the array. If the tolerance is <=1, then the absolute tolerance
544
+ is used.
545
+
546
+ Returns
547
+ -------
548
+ out : ndarray
549
+ If `a` is real, the type of `a` is used for the output. If `a`
550
+ has complex elements, the returned type is float.
551
+
552
+ See Also
553
+ --------
554
+ real, imag, angle
555
+
556
+ Notes
557
+ -----
558
+ Machine epsilon varies from machine to machine and between data types
559
+ but Python floats on most platforms have a machine epsilon equal to
560
+ 2.2204460492503131e-16. You can use 'np.finfo(float).eps' to print
561
+ out the machine epsilon for floats.
562
+
563
+ Examples
564
+ --------
565
+ >>> np.finfo(float).eps
566
+ 2.2204460492503131e-16 # may vary
567
+
568
+ >>> np.real_if_close([2.1 + 4e-14j, 5.2 + 3e-15j], tol=1000)
569
+ array([2.1, 5.2])
570
+ >>> np.real_if_close([2.1 + 4e-13j, 5.2 + 3e-15j], tol=1000)
571
+ array([2.1+4.e-13j, 5.2 + 3e-15j])
572
+
573
+ """
574
+ a = asanyarray(a)
575
+ type_ = a.dtype.type
576
+ if not issubclass(type_, _nx.complexfloating):
577
+ return a
578
+ if tol > 1:
579
+ f = getlimits.finfo(type_)
580
+ tol = f.eps * tol
581
+ if _nx.all(_nx.absolute(a.imag) < tol):
582
+ a = a.real
583
+ return a
584
+
585
+
586
+ #-----------------------------------------------------------------------------
587
+
588
+ _namefromtype = {'S1': 'character',
589
+ '?': 'bool',
590
+ 'b': 'signed char',
591
+ 'B': 'unsigned char',
592
+ 'h': 'short',
593
+ 'H': 'unsigned short',
594
+ 'i': 'integer',
595
+ 'I': 'unsigned integer',
596
+ 'l': 'long integer',
597
+ 'L': 'unsigned long integer',
598
+ 'q': 'long long integer',
599
+ 'Q': 'unsigned long long integer',
600
+ 'f': 'single precision',
601
+ 'd': 'double precision',
602
+ 'g': 'long precision',
603
+ 'F': 'complex single precision',
604
+ 'D': 'complex double precision',
605
+ 'G': 'complex long double precision',
606
+ 'S': 'string',
607
+ 'U': 'unicode',
608
+ 'V': 'void',
609
+ 'O': 'object'
610
+ }
611
+
612
+ @set_module('numpy')
613
+ def typename(char):
614
+ """
615
+ Return a description for the given data type code.
616
+
617
+ Parameters
618
+ ----------
619
+ char : str
620
+ Data type code.
621
+
622
+ Returns
623
+ -------
624
+ out : str
625
+ Description of the input data type code.
626
+
627
+ See Also
628
+ --------
629
+ dtype, typecodes
630
+
631
+ Examples
632
+ --------
633
+ >>> typechars = ['S1', '?', 'B', 'D', 'G', 'F', 'I', 'H', 'L', 'O', 'Q',
634
+ ... 'S', 'U', 'V', 'b', 'd', 'g', 'f', 'i', 'h', 'l', 'q']
635
+ >>> for typechar in typechars:
636
+ ... print(typechar, ' : ', np.typename(typechar))
637
+ ...
638
+ S1 : character
639
+ ? : bool
640
+ B : unsigned char
641
+ D : complex double precision
642
+ G : complex long double precision
643
+ F : complex single precision
644
+ I : unsigned integer
645
+ H : unsigned short
646
+ L : unsigned long integer
647
+ O : object
648
+ Q : unsigned long long integer
649
+ S : string
650
+ U : unicode
651
+ V : void
652
+ b : signed char
653
+ d : double precision
654
+ g : long precision
655
+ f : single precision
656
+ i : integer
657
+ h : short
658
+ l : long integer
659
+ q : long long integer
660
+
661
+ """
662
+ return _namefromtype[char]
663
+
664
+ #-----------------------------------------------------------------------------
665
+
666
+ #determine the "minimum common type" for a group of arrays.
667
+ array_type = [[_nx.half, _nx.single, _nx.double, _nx.longdouble],
668
+ [None, _nx.csingle, _nx.cdouble, _nx.clongdouble]]
669
+ array_precision = {_nx.half: 0,
670
+ _nx.single: 1,
671
+ _nx.double: 2,
672
+ _nx.longdouble: 3,
673
+ _nx.csingle: 1,
674
+ _nx.cdouble: 2,
675
+ _nx.clongdouble: 3}
676
+
677
+
678
+ def _common_type_dispatcher(*arrays):
679
+ return arrays
680
+
681
+
682
+ @array_function_dispatch(_common_type_dispatcher)
683
+ def common_type(*arrays):
684
+ """
685
+ Return a scalar type which is common to the input arrays.
686
+
687
+ The return type will always be an inexact (i.e. floating point) scalar
688
+ type, even if all the arrays are integer arrays. If one of the inputs is
689
+ an integer array, the minimum precision type that is returned is a
690
+ 64-bit floating point dtype.
691
+
692
+ All input arrays except int64 and uint64 can be safely cast to the
693
+ returned dtype without loss of information.
694
+
695
+ Parameters
696
+ ----------
697
+ array1, array2, ... : ndarrays
698
+ Input arrays.
699
+
700
+ Returns
701
+ -------
702
+ out : data type code
703
+ Data type code.
704
+
705
+ See Also
706
+ --------
707
+ dtype, mintypecode
708
+
709
+ Examples
710
+ --------
711
+ >>> np.common_type(np.arange(2, dtype=np.float32))
712
+ <class 'numpy.float32'>
713
+ >>> np.common_type(np.arange(2, dtype=np.float32), np.arange(2))
714
+ <class 'numpy.float64'>
715
+ >>> np.common_type(np.arange(4), np.array([45, 6.j]), np.array([45.0]))
716
+ <class 'numpy.complex128'>
717
+
718
+ """
719
+ is_complex = False
720
+ precision = 0
721
+ for a in arrays:
722
+ t = a.dtype.type
723
+ if iscomplexobj(a):
724
+ is_complex = True
725
+ if issubclass(t, _nx.integer):
726
+ p = 2 # array_precision[_nx.double]
727
+ else:
728
+ p = array_precision.get(t, None)
729
+ if p is None:
730
+ raise TypeError("can't get common type for non-numeric array")
731
+ precision = max(precision, p)
732
+ if is_complex:
733
+ return array_type[1][precision]
734
+ else:
735
+ return array_type[0][precision]