pytorch - 💡(How to fix) Fix Combining `bfloat16` with complex scalars raises `NotImplementedError` [1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
pytorch/pytorch#177859Fetched 2026-04-08 01:03:12
View on GitHub
Comments
0
Participants
1
Timeline
17
Reactions
0
Participants
Timeline (top)
mentioned ×6subscribed ×6labeled ×5

Error Message

<python-input-3>:1: UserWarning: BComplex32 support is experimental and many operators don't support it yet. (Triggered internally at /Users/habbasi/Quansight/torch-build/git/pytorch/aten/src/ATen/EmptyTensor.cpp:58.) Traceback (most recent call last): File "<python-input-3>", line 1, in <module> a + b ^ NotImplementedError: "add_stub" not implemented for 'BComplex32'

Code Example

import torch
a = torch.zeros((1,), dtype=torch.bfloat16)
b = complex(0, 0)  # Any complex scalar or array with ndim=0
a + b  # Any op

---

<python-input-3>:1: UserWarning: BComplex32 support is experimental and many operators don't support it yet. (Triggered internally at /Users/habbasi/Quansight/torch-build/git/pytorch/aten/src/ATen/EmptyTensor.cpp:58.)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    a + b
    ~~^~~
NotImplementedError: "add_stub" not implemented for 'BComplex32'
RAW_BUFFERClick to expand / collapse

🐛 Describe the bug

Introduced in #173783

import torch
a = torch.zeros((1,), dtype=torch.bfloat16)
b = complex(0, 0)  # Any complex scalar or array with ndim=0
a + b  # Any op

Gives:

<python-input-3>:1: UserWarning: BComplex32 support is experimental and many operators don't support it yet. (Triggered internally at /Users/habbasi/Quansight/torch-build/git/pytorch/aten/src/ATen/EmptyTensor.cpp:58.)
Traceback (most recent call last):
  File "<python-input-3>", line 1, in <module>
    a + b
    ~~^~~
NotImplementedError: "add_stub" not implemented for 'BComplex32'

Versions

Collecting environment information... PyTorch version: 2.12.0a0+gitecbeb70 Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A

OS: macOS 26.3.1 (arm64) GCC version: Could not collect Clang version: 19.1.7 CMake version: version 4.2.3 Libc version: N/A

Python version: 3.13.12 | packaged by conda-forge | (main, Feb 5 2026, 06:11:05) [Clang 19.1.7 ] (64-bit runtime) Python platform: macOS-26.3.1-arm64-arm-64bit-Mach-O Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA Is XPU available: False HIP runtime version: N/A MIOpen runtime version: N/A Is XNNPACK available: False Caching allocator config: N/A

CPU: Apple M3 Max

Versions of relevant libraries: [pip3] flake8==7.3.0 [pip3] numpy==2.4.2 [pip3] optree==0.19.0 [pip3] torch==2.12.0a0+gitecbeb70 [conda] Could not collect

cc @ezyang @anjali411 @dylanbespalko @mruberry @nikitaved @amjames

extent analysis

Fix Plan

The fix involves avoiding the use of experimental BComplex32 data type and instead using a supported data type for complex numbers.

  • Step 1: Convert the torch.bfloat16 tensor to a supported data type, such as torch.float32 or torch.complex64.
  • Step 2: Perform the desired operation using the converted tensor.

Example Code

import torch

# Create a tensor with a supported data type
a = torch.zeros((1,), dtype=torch.float32)
b = complex(0, 0)  # Any complex scalar or array with ndim=0

# Convert the complex number to a torch tensor
b_tensor = torch.tensor([b.real, b.imag], dtype=torch.float32)

# Perform the desired operation
result = a + b_tensor[0]  # Add the real part of b to a

print(result)

Alternatively, you can use torch.complex64 data type to represent complex numbers:

import torch

# Create a tensor with complex data type
a = torch.zeros((1,), dtype=torch.complex64)
b = complex(0, 0)  # Any complex scalar or array with ndim=0

# Convert the complex number to a torch tensor
b_tensor = torch.tensor(b, dtype=torch.complex64)

# Perform the desired operation
result = a + b_tensor

print(result)

Verification

To verify that the fix worked, you can check the output of the example code and ensure that it produces the expected result without raising any errors.

Extra Tips

  • Be cautious when using experimental data types, as they may not be fully supported and can lead to unexpected behavior.
  • Always check the PyTorch documentation for the latest information on supported data types and operations.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

pytorch - 💡(How to fix) Fix Combining `bfloat16` with complex scalars raises `NotImplementedError` [1 participants]