Skip to content

Conversation

@pyu10055
Copy link
Collaborator

@pyu10055 pyu10055 commented Apr 18, 2020

This allows platforms like WeChat miniprogram to load the wasm file using
the platform fetch method.

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@pyu10055 pyu10055 requested a review from dsmilkov April 18, 2020 02:17
Copy link
Contributor

@dsmilkov dsmilkov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Smallish comments. LGTM

Reviewed 5 of 5 files at r1.
Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @dsmilkov and @pyu10055)


tfjs-backend-wasm/README.md, line 90 at r1 (raw file):

```ts
import {setWasmPath} from '@tensorflow/tfjs-backend-wasm';
setWasmPath(yourCustomPath, true); // or tf.wasm.setWasmPath when using <script> tags.

for readability extract the true as a separate variable:

const usePlatformFetch = true;
setWasmPath(yourCustomPath, usePlatformFetch);

tfjs-backend-wasm/src/backend_wasm.ts, line 213 at r1 (raw file):

      };
      if (customFetch) {
        factoryConfig.instantiateWasm = createInstantiateWasmFunc(wasmPath);

for reference, add a comment with the above link:
https://github.com/emscripten-core/emscripten/blob/2bca083cbbd5a4133db61fbd74d04f7feecfa907/tests/manual_wasm_instantiate.html#L170


tfjs-backend-wasm/src/backend_wasm.ts, line 280 at r1 (raw file):

 * @param path wasm file path or url
 * @param usePlatformFetch optional boolean to use platform fetch to download
 *     the wasm file

append "Defaults to false." in the jsdoc


tfjs-backend-wasm/src/backend_wasm.ts, line 283 at r1 (raw file):

 */
/** @doc {heading: 'Environment', namespace: 'wasm'} */
export function setWasmPath(path: string, usePlatformFetch?: boolean): void {

use explicit defaults in the function signature: ...usePlatformFetch = false)


tfjs-backend-wasm/src/index_test.ts, line 84 at r1 (raw file):

  it('backend init fails when the path is invalid and use platform fetch',
     async () => {
       setWasmPath('invalid/path', true);

extract as a variable usePlatformFetch


tfjs-backend-wasm/src/index_test.ts, line 95 at r1 (raw file):

     });

  it('backend init succeeds with default path', async () => {

can you add 1 more test, a VALID path with usePlatformFetch=true

@pyu10055 pyu10055 merged commit 8a7ddbc into master Apr 20, 2020
@pyu10055 pyu10055 deleted the platform-fetch-wasm branch April 20, 2020 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants