Skip to content
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

Handle an input spec with first dim equal to zero #970

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions fx2ait/fx2ait/tensor_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,9 @@ def find_batch_size_dim(cls, inputs: Any) -> []:
if len(shape) < 2:
# By pass for rank-1 tensors. MRS model has rank-1 tensor carry no batch_size info
continue
if shape[0] == 0:
# We expect that 1 is the minimum batch size value anyways.
continue
# Dedup shape value for single tensor
first_dims.add(shape[0])
seen_dims = set()
Expand Down
18 changes: 18 additions & 0 deletions fx2ait/fx2ait/test/test_tensor_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,21 @@ def test_input_with_no_bs_tensor(self):
),
specs[3],
)

def test_input_with_first_dim_zero(self):
inputs = [
torch.empty([10, 8643], dtype=torch.float16),
torch.empty([0, 8643], dtype=torch.float16),
]

specs = TensorSpec.from_input_list_with_batch_size(inputs, 32)

self.assertEqual(
[
TensorSpec(
[IntVar([1, 32], "batch_size"), IntImm(8643)], torch.float16
),
TensorSpec([IntImm(0), IntImm(8643)], torch.float16),
],
specs,
)
Loading