Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wasm Backend: info.backend.decComplexRef is not a function #4609

Closed
Moumouls opened this issue Jan 28, 2021 · 5 comments
Closed

Wasm Backend: info.backend.decComplexRef is not a function #4609

Moumouls opened this issue Jan 28, 2021 · 5 comments

Comments

@Moumouls
Copy link

Please make sure that this is a bug. As per our
GitHub Policy,
we only address code/doc bugs, performance issues, feature requests and
build/installation issues on GitHub. tag:bug_template

System information

  • Have I written custom code (as opposed to using a stock example script provided in TensorFlow.js): yes
  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): Macos Bigsur
  • Mobile device (e.g. iPhone 8, Pixel 2, Samsung Galaxy) if the issue happens on mobile device:
  • TensorFlow.js installed from (npm or script link): yarn
  • TensorFlow.js version (use command below): 3.0.0
  • Browser version: None
  • Tensorflow.js Converter Version:

Describe the current behavior

Try to run wasm backend on bidirectional GRU. Wasm won't create the model.

import * as tf from '@tensorflow/tfjs'
import '@tensorflow/tfjs-backend-wasm'
import { getWindowedData, WindowedData } from './utils'

const createModel = (trainData: tf.Tensor3D) => {
	const model = tf.sequential()
	const units = 64
	model.add(
		tf.layers.bidirectional({
			// @ts-ignore
			layer: tf.layers.gru({ units, activation: 'relu', returnSequences: true }),
			inputShape: [trainData.shape[1], trainData.shape[2]],
		}),
	)
	model.add(
		tf.layers.bidirectional({
			// @ts-ignore
			layer: tf.layers.gru({ units, activation: 'relu', returnSequences: true }),
		}),
	)
	model.add(
		tf.layers.bidirectional({
			// @ts-ignore
			layer: tf.layers.gru({ units, activation: 'relu' }),
		}),
	)
	model.add(tf.layers.dense({ units: 1 }))
	model.compile({ optimizer: tf.train.adam(0.001), loss: 'meanSquaredError' })
	return model
}

export const train = async (key: string, arr: any[], window: number = 20) => {
	await tf.setBackend('wasm')
	const modelPath = `file://${__dirname}/../trainedModels/Metrics_${key}`
	const data = getWindowedData(
		arr,
		(items) => items.map((item) => [item[key]]),
		(items, nextItem) => nextItem[key],
		window,
	)
	const trainData = tf.tidy(() => buildTensors(data))
	let model = createModel(trainData.xTensor)
	let bestValLoss = Number.MAX_SAFE_INTEGER
	await model.fit(trainData.xTensor, trainData.yTensor, {
		epochs: 500,
		batchSize: 32,
		validationSplit: 0.8,
		callbacks: {
			onEpochEnd: async function (epoch, logs) {
				if (logs.val_loss < bestValLoss) {
					bestValLoss = logs.val_loss
					await model.save(modelPath)
				}
			},
		},
	})
	return tf.loadLayersModel(`${modelPath}/model.json`)
}

Describe the expected behavior

Should create the model, start fit.

Standalone code to reproduce the issue
Provide a reproducible test case that is the bare minimum necessary to generate
the problem. If possible, please share a link to Colab/CodePen/any notebook.

Other info / logs Include any logs or source code that would be helpful to
diagnose the problem. If including tracebacks, please include the full
traceback. Large logs and files should be attached.

RuntimeError: abort(TypeError: info.backend.decComplexRef is not a function). Build with -s ASSERTIONS=1 for more info.
    at process.abort (/Users/xxxx/Desktop/Repos/xxxx/xxxx/node_modules/@tensorflow/tfjs-backend-wasm/wasm-out/tfjs-backend-wasm.js:9:9928)
    at process.emit (node:events:327:20)
    at process.EventEmitter.emit (node:domain:486:12)
    at process.emit (/Users/xxxx/Desktop/Repos/xxxx/xxxx/node_modules/source-map-support/source-map-support.js:495:21)
    at processPromiseRejections (node:internal/process/promises:214:33)
    at processTicksAndRejections (node:internal/process/task_queues:94:32)
@Moumouls Moumouls added the type:bug Something isn't working label Jan 28, 2021
@Moumouls
Copy link
Author

Okay i found that you can't have this in your package.json

	"dependencies": {
		"@tensorflow/tfjs": "^3.0.0",
		"@tensorflow/tfjs-backend-wasm": "^3.0.0",
		"@tensorflow/tfjs-node": "^2.8.2",
		"@tensorflow/tfjs-node-gpu": "^3.0.0",

Error is gone after removing other @tensorflow packages

	"dependencies": {
		"@tensorflow/tfjs": "^3.0.0",
		"@tensorflow/tfjs-backend-wasm": "^3.0.0",

@rthadur
Copy link
Contributor

rthadur commented Jan 28, 2021

In your package.json, if you have include the union package '@tensorflow/tfjs',
you don't need to include other individual packages (tfjs-node,tfjs-node-gpu etc)

@rthadur rthadur self-assigned this Jan 28, 2021
@rthadur rthadur added stat:awaiting response type:build/install and removed type:bug Something isn't working labels Jan 28, 2021
@google-ml-butler
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you.

@google-ml-butler
Copy link

Closing as stale. Please @mention us if this needs more attention.

@google-ml-butler
Copy link

Are you satisfied with the resolution of your issue?
Yes
No

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants