This repository was archived by the owner on Aug 21, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -103,10 +103,25 @@ static DynamicLayer popDynamicLayer() {
103
103
return result;
104
104
}
105
105
106
+ static int64_t pushDynamicLayer (DynamicLayer&& dynamic_layer) {
107
+ auto & dynamicLayerStack = dynamicLayerStackAccessor ();
108
+ int64_t layerId = 1 + dynamicLayerStack.size ();
109
+ TORCH_INTERNAL_ASSERT (layerId == dynamic_layer.layerId ());
110
+ dynamicLayerStack.emplace_back (dynamic_layer);
111
+
112
+ if (layerId == 2 ) {
113
+ c10::impl::tls_set_dispatch_key_included (kDynamicLayerFrontModeKey , true );
114
+ c10::impl::tls_set_dispatch_key_included (kDynamicLayerBackModeKey , true );
115
+ }
116
+
117
+ return layerId;
118
+ }
119
+
106
120
static int64_t pushDynamicLayer (DispatchKey key, optional<int64_t > batch_size = nullopt) {
107
121
auto & dynamicLayerStack = dynamicLayerStackAccessor ();
108
122
TORCH_INTERNAL_ASSERT (key != DispatchKey::Undefined);
109
123
TORCH_INTERNAL_ASSERT (key != DispatchKey::Batched);
124
+
110
125
auto layerId = 1 + dynamicLayerStack.size ();
111
126
dynamicLayerStack.emplace_back (key, layerId, batch_size);
112
127
@@ -356,7 +371,7 @@ struct WithoutTop {
356
371
WithoutTop (): layer_(popDynamicLayer()) {
357
372
}
358
373
~WithoutTop () {
359
- pushDynamicLayer (layer_. key ( ));
374
+ pushDynamicLayer (std::move (layer_ ));
360
375
}
361
376
362
377
bool prev_grad_enabled_;
You can’t perform that action at this time.
0 commit comments