NVlabs / curobo

CUDA Accelerated Robot Library
https://curobo.org
Other
722 stars 107 forks source link

RuntimeError: expected scalar type double but found float #35

Closed Shihao-Feng-98 closed 8 months ago

Shihao-Feng-98 commented 10 months ago

I install cuRobo in python mode(ubuntu20.04 CUDA11.3, pytorch 1.11 and python3.7). When running pytest using "python3 -m pytest .", I got an error "RuntimeError: expected scalar type double but found float", and this error due to the function of normalize_quaternion() in src/curobo/types/math.py. I am new in pytorch and CUDA, how should I fix this bug?

balakumar-s commented 10 months ago

How did you install pytorch?

Shihao-Feng-98 commented 10 months ago

I installed using "pip install -e . --no-build-isolation" in a conda environment

balakumar-s commented 10 months ago

Can you paste the terminal output for the tests?

Shihao-Feng-98 commented 10 months ago

I got the following output in terminal

============================================================================================= ERRORS =============================================================================================
____________________________________________________________________________ ERROR collecting tests/ik_config_test.py ____________________________________________________________________________
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
../anaconda3/envs/rvbust/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
    ???
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:677: in _load_unlocked
    ???
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
tests/ik_config_test.py:134: in <module>
    (ik_base_config(), True),
tests/ik_config_test.py:36: in ik_base_config
    load_yaml(join_path(get_robot_configs_path(), robot_file))["robot_cfg"]
src/curobo/types/robot.py:49: in from_dict
    CudaRobotGeneratorConfig(**data_dict_in["kinematics"], tensor_args=tensor_args)
<string>:30: in __init__
    ???
src/curobo/cuda_robot_model/cuda_robot_generator.py:203: in __post_init__
    self.extra_links[k] = LinkParams.from_dict(self.extra_links[k])
src/curobo/cuda_robot_model/kinematics_parser.py:43: in from_dict
    Pose.from_list(dict_data["fixed_transform"], tensor_args=TensorDeviceType())
src/curobo/types/math.py:226: in from_list
    return Pose(position=position, quaternion=quaternion)
<string>:9: in __init__
    ???
src/curobo/types/math.py:83: in __post_init__
    self.quaternion = normalize_quaternion(self.quaternion)
E   RuntimeError: The following operation failed in the TorchScript interpreter.
E   Traceback of TorchScript (most recent call last):
E     File "/home/feng_shihao/curobo/src/curobo/types/math.py", line 521, in normalize_quaternion
E       k = torch.sign(in_quaternion[..., 0:1])
E       # NOTE: torch sign returns 0 as sign value when value is 0.0
E       k = torch.where(k == 0, 1.0, k)
E           ~~~~~~~~~~~ <--- HERE
E       k2 = k / torch.linalg.norm(in_quaternion, dim=-1, keepdim=True)
E       # normalize quaternion
E   RuntimeError: expected scalar type double but found float
_________________________________________________________________________ ERROR collecting tests/trajopt_config_test.py __________________________________________________________________________
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/runner.py:341: in from_call
    result: Optional[TResult] = func()
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/runner.py:372: in <lambda>
    call = CallInfo.from_call(lambda: list(collector.collect()), "collect")
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:531: in collect
    self._inject_setup_module_fixture()
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:545: in _inject_setup_module_fixture
    self.obj, ("setUpModule", "setup_module")
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:310: in obj
    self._obj = obj = self._getobj()
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:528: in _getobj
    return self._importtestmodule()
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/python.py:617: in _importtestmodule
    mod = import_path(self.path, mode=importmode, root=self.config.rootpath)
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/pathlib.py:567: in import_path
    importlib.import_module(module_name)
../anaconda3/envs/rvbust/lib/python3.7/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
<frozen importlib._bootstrap>:1006: in _gcd_import
    ???
<frozen importlib._bootstrap>:983: in _find_and_load
    ???
<frozen importlib._bootstrap>:967: in _find_and_load_unlocked
    ???
<frozen importlib._bootstrap>:677: in _load_unlocked
    ???
../anaconda3/envs/rvbust/lib/python3.7/site-packages/_pytest/assertion/rewrite.py:186: in exec_module
    exec(co, module.__dict__)
tests/trajopt_config_test.py:115: in <module>
    (trajopt_base_config(), True),
tests/trajopt_config_test.py:31: in trajopt_base_config
    load_yaml(join_path(get_robot_configs_path(), robot_file))["robot_cfg"]
src/curobo/types/robot.py:49: in from_dict
    CudaRobotGeneratorConfig(**data_dict_in["kinematics"], tensor_args=tensor_args)
<string>:30: in __init__
    ???
src/curobo/cuda_robot_model/cuda_robot_generator.py:203: in __post_init__
    self.extra_links[k] = LinkParams.from_dict(self.extra_links[k])
src/curobo/cuda_robot_model/kinematics_parser.py:43: in from_dict
    Pose.from_list(dict_data["fixed_transform"], tensor_args=TensorDeviceType())
src/curobo/types/math.py:226: in from_list
    return Pose(position=position, quaternion=quaternion)
<string>:9: in __init__
    ???
src/curobo/types/math.py:83: in __post_init__
    self.quaternion = normalize_quaternion(self.quaternion)
E   RuntimeError: The following operation failed in the TorchScript interpreter.
E   Traceback of TorchScript (most recent call last):
E     File "/home/feng_shihao/curobo/src/curobo/types/math.py", line 521, in normalize_quaternion
E       k = torch.sign(in_quaternion[..., 0:1])
E       # NOTE: torch sign returns 0 as sign value when value is 0.0
E       k = torch.where(k == 0, 1.0, k)
E           ~~~~~~~~~~~ <--- HERE
E       k2 = k / torch.linalg.norm(in_quaternion, dim=-1, keepdim=True)
E       # normalize quaternion
E   RuntimeError: expected scalar type double but found float
balakumar-s commented 10 months ago

Can you upgrade your pytorch to a newer version? Looks like this was an issue in pytorch that was fixed: https://github.com/pytorch/pytorch/issues/64161

Shihao-Feng-98 commented 10 months ago

I upgraded pytorch to 1.12, and the above pytest error was fixed. And a new error about "ValueError: string is not a file: /home/feng_shihao/curobo/src/curobo/content/assets/scene/nvblox/srl_ur10_bins.obj" occured in pytest, does it mean the nvblox should installed?

balakumar-s commented 10 months ago

That could mean that you don't have lfs installed.

Try this: https://github.com/NVlabs/curobo/issues/14#issuecomment-1790139026

balakumar-s commented 8 months ago

Closing this issue assuming the issue was not having lfs installed.