File tree Expand file tree Collapse file tree
deepmd/pt/model/descriptor Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -168,8 +168,10 @@ def share_params(
168168 # must share, even if not do stat
169169 self .mean = base_class .mean
170170 self .stddev = base_class .stddev
171- # self.load_state_dict(base_class.state_dict()) # this does not work, because it only inits the model
172- # the following will successfully link all the params except buffers
171+ # Direct parameters are not part of the child-module registry.
172+ for item in self ._parameters :
173+ self ._parameters [item ] = base_class ._parameters [item ]
174+ # Child modules carry their own parameters and buffers.
173175 for item in self ._modules :
174176 self ._modules [item ] = base_class ._modules [item ]
175177 else :
Original file line number Diff line number Diff line change @@ -368,6 +368,19 @@ def test_degree_gain_zero_recovers_lmax_one(self) -> None:
368368 (gradient ,) = torch .autograd .grad (output .sum (), raw_gain )
369369 self .assertGreater (torch .linalg .vector_norm (gradient ).item (), 0.0 )
370370
371+ def test_level_zero_shares_degree_gain_parameter (self ) -> None :
372+ base = self ._build_descriptor (lmax = 4 )
373+ branch = self ._build_descriptor (lmax = 4 )
374+ base_gain = base .se_atten .adam_degree_gain_raw
375+ branch_gain = branch .se_atten .adam_degree_gain_raw
376+ assert base_gain is not None
377+ assert branch_gain is not None
378+ self .assertIsNot (branch_gain , base_gain )
379+
380+ branch .share_params (base , shared_level = 0 , resume = True )
381+
382+ self .assertIs (branch .se_atten .adam_degree_gain_raw , base_gain )
383+
371384 def test_lmax_two_resolves_quadrupole_collision (self ) -> None :
372385 square = self ._square_directions ()
373386 tetrahedral = self ._tetrahedral_directions ()
You can’t perform that action at this time.
0 commit comments