(module, prefix='', level=0)
| 203 | all_ds_ids = {} |
| 204 | |
| 205 | def load_module_recursive(module, prefix='', level=0): |
| 206 | for name, child in module.named_children(): |
| 207 | if child.__class__ in layer_policies: |
| 208 | checking_key = prefix + name + '.' |
| 209 | if not any(checking_key in item for item in sd[0].keys()): |
| 210 | if hasattr(child, 'weight') and \ |
| 211 | (hasattr(child.weight, 'ds_id') and \ |
| 212 | child.weight.ds_id in all_ds_ids): |
| 213 | prefix1 = all_ds_ids[child.weight.ds_id] |
| 214 | if child.__class__ is nn.Linear: |
| 215 | child = LinearLayer(weight=all_ds_ids[child.weight.ds_id]) |
| 216 | setattr(module, name, child) |
| 217 | continue |
| 218 | child_params = list(child.parameters()) |
| 219 | if len(child_params) > 0 and (child_params[0].numel() == 0 or child_params[0].is_meta): |
| 220 | if child.weight.is_meta: |
| 221 | ds_shape = child.weight.shape |
| 222 | else: |
| 223 | ds_shape = child.weight.ds_shape |
| 224 | if child.__class__ is nn.LayerNorm: |
| 225 | child = Normalize(dim=ds_shape[-1], dtype=child.weight.dtype, eps=child.eps) |
| 226 | setattr(module, name, child) |
| 227 | elif child.__class__ is nn.Linear: |
| 228 | child = LinearLayer(weight_shape=child.weight.shape, bias=child.bias) |
| 229 | setattr(module, name, child) |
| 230 | elif child.__class__ is OPTLearnedPositionalEmbedding: |
| 231 | child = OPTEmbedding(weight_shape=ds_shape) |
| 232 | setattr(module, name, child) |
| 233 | elif child.__class__ is LlamaRMSNorm: |
| 234 | child = RMSNormalize(dim=ds_shape[-1], dtype=child.weight.dtype, eps=child.variance_epsilon) |
| 235 | setattr(module, name, child) |
| 236 | else: |
| 237 | ds_id = None |
| 238 | if hasattr(child.weight, 'ds_id'): |
| 239 | ds_id = child.weight.ds_id |
| 240 | child = EmbeddingLayer(weight_shape=ds_shape, dtype=child.weight.dtype) |
| 241 | if ds_id is not None: |
| 242 | all_ds_ids[ds_id] = child.weight |
| 243 | setattr(module, name, child) |
| 244 | layer_policies[child.__class__](child, prefix + name + '.') |
| 245 | else: |
| 246 | load_module_recursive( |
| 247 | child, |
| 248 | prefix if (level == 0 and ckpt_type == 'pp') and skip_level_0_prefix else \ |
| 249 | prefix + name + '.', |
| 250 | level + 1) |
| 251 | |
| 252 | load_module_recursive(r_module) |
| 253 |
no test coverage detected