Closed
Description
System information
- Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js):
- OS Platform and Distribution (e.g., Linux Ubuntu 16.04): WeChat 8.0.3
- Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device: Android and IOS
- TensorFlow.js installed from (npm or script link): npm
- TensorFlow.js version (use command below): 3.6
- Browser version: WeChat 8.0.3
- Tensorflow.js Converter Version: 3.6
WebAssembly has changed to WXWebAssembly after WeChat 8.0
- not simd or thread support.
- only load local wasm file is allowed.
- WebAssembly.validate not working.
my approch to fix this is replace some code in build time, using tfjs-backend-wasm/dist/index.js
as entry
https://github.com/deepkolos/wxmp-tensorflow/blob/main/rollup.config.js#L30
function codeTransform() {
return {
transform(code, file) {
// 修复wasm
if (
file.endsWith('tfjs-backend-wasm-threaded-simd.worker.js') ||
file.endsWith('tfjs-backend-wasm-threaded-simd.js')
) {
code = code.replace(`require("worker_threads")`, 'null');
code = code.replace(`require("perf_hooks")`, 'null');
}
if (file.endsWith('backend_wasm.js')) {
code = code.replace(`env().getAsync('WASM_HAS_SIMD_SUPPORT')`, 'false');
code = code.replace(`env().getAsync('WASM_HAS_MULTITHREAD_SUPPORT')`, 'false');
code = code.replace(
`return (imports, callback) => {`,
`return (imports, callback) => {
WebAssembly.instantiate(path, imports).then(output => {
callback(output.instance, output.module);
});
return {};`,
);
}
code = code.replace(`WebAssembly.`, `WXWebAssembly.`);
code = code.replace(`typeof WebAssembly`, `typeof WXWebAssembly`);
return { code };
},
};
}
but this is a temporary solution, hope it can be fix in better way inside the @tensorflow/tfjs-backend-wasm
package. thanks