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

Method readArchiveAndTensors

source/python.js:14339–14379  ·  view source on GitHub ↗
(archive_name, pickle_prefix, tensor_prefix, type_resolver, obj_loader, device, stream_reader, type_parser, storage_context)

Source from the content-addressed store, hash-verified

14337 return this.readArchiveAndTensors(archive_name, this._pickle_dir_prefix, this._tensor_dir_prefix, type_resolver, ObjLoaderFunc, this._device, this._reader, null, this._storage_context);
14338 }
14339 readArchiveAndTensors(archive_name, pickle_prefix, tensor_prefix, type_resolver, obj_loader, device, stream_reader, type_parser, storage_context) {
14340 const picklename = `${pickle_prefix + archive_name}.pkl`;
14341 const stream = stream_reader.get_record(picklename);
14342 if (!stream) {
14343 throw new python.Error(`File '${picklename}' is not found.`);
14344 }
14345 const buffer = stream.peek();
14346 const tensor_dir_path = tensor_prefix ? tensor_prefix : `${archive_name}/`;
14347 const read_record = (name) => {
14348 const stream = stream_reader.get_record(tensor_dir_path + name);
14349 return stream.length <= 0x40000 ? stream.peek() : stream;
14350 };
14351 const execution = this._compilation_unit.execution;
14352 const pickle = execution.__import__('pickle');
14353 const Unpickler = class extends pickle.Unpickler {
14354 find_class(module, name) {
14355 return super.find_class(module, name);
14356 }
14357 };
14358 const unpickler = new Unpickler(buffer);
14359 unpickler.persistent_load = (saved_id) => {
14360 if (saved_id[0] !== 'storage') {
14361 throw new python.Error(`Unsupported persistent load type '${saved_id[0]}'.`);
14362 }
14363 const [, storage_type, key, , size] = saved_id;
14364 if (storage_context && storage_context.has_storage(key)) {
14365 return storage_context.get_storage(key);
14366 }
14367 const storage = new storage_type(size);
14368 if (!storage._set_cdata) {
14369 throw new python.Error(`'${storage_type.__name__}._set_cdata' is not a function.`);
14370 }
14371 const storage_ptr = read_record(key);
14372 storage._set_cdata(storage_ptr);
14373 if (storage_context) {
14374 storage_context.add_storage(key);
14375 }
14376 return storage;
14377 };
14378 return unpickler.load();
14379 }
14380 });
14381 this.registerType('torch._C.WithInsertPoint', class {
14382 constructor(...args) {

Callers 1

readArchiveMethod · 0.80

Calls 8

get_recordMethod · 0.80
__import__Method · 0.80
has_storageMethod · 0.80
get_storageMethod · 0.80
_set_cdataMethod · 0.80
add_storageMethod · 0.80
peekMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected