(self, state_dict, remove_prefix=None)
| 201 | return self |
| 202 | |
| 203 | def export_trainable_state_dict(self, state_dict, remove_prefix=None): |
| 204 | trainable_param_names = self.trainable_param_names() |
| 205 | state_dict = {name: param for name, param in state_dict.items() if name in trainable_param_names} |
| 206 | if remove_prefix is not None: |
| 207 | state_dict_ = {} |
| 208 | for name, param in state_dict.items(): |
| 209 | if name.startswith(remove_prefix): |
| 210 | name = name[len(remove_prefix):] |
| 211 | state_dict_[name] = param |
| 212 | state_dict = state_dict_ |
| 213 | return state_dict |
| 214 | |
| 215 | def trainable_param_names(self): |
| 216 | trainable_param_names = list(filter(lambda named_param: named_param[1].requires_grad, self.named_parameters())) |
no test coverage detected