MCPcopy Index your code
hub / github.com/DustinBrett/daedalOS / fetchNDArrayCacheInternal

Method fetchNDArrayCacheInternal

public/System/tvm/tvmjs.bundle.js:2431–2516  ·  view source on GitHub ↗

* Fetch list of NDArray into the NDArrayCache. * * @param ndarrayCacheUrl The cache url. * @param list The list of array data. * @param device The device to store the data to.

(ndarrayCacheUrl, list, device)

Source from the content-addressed store, hash-verified

2429 * @param device The device to store the data to.
2430 */
2431 fetchNDArrayCacheInternal(ndarrayCacheUrl, list, device) {
2432 return __awaiter(this, void 0, void 0, function* () {
2433 const perf = compact.getPerformance();
2434 let tstart = perf.now();
2435 let totalBytes = 0;
2436 for (let i = 0; i < list.length; ++i) {
2437 totalBytes += list[i].nbytes;
2438 }
2439 let fetchedBytes = 0;
2440 let timeElapsed = 0;
2441 const reportCallback = (iter) => {
2442 // report
2443 for (let j = 0; j < this.initProgressCallback.length; ++j) {
2444 let text = "Loading model [" + iter + "/" + list.length + "]: ";
2445 text += Math.ceil(fetchedBytes / (1024 * 1024)).toString() + " MB, ";
2446 text += Math.floor(fetchedBytes * 100 / totalBytes).toString() + "% complete (";
2447 text += timeElapsed + " secs)";
2448 this.initProgressCallback[j]({
2449 progress: fetchedBytes / totalBytes,
2450 timeElapsed: timeElapsed,
2451 text: text
2452 });
2453 }
2454 };
2455 for (let j = 0; j < this.initProgressCallback.length; ++j) {
2456 this.initProgressCallback[j]({
2457 progress: fetchedBytes / totalBytes,
2458 timeElapsed: 0,
2459 text: "Start to fetch params",
2460 });
2461 }
2462 const cache = yield caches.open("tvmjs");
2463 for (let i = 0; i < list.length; ++i) {
2464 reportCallback(i);
2465 fetchedBytes += list[i].nbytes;
2466 const dataUrl = new URL(list[i].dataPath, ndarrayCacheUrl).href;
2467 const request = new Request(dataUrl);
2468 let buffer;
2469 try {
2470 // use native cache
2471 let result = yield cache.match(request);
2472 if (result === undefined) {
2473 yield cache.add(request);
2474 result = yield cache.match(request);
2475 }
2476 if (result == undefined) {
2477 this.env.logger("Error: Cannot cache " + dataUrl + ", reloading will be slow");
2478 result = yield fetch(request);
2479 }
2480 buffer = yield result.arrayBuffer();
2481 }
2482 catch (err) {
2483 this.env.logger("Error: Cannot fetch " + dataUrl + " err= " + err);
2484 throw err;
2485 }
2486 const shardRecords = list[i].records;
2487 for (let j = 0; j < shardRecords.length; ++j) {
2488 const rec = shardRecords[j];

Callers 1

fetchNDArrayCacheMethod · 0.95

Calls 14

withNewScopeMethod · 0.95
emptyMethod · 0.95
cpuMethod · 0.95
ndarrayCacheUpdateMethod · 0.95
fetchFunction · 0.85
sliceMethod · 0.80
openMethod · 0.45
matchMethod · 0.45
addMethod · 0.45
disposeMethod · 0.45
copyFromMethod · 0.45

Tested by

no test coverage detected