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

WebGPU readSync is only available for CPU-resident tensors. #7274

Closed
lebron8dong opened this issue Jan 16, 2023 · 12 comments · Fixed by #7276
Closed

WebGPU readSync is only available for CPU-resident tensors. #7274

lebron8dong opened this issue Jan 16, 2023 · 12 comments · Fixed by #7276

Comments

@lebron8dong
Copy link

I trained a model on the browser and used webgpu to load the model and reported an error:I trained a model on the browser and used webgpu to load the model and reported an error

@qjia7
Copy link
Contributor

qjia7 commented Jan 16, 2023

@lebron8dong Can you help to give an accessible case so that we can reproduce and debug this issue?

@lebron8dong
Copy link
Author

lebron8dong commented Jan 16, 2023

@lebron8dong Can you help to give an accessible case so that we can reproduce and debug this issue?
@qjia7

https://codelabs.developers.google.com/codelabs/tfjs-training-classfication?hl=zh-cn#0 This is the official example, I reproduced the model, but reported the error when using webgpu as the backend. I used cpu and webgl to train the model respectively, but when I used webgpu to load the model, both reported the same error:WebGPU readSync is only available for CPU-resident tensors.

@qjia7
Copy link
Contributor

qjia7 commented Jan 16, 2023

Can you directly share the complete webgpu case code so that I can try it locally? Or a very small case to reproduce your issue?

@lebron8dong
Copy link
Author

Can you directly share the complete webgpu case code so that I can try it locally? Or a very small case to reproduce your issue?
@qjia7
https://github.com/lebron8dong/tfjs This is the folder for training the model and loading the model with webgpu.

@lebron8dong
Copy link
Author

Can you directly share the complete webgpu case code so that I can try it locally? Or a very small case to reproduce your issue?

@qjia7 source of error:
// TODO: Remove once this is fixed:
// #1595
override readSync(dataId: object): BackendValues {
const tensorData = this.tensorMap.get(dataId);
const {values} = tensorData;

if (values == null) {
  throw new Error(
      'WebGPU readSync is only available for CPU-resident tensors.');
}

return values;

}

@qjia7
Copy link
Contributor

qjia7 commented Jan 16, 2023

@lebron8dong Thanks for your information. I can reproduce it now. The main problem is that webgpu itself doesn't support synchronous read. However, there are still several places using dataSync in tfjs framework. The error in your case is triggered by https://github.com/tensorflow/tfjs/blob/master/tfjs-vis/src/util/math.ts#L290. I will check whether I can remove dataSync and use something else or workaround it in webgpu backend.

@lebron8dong
Copy link
Author

@lebron8dong Thanks for your information. I can reproduce it now. The main problem is that webgpu itself doesn't support synchronous read. However, there are still several places using dataSync in tfjs framework. The error in your case is triggered by https://github.com/tensorflow/tfjs/blob/master/tfjs-vis/src/util/math.ts#L290. I will check whether I can remove dataSync and use something else or workaround it in webgpu backend.

@qjia7
Thank you very much, I will wait for your good news.

qjia7 added a commit to qjia7/tfjs that referenced this issue Jan 17, 2023
qjia7 added a commit that referenced this issue Jan 18, 2023
Fix: #7274

Co-authored-by: Linchenn <40653845+Linchenn@users.noreply.github.com>
@lebron8dong
Copy link
Author

@qjia7 There is still the same error in my demo. Does my demo code need to be changed?

@qjia7
Copy link
Contributor

qjia7 commented Jan 18, 2023

You need to wait for the next release of tfjs-vis. Or build it by yourself from the source code https://github.com/tensorflow/tfjs/tree/master/tfjs-vis. I tried it locally. The next issue you may meet is platform.isTypedArray is not a function. After some workarounds to void #7273, it works on webgpu.

@lebron8dong
Copy link
Author

@qjia7 thank you very much,thank you very much.

@lebron8dong
Copy link
Author

@qjia7
const res = model.predict(test);
res. print();
reported the same error:WebGPU readSync is only available for CPU-resident tensors.
Under the backend of webgpu, I want to print the result on the console, is this possible?

@qjia7
Copy link
Contributor

qjia7 commented Feb 13, 2023

@lebron8dong WebGPU only supports async read. Maybe try const data = await res.data(); console.log(data)

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

Successfully merging a pull request may close this issue.

2 participants