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

[BUGFIX] Drone rpm to cpu #607

Conversation

eferreirafilho
Copy link
Contributor

@eferreirafilho eferreirafilho commented Jan 18, 2025

Problem

Using python examples/drone/hover_train.py -e drone-hovering -B 8192 --max_iterations 10 was not working:

root@9f23f87289b1:/workspace# python examples/drone/hover_train.py -e drone-hovering -B 8192 --max_iterations 30 
Actor MLP: Sequential(
  (0): Linear(in_features=17, out_features=128, bias=True)
  (1): Tanh()
  (2): Linear(in_features=128, out_features=128, bias=True)
  (3): Tanh()
  (4): Linear(in_features=128, out_features=4, bias=True)
)
Critic MLP: Sequential(
  (0): Linear(in_features=17, out_features=128, bias=True)
  (1): Tanh()
  (2): Linear(in_features=128, out_features=128, bias=True)
  (3): Tanh()
  (4): Linear(in_features=128, out_features=1, bias=True)
)
Traceback (most recent call last):
  File "/workspace/examples/drone/hover_train.py", line 150, in <module>
    main()
  File "/workspace/examples/drone/hover_train.py", line 146, in main
    runner.learn(num_learning_iterations=args.max_iterations, init_at_random_ep_len=True)
  File "/workspace/rsl_rl/rsl_rl/runners/on_policy_runner.py", line 108, in learn
    obs, privileged_obs, rewards, dones, infos = self.env.step(actions)
                                                 ^^^^^^^^^^^^^^^^^^^^^^
  File "/workspace/examples/drone/hover_env.py", line 135, in step
    self.drone.set_propellels_rpm((1 + exec_actions * 0.8) * 14468.429183500699)
  File "/opt/conda/lib/python3.11/site-packages/genesis/engine/entities/drone_entity.py", line 50, in set_propellels_rpm
    propellels_rpm = self.solver._process_dim(np.array(propellels_rpm, dtype=gs.np_float)).T
                                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/conda/lib/python3.11/site-packages/torch/_tensor.py", line 1151, in __array__
    return self.numpy().astype(dtype, copy=False)
           ^^^^^^^^^^^^
TypeError: can't convert cuda:0 device type tensor to numpy. Use Tensor.cpu() to copy the tensor to host memory first.

Fix

Change propellers rpm to cpu before applying to drone.

@KafuuChikai
Copy link
Contributor

You can refer to the latest update #598 where we have replaced NumPy with Torch for performance reasons.

Therefore, the issue should be resolved by installing the latest version of Genesis.

git clone https://github.com/Genesis-Embodied-AI/Genesis.git
cd Genesis
pip install -e .

@YilingQiao
Copy link
Collaborator

Thanks for your PR. I'm going to close it, but feel free to let us know if you have any other issues.

@YilingQiao YilingQiao closed this Feb 2, 2025
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 this pull request may close these issues.

3 participants