8000 [ONNX] Produce correct dtypes for bf16/f8 in IR TorchTensor by justinchuby · Pull Request #151259 · pytorch/pytorch · GitHub
[go: up one dir, main page]

Skip to content

[ONNX] Produce correct dtypes for bf16/f8 in IR TorchTensor #151259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update test
  • Loading branch information
justinchuby committed Apr 14, 2025
commit c7617da566e9de41ecf1a0be9dd5a482d05fddc3
26 changes: 24 additions & 2 deletions test/onnx/exporter/test_small_models_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,30 @@ def forward(self, input: torch.Tensor):
input = input.to(float8_type)
return input

onnx_program = self.export(Float8Module(), (torch.randn(1, 2),))
self.assertEqual(onnx_program.model.graph.outputs[0].dtype, onnx_type)
_ = self.export(Float8Module(), (torch.randn(1, 2),))

def test_bfloat16_support(self):
class BfloatModel(torch.nn.Module):
def __init__(self):
super().__init__()
# Test parameters
self.param = torch.nn.Parameter(torch.tensor(2.0, dtype=torch.bfloat16))

def forward(self, x):
# Test constant tensors are stored as bfloat16
const = torch.tensor(1.0, dtype=torch.bfloat16)
return x * const * self.param

input = torch.tensor([1.0, 2.0], dtype=torch.bfloat16)
onnx_program = self.export(BfloatModel(), (input,), optimize=False)
initializers = onnx_program.model.graph.initializers.values()
self.assertEqual(len(initializers), 2)
for initializer in initializers:
self.assertEqual(initializer.dtype, ir.DataType.BFLOAT16)
self.assertEqual(onnx_program.model.graph.inputs[0].dtype, ir.DataType.BFLOAT16)
self.assertEqual(
onnx_program.model.graph.outputs[0].dtype, ir.DataType.BFLOAT16
)

def test_export_with_logging_logger(self):
logger = logging.getLogger(__name__)
Expand Down
Loading
0