File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change 17
17
import json
18
18
import os
19
19
20
+ import h5py
21
+
22
+ from keras_nlp .backend import config as backend_config
20
23
from keras_nlp .backend import keras
21
24
22
25
try :
@@ -171,6 +174,19 @@ def legacy_load_weights(layer, weights_path):
171
174
functional_cls = cls
172
175
property = functional_cls ._layer_checkpoint_dependencies
173
176
functional_cls ._layer_checkpoint_dependencies = []
177
+
178
+ from keras_nlp .models .backbone import Backbone
179
+
180
+ if not backend_config .keras_3 () and isinstance (layer , Backbone ):
181
+ # Hacky fix for Keras 2 backwards compatibility. Keras 2 traverses loading
182
+ # weights in the reverse order, causing a naming mismatch when loading
183
+ # Kaggle weights saved from Keras 3.
184
+ f = h5py .File (weights_path , "r+" )
185
+ if "_token_embedding" in f .keys ():
186
+ data = f ["_token_embedding" ]
187
+ f ["token_embedding" ] = data
188
+ f .close ()
189
+
174
190
layer .load_weights (weights_path )
175
191
functional_cls ._layer_checkpoint_dependencies = property
176
192
You can’t perform that action at this time.
0 commit comments