@@ -30,7 +30,7 @@ Trackable object_to_save
3030 ) ;
3131 public static class SaveUtil
3232 {
33- public static ( IDictionary < Trackable , IDictionary < string , OneOf < Tensor , IDictionary < string , Tensor > > > > , IDictionary < Tensor , object > , IDictionary < string , IDictionary < string , Trackable > > , TrackableObjectGraph )
33+ public static ( IDictionary < Trackable , IDictionary < string , IDictionary < string , OneOf < Tensor , SaveSpec > > > > , IDictionary < Tensor , object > , IDictionary < string , IDictionary < string , Trackable > > , TrackableObjectGraph )
3434 serialize_graph_view ( ObjectGraphView graph_view , IDictionary < Trackable , Trackable > ? object_map = null , bool call_with_mapped_captures = false , object ? cache = null )
3535 {
3636 var ( trackable_data , node_ids ) = gather_trackable_data ( graph_view , object_map ) ;
@@ -119,16 +119,16 @@ private static TrackableObjectGraph fill_object_graph_proto(IList<TrackableData>
119119 /// <param name="call_with_mapped_captures"></param>
120120 /// <param name="cache"></param>
121121 /// <param name="object_graph_proto"></param>
122- private static IDictionary < Trackable , IDictionary < string , OneOf < Tensor , IDictionary < string , Tensor > > > > get_and_write_tensors_to_serialize ( IList < TrackableData > tensor_trackables , IDictionary < Trackable , int > node_ids ,
122+ private static IDictionary < Trackable , IDictionary < string , IDictionary < string , OneOf < Tensor , SaveSpec > > > > get_and_write_tensors_to_serialize ( IList < TrackableData > tensor_trackables , IDictionary < Trackable , int > node_ids ,
123123 bool call_with_mapped_captures , object ? cache , TrackableObjectGraph object_graph_proto )
124124 {
125- Dictionary < Trackable , IDictionary < string , OneOf < Tensor , IDictionary < string , Tensor > > > > serialized_tensors = new ( ) ;
125+ Dictionary < Trackable , IDictionary < string , IDictionary < string , OneOf < Tensor , SaveSpec > > > > serialized_tensors = new ( ) ;
126126 foreach ( var td in tensor_trackables )
127127 {
128128 // TODO: deal with cache.
129129 var legacy_name = SaveableCompat . get_saveable_name ( td . object_to_save ) ?? "" ;
130130 Trackable trackable = null ;
131- IDictionary < string , OneOf < Tensor , IDictionary < string , Tensor > > > tensor_dict ;
131+ IDictionary < string , IDictionary < string , OneOf < Tensor , SaveSpec > > > tensor_dict ;
132132 if ( ! saveable_object_util . trackable_has_serialize_to_tensor ( td . object_to_save ) || legacy_name . Length > 0 )
133133 {
134134 ( trackable , tensor_dict ) = get_tensors_from_legacy_saveable ( td , node_ids , call_with_mapped_captures , object_graph_proto ) ;
@@ -150,12 +150,12 @@ private static IDictionary<Trackable, IDictionary<string, OneOf<Tensor, IDiction
150150 return serialized_tensors ;
151151 }
152152
153- private static IDictionary < string , OneOf < Tensor , IDictionary < string , Tensor > > > get_tensors_from_trackable ( TrackableData trackable_data , bool call_with_mapped_captures , TrackableObjectGraph object_graph_proto )
153+ private static IDictionary < string , IDictionary < string , OneOf < Tensor , SaveSpec > > > get_tensors_from_trackable ( TrackableData trackable_data , bool call_with_mapped_captures , TrackableObjectGraph object_graph_proto )
154154 {
155155 var trackable = trackable_data . object_to_save ;
156156
157157 // TODO: complete it. Note that actually `call_with_mapped_captures` is of function type.
158- IDictionary < string , OneOf < Tensor , IDictionary < string , Tensor > > > ret_tensor_dict ;
158+ IDictionary < string , IDictionary < string , OneOf < Tensor , SaveSpec > > > ret_tensor_dict ;
159159 if ( call_with_mapped_captures )
160160 {
161161 throw new NotImplementedException ( ) ;
@@ -165,8 +165,7 @@ private static IDictionary<string, OneOf<Tensor, IDictionary<string, Tensor>>> g
165165 ret_tensor_dict = trackable . serialize_to_tensors ( ) ;
166166 }
167167
168- // TODO: deal with the type `SaveSpce` (currently it will never be it).
169- Dictionary < string , OneOf < Tensor , IDictionary < string , Tensor > > > tensor_dict = new ( ) ;
168+ Dictionary < string , IDictionary < string , OneOf < Tensor , SaveSpec > > > tensor_dict = new ( ) ;
170169 foreach ( var pair in ret_tensor_dict )
171170 {
172171 var local_name = TrackableUtils . escape_local_name ( pair . Key ) ;
@@ -175,10 +174,12 @@ private static IDictionary<string, OneOf<Tensor, IDictionary<string, Tensor>>> g
175174
176175 tensor_dict [ checkpoint_key ] = maybe_tensor ;
177176
178- if ( maybe_tensor . IsTypeOrDeriveFrom < SaveSpec > ( ) )
177+ foreach ( var key in maybe_tensor . Keys )
179178 {
180- throw new NotImplementedException ( ) ;
181- //((SaveSpec)maybe_tensor).name = local_name + ((SaveSpec)maybe_tensor).name;
179+ if ( maybe_tensor [ key ] . IsTypeOrDeriveFrom < SaveSpec > ( ) )
180+ {
181+ maybe_tensor [ key ] . AsT1 . name = local_name + maybe_tensor [ key ] . AsT1 . name ;
182+ }
182183 }
183184
184185 if ( object_graph_proto is not null )
@@ -202,7 +203,7 @@ private static IDictionary<string, OneOf<Tensor, IDictionary<string, Tensor>>> g
202203 /// <param name="call_with_mapped_captures"></param>
203204 /// <param name="object_graph_proto"></param>
204205 /// <returns></returns>
205- private static ( Trackable , IDictionary < string , OneOf < Tensor , IDictionary < string , Tensor > > > ) get_tensors_from_legacy_saveable ( TrackableData trackable_data , IDictionary < Trackable , int > node_ids ,
206+ private static ( Trackable , IDictionary < string , IDictionary < string , OneOf < Tensor , SaveSpec > > > ) get_tensors_from_legacy_saveable ( TrackableData trackable_data , IDictionary < Trackable , int > node_ids ,
206207 bool call_with_mapped_captures , TrackableObjectGraph object_graph_proto )
207208 {
208209 Dictionary < Trackable , string > object_names = new ( ) ;
0 commit comments