MCPcopy Index your code
hub / github.com/lutzroeder/netron / deserialize_metadata

Method deserialize_metadata

source/python.js:20461–20514  ·  view source on GitHub ↗
(metadata)

Source from the content-addressed store, hash-verified

20459 this.serialized_name_to_node.set(fx_node.name, fx_node);
20460 }
20461 deserialize_metadata(metadata) {
20462 const ret = new builtins.dict();
20463 const stack_trace = metadata.get('stack_trace');
20464 if (stack_trace) {
20465 ret.set('stack_trace', stack_trace);
20466 }
20467 const deserialize_meta_func = (serialized_target) => {
20468 let module = null;
20469 let serialized_target_names = [];
20470 if (serialized_target.startsWith('torch.nn')) {
20471 module = torch.nn;
20472 serialized_target_names = serialized_target.split('.').slice(1);
20473 } else if (serialized_target.startsWith('torch')) {
20474 module = torch;
20475 serialized_target_names = serialized_target.split('.').slice(1);
20476 } else {
20477 return this.deserialize_operator(serialized_target);
20478 }
20479 let target = module;
20480 for (const name of serialized_target_names) {
20481 if (!builtins.hasattr(target, name)) {
20482 return serialized_target;
20483 }
20484 target = builtins.getattr(target, name);
20485 }
20486 return target;
20487 };
20488 const nn_module_stack_str = metadata.get('nn_module_stack');
20489 if (nn_module_stack_str) {
20490 const import_nn_module_stack = (key, path, ty) => {
20491 return [key, [path, ty]];
20492 };
20493 const nn_module_stack = new Map(nn_module_stack_str.split(';').map((item) => import_nn_module_stack(...item.split(','))));
20494 ret.set('nn_module_stack', nn_module_stack);
20495 }
20496 const source_fn_st_str = metadata.get('source_fn_stack');
20497 if (source_fn_st_str) {
20498 const source_fn_st = [];
20499 for (const source_fn_str of source_fn_st_str.split(';')) {
20500 const [name, target_str] = source_fn_str.split(',');
20501 source_fn_st.push([name, deserialize_meta_func(target_str)]);
20502 }
20503 ret.set('source_fn_stack', source_fn_st);
20504 }
20505 const torch_fn = metadata.get('torch_fn');
20506 if (torch_fn) {
20507 ret.set('torch_fn', new builtins.tuple(torch_fn.split(';')));
20508 }
20509 const custom_str = metadata.get('custom');
20510 if (custom_str) {
20511 ret.set('custom', JSON.parse(custom_str));
20512 }
20513 return ret;
20514 }
20515 deserialize_argument_spec(x) {
20516 if (x.type === 'as_tensor') {
20517 return new torch.export.graph_signature.TensorArgument(x.as_tensor.name);

Callers 2

deserialize_nodeMethod · 0.80

Calls 6

mapMethod · 0.80
splitMethod · 0.80
getMethod · 0.45
setMethod · 0.45
pushMethod · 0.45
parseMethod · 0.45

Tested by

no test coverage detected