| 3206 | shared_params_by_full_name = {} |
| 3207 | |
| 3208 | def get_layer_state_dict(module, prefix=""): |
| 3209 | # handle params |
| 3210 | for name, param in module.named_parameters(recurse=False): |
| 3211 | if param is None or not hasattr(param, "ds_id"): |
| 3212 | continue |
| 3213 | key = prefix + name |
| 3214 | # can't rely on param.data_ptr() as it will be reused as weights gets |
| 3215 | # gathered and reduced, but param.ds_id is unique across all zero weights |
| 3216 | # (and shared params will have the same param.ds_id) |
| 3217 | if param.ds_id in shared_ds_ids: |
| 3218 | # shared weights |
| 3219 | #print(f"`{key}` is shared with `{shared_ds_ids[param.ds_id]}`") |
| 3220 | shared_params_by_full_name[key] = shared_ds_ids[param.ds_id] |
| 3221 | else: |
| 3222 | shared_ds_ids[param.ds_id] = key |
| 3223 | |
| 3224 | for name, child in module.named_children(): |
| 3225 | if child is not None: |
| 3226 | get_layer_state_dict(child, prefix + name + ".") |
| 3227 | |
| 3228 | if dist.get_rank() == 0: |
| 3229 | get_layer_state_dict(self.module, prefix="") |