Skip to content
This repository was archived by the owner on Aug 15, 2019. It is now read-only.

Commit c1781ee

Browse files
author
Nikhil Thorat
authored
Undo change where we add an arraybuffer response type to the re… (#1848)
BUG TLDR: we added a request header in core which changes how CORS interacts with GCP. Longer story: This change added a "responseType: arrayBuffer" header so that react native would be happy: https://github.com/tensorflow/tfjs-core/pull/1789/files#diff-5c8893bf31b1cd319675fcf3524961e8 When browsers see custom request headers they make an initial request of type OPTIONS which allows the server to respond saying that they will accept the next GET request. If the OPTIONS request fails, the GET request never happens for the weights. It turns out you have to do some more configuration on GCP to allow OPTIONS requests through. As a quick fix, we just changed our GCP settings for tfjs-models. However, this problem will still show up for anyone hosting their own models (without custom server config stuff). So I'm going to undo the change from the PR above as a permanent solution and we'll send the request header just for react native (which treats these things differently). Fixes tensorflow/tfjs#1755
1 parent ae1dd4a commit c1781ee

File tree

2 files changed

+2
-12
lines changed

2 files changed

+2
-12
lines changed

src/io/weights_loader.ts

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,9 @@ export async function loadWeightsAsArrayBuffer(
4242
const fetchFunc =
4343
loadOptions.fetchFunc == null ? util.fetch : loadOptions.fetchFunc;
4444

45-
// Update the request headers without modifying the passed in
46-
// loadOptions object.
47-
const requestOptions = Object.assign({}, loadOptions.requestInit);
48-
requestOptions.headers = Object.assign({}, requestOptions.headers, {
49-
responseType: 'arraybuffer',
50-
});
51-
5245
// Create the requests for all of the weights in parallel.
5346
const requests =
54-
fetchURLs.map(fetchURL => fetchFunc(fetchURL, requestOptions));
47+
fetchURLs.map(fetchURL => fetchFunc(fetchURL, loadOptions.requestInit));
5548

5649
const fetchStartFraction = 0;
5750
const fetchEndFraction = 0.5;

src/io/weights_loader_test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,7 @@ describeWithFlags('loadWeights', BROWSER_ENVS, () => {
436436
manifest, './', weightsNamesToFetch, {credentials: 'include'});
437437
expect((tf.util.fetch as jasmine.Spy).calls.count()).toBe(1);
438438
expect(tf.util.fetch).toHaveBeenCalledWith('./weightfile0', {
439-
credentials: 'include',
440-
headers: {
441-
responseType: 'arraybuffer',
442-
}
439+
credentials: 'include'
443440
});
444441
});
445442

0 commit comments

Comments
 (0)