-
Notifications
You must be signed in to change notification settings - Fork 101
onnx export: properly handle obs_keys #231
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello, and thanks for this PR.
A couple of quick test notes:
- When trying to export multiple keys, e.g. obs1 and obs2 using
export_model_as_onnx(model, str(path_onnx), obs_keys=["obs1, obs2"])I got:KeyError: 'obs1'. This wasn't previously supported either, so it's not something that this PR needs to address. - With a single key, the export works, but there's a verification error, as our verification currently uses "obs" for the name.
I should add for context that the original code exported ["obs"] and the recent change to support changing the name was only intended to allow training with a custom obs dictionary name (#212), it did still use ["obs"] for inference, as it didn't require changing the onnx code and the dictionary name during inference shouldn't have any effect. The PR didn't tackle support for multiple keys.
When it comes to multiple obs dictionaries, in the simplest case the observations are just concatenated, so it should be possible to use a single dictionary as well. In other cases where each observation dictionary is processed separately it is different (currently not supported by our onnx inference code, but Python inference support is available).
Other considerations (I edited this section after re-checking the plugin PR and seeing it shouldn't affect compatibility):
- We should also check also if the CleanRL and Rllib exported onnx still work with the plugin changes.
Edit 2: I've briefly checked with clean_rl_pqn_example for now, it seems to work. I didn't check the plugin code in depth yet, but I assume it just sends the observation arrays for each dictionary key to the onnx model instead of the fixed "obs", and so should still work with previously exported onnx files.
|
Hello, thank you for locking into my PR. About your notes:
I think it's quite relevant to support multiple keys for stuff like the aforementioned feature extractor (or at least I wouldn't know how to do this in such a simple manner else). The exported ONNX models of the other libraries should absolutely still work in the plugin with that PR, as the behavior is still pretty much the same. Exactly like you said, it just does what the plugin did for the 'obs' key before for all the keys in the observation dictionary now. |
|
Thanks for the update and nice catch about the typo. Everything sounds good based on your comments and I agree with the changes.
Yes, it's likely the best option for those cases. Thanks again for the PR. I will start the automated workflows, it may be a couple of days until I can manually check it for a final test, but otherwise it all looks good. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for clarifying on some points. I performed a quick test, should be ready to merge after adding support for use_obs_array=True as above.
Co-authored-by: Ivan-267 <[email protected]>
|
@edbeeching should be ready to merge now. |
|
merged, thanks |
At the moment, the onnx export kinda ignores the passed observation keys and uses a hard coded "obs" at export. With these minor changes this is fixed and the onnx model has the properly named inputs set after export.
I viewed the exported model in Netron and ran an exported model in godot with the godot addon (I had to modify the add-on to not take the key "obs" for granted, probably will make a pull request for that later) to verify this modification works as intended.
Pls let me know if any further changes are necessary to get this merged.
Kind regards
Nico