torch-ddp 0.2.5 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 01c3dafea6b9ee6b691d59448137a325d54bd794c4004ac6cf519ac6d2961bc3
4
- data.tar.gz: fbb84030108e52d0f54ce67ac43bb07ab1608d3878c8988bfcf91073e9e3f292
3
+ metadata.gz: 9f9b645358a4641e4276ff48adb382c869feb024882d84c4835a39025bda6e62
4
+ data.tar.gz: 8f141183e503f72f0ec1622209e4ca17dcf8611471f68a45e34e0e2c146e4631
5
5
  SHA512:
6
- metadata.gz: f378128687e1c9db4deb53d01b5e10918d76456f586f1d9c35cca9ccdd3ac0f3effebf98724ad52d64c1ee38a4019e2996057791ddcc0cb6232e99a3263dc893
7
- data.tar.gz: 2f028ae611ba90f2f664dbca9b37168f725d5bbe6743c2bd633e40e6d53e9083264e51407bb1365a699b17336a24454995866a492e01e16fb8a96cac0d89ce25
6
+ metadata.gz: fe63d5d9cbc27128b15166363c6a1ae84f342a33c66211e43f6464b9fc58a2a70e497d053561bdf176826307ef089a616fd102db2dd8da135b1ac4e8ee9b781c
7
+ data.tar.gz: 733d6befc6151f55452b3834d2b8c4e174184adda5e8cacc99bc510b65576b26f6e721454d7e88d6309ff2a39290488cc75926f5e137c4ce697ccc0dd53e8827
@@ -54,22 +54,44 @@ struct StoreWrapper {
54
54
 
55
55
  struct ProcessGroupWrapper {
56
56
  ProcessGroupWrapper() = default;
57
- explicit ProcessGroupWrapper(ProcessGroupPtr pg) : pg_(std::move(pg)) {}
57
+ explicit ProcessGroupWrapper(ProcessGroupPtr pg)
58
+ : pg_(std::move(pg)), preserve_on_destroy_(pg_ && pg_->getBackendName() == "nccl") {}
59
+
60
+ ~ProcessGroupWrapper() {
61
+ if (preserve_on_destroy_) {
62
+ pg_.release();
63
+ }
64
+ }
58
65
 
59
66
  ProcessGroupPtr pg_;
67
+ bool preserve_on_destroy_ = false;
60
68
  };
61
69
 
62
70
  ProcessGroupPtr default_process_group;
63
71
  std::once_flag default_pg_cleanup_once;
64
72
 
65
73
  void shutdown_default_process_group() {
66
- if (default_process_group) {
74
+ if (!default_process_group) {
75
+ return;
76
+ }
77
+
78
+ auto process_group = std::move(default_process_group);
79
+ if (process_group->getBackendName() == "nccl") {
67
80
  try {
68
- default_process_group->shutdown();
81
+ process_group->abort();
69
82
  } catch (...) {
70
- // best effort; ensure reset still happens
83
+ // best effort; avoid throwing from Ruby/C++ exit handlers
71
84
  }
72
- default_process_group.reset();
85
+ // LibTorch 2.13 may double-free NCCL resources from the intrusive_ptr
86
+ // destructor after abort; leave this final owning reference leaked.
87
+ process_group.release();
88
+ return;
89
+ }
90
+
91
+ try {
92
+ process_group->shutdown();
93
+ } catch (...) {
94
+ // best effort; the local intrusive_ptr still releases the Gloo group
73
95
  }
74
96
  }
75
97
 
@@ -1,5 +1,5 @@
1
1
  module Torch
2
2
  module DDP
3
- VERSION = "0.2.5"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
data/lib/torch/ddp_ext.so CHANGED
Binary file
@@ -62,12 +62,10 @@ module Torch
62
62
 
63
63
  timeout_ms = (timeout * 1000).to_i
64
64
  bound_device_id = device_id.nil? ? -1 : Integer(device_id)
65
- if backend == "nccl" && bound_device_id >= 0 && Torch.const_defined?(:CUDA) && Torch::CUDA.respond_to?(:set_device)
66
- device_count = Torch::CUDA.device_count if Torch::CUDA.respond_to?(:device_count)
67
- # Only attempt to switch devices when the requested id exists to avoid
68
- # raising on hosts with fewer GPUs than the provided local rank.
69
- Torch::CUDA.set_device(bound_device_id) if device_count.nil? || bound_device_id < device_count
70
- end
65
+ # The native extension selects the NCCL device after creating the process group.
66
+ # Calling a Ruby compatibility cudaSetDevice before construction triggers a
67
+ # LibTorch 2.13/CUDA teardown double free.
68
+
71
69
  pg = _init_process_group(backend, store, rank, world_size, timeout_ms, bound_device_id)
72
70
  warmup_process_group(pg, backend)
73
71
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: torch-ddp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Razuvaev