-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[tfjs-react-native] AsyncStorageIO fails to save big GraphModels: "Error: Exception in HostFunction: Malformed calls from JS: field sizes are different" #2773
Comments
This might be related to this issue facebook/react-native#23835. One potential cause is a (seemingly) unserializable values like Could you check your weights to see if you have any of these values? If you load your model in a browser you can use https://js.tensorflow.org/api_vis/1.4.0/#show.layer to look at counts for these for each layer (you can also just count them directly). |
Thank you for checking in! Given that my model is a GraphModel, it lacks the layer property, and I am unable to visualize it using tfjs-vis since the method you linked uses layers, and the summary one accepts only LayerModels. However, I manually checked the weights using the var model = await tfconv.loadGraphModel(this.modelPath);
var result = Object.keys(model.model.weights).map(function(key) {
return model.model.weights[key][0].dataSync().map(value => ( value == Infinity || value == -Infinity || value == NaN ));
}); // <-- this takes a long time since the weights are in total 200MB
result.map(a=>(a.length)).reduce((a, b) => (a+b)) // 50537445
result.map(val => (val.reduce((a, b) => (a+b)))).reduce((a, b) => (a+b)) // 0 My apologies if I made the comparisons wrong, I believe that since all the weights are ints and floats stored in Int32Arrays and Float32Arrays a simple comparison with By the way, the loaded model predicts the expected results both in tfjs (browser and RN) and in python, so I'm not sure if the issue is in the model. |
One correction, since NaN === NaN is false, you should use isNaN(value) to test for NaN. (You can also simplify your code a bit Array.filter The fact that it is predicting correctly doesn't completely rule out NaNs or Infinities. So just trying to pin down what might cause the serialization issue. Also what OS/Platform are you running this on? |
Thanks for the correction and suggestion, I checked for NaNs too and there's none. var result = Object.keys(model.model.weights).filter(function(key) {
return model.model.weights[key][0].dataSync().filter(value => isNaN(value)).length > 0;
});
// Array [] I'm developing it on a linux machine (ubuntu), and running it on an android device, with android 10. |
Though the error produced looks strange for this. It looks like on Android there is a default 6MB limit for AsyncStorage. This asyncStorage PR suggests that it is configurable in a gradle config. Configuration is documented here. Try that and see if it helps. |
Automatically closing due to lack of recent activity. Please update the issue when new information becomes available, and we will reopen the issue. Thanks! |
To get help from the community, we encourage using Stack Overflow and the
tensorflow.js
tag.TensorFlow.js version
All the relevant dependencies:
Browser version
React native.
Describe the problem or feature request
After loading a big model via loadGraphModel through http (the model is served locally but it should not be a problem once loaded), I try to save it in local storage using an AsyncStorageIO handler it fails, showing the following error:
Worth noting that the original SaveModel weights were 200MB, which is way bigger than any example at hand, and since the conversion shards them, the model has 49 shards of 4MB each, besides the
model.json
.Code to reproduce the bug / link to feature request
The text was updated successfully, but these errors were encountered: