(module_def)
| 14254 | return this.LEGACY_convertModule(module_def); |
| 14255 | } |
| 14256 | LEGACY_convertModule(module_def) { |
| 14257 | const atoms = new torch._C.QualifiedName(module_def.name).atoms(); |
| 14258 | const numPushed = atoms.length; |
| 14259 | for (const atom of atoms) { |
| 14260 | const sanitized = /^\d+$/.test(atom) ? `_${atom}` : atom; |
| 14261 | this._LEGACY_moduleStack.push(sanitized); |
| 14262 | } |
| 14263 | const qn = new torch._C.QualifiedName(this._LEGACY_moduleStack); |
| 14264 | const module = new torch.ScriptModule(qn, this._compilation_unit); |
| 14265 | for (const sub_def of module_def.submodules || []) { |
| 14266 | const submodule = this.LEGACY_convertModule(sub_def); |
| 14267 | module.register_module(sub_def.name, submodule); |
| 14268 | } |
| 14269 | for (const param_def of module_def.parameters || []) { |
| 14270 | const tensor = this._constant_table[Number(param_def.tensor_id)]; |
| 14271 | if (param_def.isBuffer) { |
| 14272 | module.register_buffer(param_def.name, tensor); |
| 14273 | } else { |
| 14274 | module.register_parameter(param_def.name, tensor, false); |
| 14275 | } |
| 14276 | } |
| 14277 | // const typeParser = new torch._C.ScriptTypeParser(this._source_importer); |
| 14278 | for (const attr_def of module_def.attributes || []) { |
| 14279 | if (module.hasattr(attr_def.name)) { |
| 14280 | continue; |
| 14281 | } |
| 14282 | throw new python.Error('Not implemented.'); |
| 14283 | // IValue ivalue; |
| 14284 | // if (attr_def.id() >= 0) { |
| 14285 | // ivalue = LEGACY_pickled_ivalues_.at(attr_def.id()); |
| 14286 | // } |
| 14287 | // module.register_attribute(attr_def.name, typeParser.parseType(attr_def.type), ivalue); |
| 14288 | } |
| 14289 | if (module_def.torchscript_arena) { |
| 14290 | const key = module_def.torchscript_arena.key; |
| 14291 | const file = key.substring('code/'.length); |
| 14292 | const name = file.replace(/\.py$/, '').split('/').join('.'); |
| 14293 | const code = execution.import(name); |
| 14294 | if (code.forward.__class__ === execution.builtins.function) { |
| 14295 | module.forward = code.forward; |
| 14296 | } |
| 14297 | } |
| 14298 | // let gen_ranges = null; |
| 14299 | if (module_def.torchscript_debug_arena) { |
| 14300 | throw new python.Error('Not implemented.'); |
| 14301 | //const [data, size] = reader_->getRecord(module_def.torchscript_debug_arena().key()); |
| 14302 | //gen_ranges = std::make_shared<ConcreteSourceRangeUnpickler>(std::move(data), size); |
| 14303 | } |
| 14304 | if (module_def.torchscript_arena) { |
| 14305 | const filename = module_def.torchscript_arena.key; |
| 14306 | const stream = this._reader.get_record(filename); |
| 14307 | const data = stream.peek(); |
| 14308 | const src = new torch._C.Source(data, filename); |
| 14309 | this._source_importer.LEGACY_import_methods(module, src); |
| 14310 | } |
| 14311 | if (module_def.get_state_attribute_id) { |
| 14312 | throw new python.Error('Not implemented.'); |
| 14313 | // LEGACY_moduleSetState(module, LEGACY_pickled_ivalues_.at(module_def.get_state_attribute_id())); |
no test coverage detected