Skip to content

TypeError "Got unsupported ScalarType BFloat16" in validation when training with amp_dtype="bfloat16" #940

Closed

Description

@AnuarSv

What happened

Training GTR-X-seg (task="segment") with amp=True, amp_dtype="bfloat16". Training steps run fine, but validation fails after every epoch, so no metrics are logged and best.pt is never selected. The validator runs under bf16 autocast, and postprocess/ec.py calls .cpu().numpy() on bf16 tensors, which NumPy does not support. postprocess and postprocess_pose in the same file have the same pattern. fp16 and fp32 are not affected.

Reproduce

import torch
from libreyolo.postprocess.ec import postprocess, postprocess_seg

out = {
    "pred_logits": torch.randn(1, 300, 1).bfloat16(),
    "pred_boxes": torch.rand(1, 300, 4).bfloat16(),
    "pred_masks": torch.randn(1, 300, 160, 160).bfloat16(),
}
postprocess(out, conf_thres=0.0, original_size=(640, 640))
postprocess_seg(out, conf_thres=0.0, original_size=(640, 640))

End to end: LibreYOLO("LibreGTRx-seg.pt").val(data=..., half=True, amp_dtype="bfloat16")

Traceback / output

ERROR | Validation failed: Got unsupported ScalarType BFloat16

  File "libreyolo/models/gtr/model.py", line 395, in _postprocess
    return postprocess_seg(
  File "libreyolo/postprocess/ec.py", line 82, in postprocess_seg
    "scores": scores.cpu().numpy()
TypeError: Got unsupported ScalarType BFloat16

Environment

libreyolo 1.6.0 (same code on dev e11cae7), Python 3.14, torch 2.12.0+cu126, Linux, CUDA
Custom dataset, ~26k images, 1 class, imgsz 640, batch 4

Already tried

  • val with half=False works
  • fp16 autocast works
  • calling .float() on the bf16 tensors before .numpy() makes the snippet above pass

Activity

  1. added a commit that references this issue on Oct 17, 2026
  2. EHxuban11 commented on Oct 17, 2026

    @EHxuban11
    Contributor

    Hello @AnuarSv ,

    Thank you for reporting this and for proposing a fix. The fix is minimal and does the job. So I merged it to dev and it will ship on the next release (v1.7.0).

    Congratulations on your first contribution to LibreYOLO and thanks again ! 🚀 : )

  3. added
    bugSomething isn't working
    and removed on Oct 21, 2026
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

    bugSomething isn't working

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions