facebookresearch / mbrl-lib

Library for Model Based RL
MIT License
952 stars 154 forks source link

[Bug] Algorithm tests fail in Pytorch 1.7.1 #147

Closed AVSurfer123 closed 2 years ago

AVSurfer123 commented 2 years ago

Steps to reproduce

  1. Install this library with Python 3.7 and PyTorch 1.7.1
  2. Run the test python3 -m pytest tests/algorithms

Observed Results

You get the errors

FAILED tests/algorithms/test_algorithms.py::test_pets_icem_gaussian_mlp_ensemble - TypeError: clamp(): argument 'min' (position 2) must be Number, not Tensor
FAILED tests/algorithms/test_algorithms.py::test_pets_icem_basic_ensemble_deterministic_mlp - TypeError: clamp(): argument 'min' (position 2) must be Number, not Tensor

because torch.clamp doesn't support tensors for the min and max arguments till version 1.9.0. So either the README should be updated with the newer PyTorch version or the test/code should be fixed to work with 1.7.0 still.

Expected Results

Tests pass successfully.

Relevant Code

The error occurs at

population = mbrl.util.math.powerlaw_psd_gaussian(
    self.colored_noise_exponent,
    size=(decay_population_size, x0.shape[1], x0.shape[0]),
    device=self.device,
).transpose(1, 2)
population = torch.clamp(
    population * torch.sqrt(var) + mu, self.lower_bound, self.upper_bound
)

E           TypeError: clamp(): argument 'min' (position 2) must be Number, not Tensor

mbrl/planning/trajectory_opt.py:439: TypeError
luisenp commented 2 years ago

Hi @AVSurfer123, thanks for reporting! Can you pull the code in #148 and test if it works for you? Thanks!