( fetchURLs: string[], loadOptions?: LoadOptions)
| 36 | * length as `fetchURLs`. |
| 37 | */ |
| 38 | export 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 | |
| 74 | export function streamWeights(fetchURLs: string[], loadOptions: LoadOptions): ReadableStream<ArrayBuffer> { |
| 75 | const fetchFunc = loadOptions.fetchFunc == null ? env().platform.fetch : |
no test coverage detected
searching dependent graphs…