MCPcopy
hub / github.com/tensorflow/tfjs / loadWeightsAsArrayBuffer

Function loadWeightsAsArrayBuffer

tfjs-core/src/io/weights_loader.ts:38–72  ·  view source on GitHub ↗
(
  fetchURLs: string[], loadOptions?: LoadOptions)

Source from the content-addressed store, hash-verified

36 * length as `fetchURLs`.
37 */
38export async function loadWeightsAsArrayBuffer(
39 fetchURLs: string[], loadOptions?: LoadOptions): Promise<ArrayBuffer[]> {
40 if (loadOptions == null) {
41 loadOptions = {};
42 }
43
44 const fetchFunc = loadOptions.fetchFunc == null ? env().platform.fetch :
45 loadOptions.fetchFunc;
46
47 // Create the requests for all of the weights in parallel.
48 const requests = fetchURLs.map(
49 fetchURL =>
50 fetchFunc(fetchURL, loadOptions.requestInit, { isBinary: true }));
51
52 const fetchStartFraction = 0;
53 const fetchEndFraction = 0.5;
54
55 const responses = loadOptions.onProgress == null ?
56 await Promise.all(requests) :
57 await monitorPromisesProgress(
58 requests, loadOptions.onProgress, fetchStartFraction,
59 fetchEndFraction);
60
61 const bufferPromises = responses.map(response => response.arrayBuffer());
62
63 const bufferStartFraction = 0.5;
64 const bufferEndFraction = 1;
65
66 const buffers = loadOptions.onProgress == null ?
67 await Promise.all(bufferPromises) :
68 await monitorPromisesProgress(
69 bufferPromises, loadOptions.onProgress, bufferStartFraction,
70 bufferEndFraction);
71 return buffers;
72}
73
74export function streamWeights(fetchURLs: string[], loadOptions: LoadOptions): ReadableStream<ArrayBuffer> {
75 const fetchFunc = loadOptions.fetchFunc == null ? env().platform.fetch :

Callers 2

loadWeightsMethod · 0.90
fetchWeightsFunction · 0.85

Calls 4

envFunction · 0.90
monitorPromisesProgressFunction · 0.90
fetchFuncFunction · 0.85
allMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…