Skip to content

RuntimeError: expected scalar type Float but found BFloat16 #31

Closed

Description

@yusskkt

what i input :
ns-train gaussctrl --load-checkpoint unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt --experiment-name bear --output-dir outputs --pipeline.datamanager.data data/bear --pipeline.edit_prompt "a photo of a polar bear in the forest" --pipeline.reverse_prompt "a photo of a bear statue in the forest" --pipeline.guidance_scale 5 --pipeline.chunk_size 3 --pipeline.langsam_obj 'bear' --viewer.quit-on-train-completion True

Loading pipeline components...: 100%|█████████████████████████████████████████████████████████████████| 7/7 [00:01<00:00, 5.32it/s]
Attempting to load checkpoint from: unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt
Done loading Nerfstudio checkpoint from
unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt
Rendering view 0
Traceback (most recent call last):
File "/root/data1/miniconda3/envs/gsctrl/bin/ns-train", line 8, in
sys.exit(entrypoint())
^^^^^^^^^^^^
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 262, in entrypoint
main(
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 247, in main
launch(
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 189, in launch
main_func(local_rank=0, world_size=world_size, config=config)
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 99, in train_loop
trainer.setup()
File "/root/data1/code/gaussctrl/gaussctrl/gc_trainer.py", line 76, in setup
self.pipeline.render_reverse()
File "/root/data1/code/gaussctrl/gaussctrl/gc_pipeline.py", line 134, in render_reverse
rendered_image = self._model.get_outputs_for_camera(current_cam)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/torch/utils/_contextlib.py", line 116, in decorate_context
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/root/data1/code/gaussctrl/gaussctrl/gc_model.py", line 232, in get_outputs_for_camera
outs = self.get_outputs(camera.to(self.device))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/data1/code/gaussctrl/gaussctrl/gc_model.py", line 140, in get_outputs
self.xys, depths, self.radii, conics, num_tiles_hit, cov3d = project_gaussians( # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/gsplat/project_gaussians.py", line 59, in project_gaussians
return _ProjectGaussians.apply(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/torch/autograd/function.py", line 574, in apply
return super().apply(*args, **kwargs) # type: ignore[misc]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/gsplat/project_gaussians.py", line 109, in forward
) = _C.project_gaussians_forward(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/gsplat/cuda/init.py", line 9, in call_cuda
return getattr(_C, name)(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
RuntimeError: expected scalar type Float but found BFloat16

How can I solve this problem? Thanks a lot!

Activity

  1. jingwu2121 commented on Feb 18, 2025

    @jingwu2121
    Collaborator

    Hi, please try manually set the variable type to float16 in

    File "/root/data1/code/gaussctrl/gaussctrl/gc_pipeline.py", line 134, in render_reverse
    rendered_image = self._model.get_outputs_for_camera(current_cam)
    

    like this

    current_cam.to(torch.float16())
    
  2. yusskkt commented on Feb 19, 2025

    @yusskkt
    Author

    Thank you very much for your reply! I changed the variable to float16 and tried to run it again, and then an error occurred.
    change:
    current_cam = self.datamanager.cameras[cam_idx].to(self.device).to(torch.float16)

      if current_cam.metadata is None:
          current_cam.metadata = {}
      current_cam.metadata["cam_idx"] = cam_idx
      rendered_image = self._model.get_outputs_for_camera(current_cam)
    

    error:
    Attempting to load checkpoint from: unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt
    Done loading Nerfstudio checkpoint from
    unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt
    Rendering view 0
    Traceback (most recent call last):
    File "/root/data1/miniconda3/envs/gsctrl/bin/ns-train", line 8, in
    sys.exit(entrypoint())
    ^^^^^^^^^^^^
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 262, in entrypoint
    main(
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 247, in main
    launch(
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 189, in launch
    main_func(local_rank=0, world_size=world_size, config=config)
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 99, in train_loop
    trainer.setup()
    File "/root/data1/code/gaussctrl/gaussctrl/gc_trainer.py", line 76, in setup
    self.pipeline.render_reverse()
    File "/root/data1/code/gaussctrl/gaussctrl/gc_pipeline.py", line 132, in render_reverse
    current_cam = self.datamanager.cameras[cam_idx].to(self.device).to(torch.float16)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/utils/tensor_dataclass.py", line 265, in to
    return self._apply_fn_to_fields(lambda x: x.to(device))
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/utils/tensor_dataclass.py", line 310, in _apply_fn_to_fields
    return dataclasses.replace(self_dc, **new_fields)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/dataclasses.py", line 1503, in replace
    return obj.class(**changes)
    ^^^^^^^^^^^^^^^^^^^^^^^^
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/cameras/cameras.py", line 152, in init
    self.height = self._init_get_height_width(height, self.cy)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/cameras/cameras.py", line 245, in _init_get_height_width
    assert not torch.is_floating_point(h_w), f"height and width tensor must be of type int, not: {h_w.dtype}"
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    AssertionError: height and width tensor must be of type int, not: torch.float16

  3. zengjl03 commented on Mar 5, 2025

    @zengjl03
    Contributor

    Thank you very much for your reply! I changed the variable to float16 and tried to run it again, and then an error occurred. change: current_cam = self.datamanager.cameras[cam_idx].to(self.device).to(torch.float16)

      if current_cam.metadata is None:
          current_cam.metadata = {}
      current_cam.metadata["cam_idx"] = cam_idx
      rendered_image = self._model.get_outputs_for_camera(current_cam)
    

    error: Attempting to load checkpoint from: unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt Done loading Nerfstudio checkpoint from unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt Rendering view 0 Traceback (most recent call last): File "/root/data1/miniconda3/envs/gsctrl/bin/ns-train", line 8, in sys.exit(entrypoint()) ^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 262, in entrypoint main( File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 247, in main launch( File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 189, in launch main_func(local_rank=0, world_size=world_size, config=config) File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 99, in train_loop trainer.setup() File "/root/data1/code/gaussctrl/gaussctrl/gc_trainer.py", line 76, in setup self.pipeline.render_reverse() File "/root/data1/code/gaussctrl/gaussctrl/gc_pipeline.py", line 132, in render_reverse current_cam = self.datamanager.cameras[cam_idx].to(self.device).to(torch.float16) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/utils/tensor_dataclass.py", line 265, in to return self._apply_fn_to_fields(lambda x: x.to(device)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/utils/tensor_dataclass.py", line 310, in _apply_fn_to_fields return dataclasses.replace(self_dc, **new_fields) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/dataclasses.py", line 1503, in replace return obj.class(**changes) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/cameras/cameras.py", line 152, in init self.height = self._init_get_height_width(height, self.cy) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/cameras/cameras.py", line 245, in _init_get_height_width assert not torch.is_floating_point(h_w), f"height and width tensor must be of type int, not: {h_w.dtype}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: height and width tensor must be of type int, not: torch.float16

    I have same problem, could you tell me how to solve it? thanks!

  4. PotatoBigRoom commented on Mar 13, 2025

    @PotatoBigRoom

    I have the same problem,could you please tell me how to solve it?

  5. yusskkt commented on Apr 2, 2025

    @yusskkt
    Author

    I have the same problem,could you please tell me how to solve it?

    Thank you very much for your reply! I changed the variable to float16 and tried to run it again, and then an error occurred. change: current_cam = self.datamanager.cameras[cam_idx].to(self.device).to(torch.float16)

      if current_cam.metadata is None:
          current_cam.metadata = {}
      current_cam.metadata["cam_idx"] = cam_idx
      rendered_image = self._model.get_outputs_for_camera(current_cam)
    

    error: Attempting to load checkpoint from: unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt Done loading Nerfstudio checkpoint from unedited_models/bear/splatfacto/2024-12-20_113611/nerfstudio_models/step-000029999.ckpt Rendering view 0 Traceback (most recent call last): File "/root/data1/miniconda3/envs/gsctrl/bin/ns-train", line 8, in sys.exit(entrypoint()) ^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 262, in entrypoint main( File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 247, in main launch( File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 189, in launch main_func(local_rank=0, world_size=world_size, config=config) File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/scripts/train.py", line 99, in train_loop trainer.setup() File "/root/data1/code/gaussctrl/gaussctrl/gc_trainer.py", line 76, in setup self.pipeline.render_reverse() File "/root/data1/code/gaussctrl/gaussctrl/gc_pipeline.py", line 132, in render_reverse current_cam = self.datamanager.cameras[cam_idx].to(self.device).to(torch.float16) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/utils/tensor_dataclass.py", line 265, in to return self._apply_fn_to_fields(lambda x: x.to(device)) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/utils/tensor_dataclass.py", line 310, in _apply_fn_to_fields return dataclasses.replace(self_dc, **new_fields) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/dataclasses.py", line 1503, in replace return obj.class(**changes) ^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/cameras/cameras.py", line 152, in init self.height = self._init_get_height_width(height, self.cy) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/root/data1/miniconda3/envs/gsctrl/lib/python3.11/site-packages/nerfstudio/cameras/cameras.py", line 245, in _init_get_height_width assert not torch.is_floating_point(h_w), f"height and width tensor must be of type int, not: {h_w.dtype}" ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: height and width tensor must be of type int, not: torch.float16

    I have same problem, could you tell me how to solve it? thanks!

    sorry,i can't solve it

  6. manolisfosteris commented on Mar 10, 2026

    @manolisfosteris

    Hey, I had the same problem and my understanding is that this is caused by a dtype mismatch between the splatfacto checkpoint (which stores tensors in BFloat16) and gsplat's project_gaussians(), which expects Float32.

    Two changes in gc_model.py fix it:
    1. Explicitly cast all tensors to float32 before calling project_gaussians():
    means_crop = means_crop.float()
    scales_crop = scales_crop.float()
    quats_crop = quats_crop.float()
    opacities_crop = opacities_crop.float()
    colors_crop = colors_crop.float()
    viewmat = viewmat.float()
    projmat = projmat.float()
    2. Wrap the get_outputs() call in get_render_outputs() with autocast(enabled=False) to prevent AMP from re-introducing BFloat16:
    with torch.cuda.amp.autocast(enabled=False):
    outs = self.get_outputs(camera.to(self.device))
    Without the second fix, PyTorch's Automatic Mixed Precision can silently cast the tensors back to BFloat16 inside get_outputs(), undoing the explicit casts.

  7. HuangZhongTian1009 commented on Mar 18, 2026

    @HuangZhongTian1009

    Has everyone solved this problem,“RuntimeError: expected scalar type Float but found BFloat16 ”

  8. zengjl03 commented on Mar 18, 2026

    @zengjl03
    Contributor

    Has everyone solved this problem,“RuntimeError: expected scalar type Float but found BFloat16 ”

    #31 (comment) you could have a try to solve the problem using this method, i conduct perfectly before.

  9. HuangZhongTian1009 commented on Mar 18, 2026

    @HuangZhongTian1009

    大家都解决这个问题了吗?“运行时错误:预期标量类型为 Float,但找到的是 BFloat16”

    #31(评论)你可以尝试用这种方法解决问题,我之前用这种方法成功解决了这个问题。

    After completing the conversion of the first variable, an error is still reported.
    Does the second one also need to be modified?

  10. zengjl03 commented on Mar 18, 2026

    @zengjl03
    Contributor

    大家都解决这个问题了吗?“运行时错误:预期标量类型为 Float,但找到的是 BFloat16”

    #31(评论)你可以尝试用这种方法解决问题,我之前用这种方法成功解决了这个问题。

    After completing the conversion of the first variable, an error is still reported. Does the second one also need to be modified?

    maybe you can convert scalar type to Float manually everywhere it's mentioned. It's also important thing that your machine could support BFloat16. There are several months since i taken my attention to this work, so it's hard for me to give more details for you. Best wishes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions