-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
[Question] C++ Inference #836
Comments
Hello,
Is that different options or a list of features? but yes, at the end would be nice to have something like
what are your questions? |
My list is a list of features. About questions, I mostly wanted to know what was the recommended direction for this. Making it some contrib to RL Zoo indeed looks like the way to go, since the export can be achieve "from the outside" or SB3. |
Feel free to open a draft PR there if you want to discuss it in more details ;) |
I started working on that in the RL Zoo, I will indeed open a draft PR soon, even if it will not support everything it can be used as a base for discussions I have a very short term goals of embedding inferences in our humanoid robots so I will also be the first user |
Ok, I started a draft PR Design choices
A procedure to testTo test that it indeed works, I added an option to generate a Python binding while building, so that we can directly use Python's gym to test it. Here are the steps:
From here you can test with such a script: import gym
from baselines3_py import CartPole_v1
cp = CartPole_v1()
env = gym.make('CartPole-v1')
obs = env.reset()
while True:
action = cp.predict(obs)
obs, reward, done, info = env.step(int(action[0]))
env.render("human")
if done:
obs = env.reset()
obs = gym.reset() It should show you the CartPole, using the C++ built library for prediction. You can also of course build without the Python binding and use the library from your C++ code. An example can be found in |
Maybe you are just looking for something like this... |
@stalek71 thanks for the lead, however the problem here is not exactly to save a PyTorch model to a C++ executable file and load it (which is explained in [1]), but to export SB3 models (at least in first place More specifically, it implies:
This is not very complicated matter but it requires some specific knowledge of how underlying RL agents works. So I guess it's good to have the whole process automated. (The use case is: I want the thing running in a robot without running any Python code (because it is embedded real-time robotics application).) |
Thanks for the PR =)
sounds good.
I think we should keep the first version as simple as possible (for instance limiting ourselves to a subset of models or action spaces)
how much more difficult is it to just give a path to
this could be even automated, no?
I would rather keep the name of the algorithm (or concatenate it with the name of the env) to avoid confusion.
Do you have also an example cpp file to show how to use that shared lib?
This is not consistent with SB3 API, but I think it's fine as it is target towards deployment (and only RecurrentPPO requires a hidden state). |
It is not, I really can make it this way, dropping the dependency with CMRC or making it optional
Enabling the Python binding is more like a test than a real use case. There is likely not that much performance boost because most of the computation is actually achieved by PyTorch, it's just about embedding it in C++. But yes, we could automate the build and run of Python tests on the top of library for unit test purposes, CI and so
So far just the simple: |
Less dependencies is usually better ;)
I meant automating the build of the shared lib, but I probably misunderstood what you wrote.
this would be nice to have at least some test on the CI (nothing too complicated)
thanks =) |
Closing that one in favor of another one that gonna be opened soon (per discussion with Grégoire). |
Question
Hello, I am using SB3 to train some model where I want the inference to run on embedded robots using C++. I had a look at PyTorch documentation and doing this is not very hard "by hand", but the process could indeed be automated.
I could maybe contribute, but I would like some questions to be answered about how do you imagine the feature.
In my opinion, there is more that can be done that simply documenting it, because we could help to automate the observation and action rescaling and normalizing, in a way such that methods like
model.predict
gets converted seamlessly to C++.Here is how I would see it:
.pt
) from the different agents implemented in SB3What do you think ?
Additional context
Checklist
The text was updated successfully, but these errors were encountered: