Skip to content

[FIX] Fix sanitizer handling of multi-element TensorHandle - #174

Closed
mark14wu wants to merge 2 commits into
mainfrom
fix_create_reshape
Closed

mark14wu wants to merge 2 commits into
mainfrom
fix_create_reshape

Conversation

@mark14wu

@mark14wu mark14wu commented Sep 26, 2025 •

Copy link
Copy Markdown
Collaborator
  • Update _infer_literal_dtype to handle TensorHandle with multiple data elements
  • Verify dtype consistency across all elements in multi-element cases
  • Modify from_value to preserve entire array for multi-element TensorHandle
  • Maintain backward compatibility for single-element cases

This fixes crashes when using tl.interleave and similar operations that produce TensorHandle objects with multiple internal values.

Fixes #144.

- Update _infer_literal_dtype to handle TensorHandle with multiple data elements
- Verify dtype consistency across all elements in multi-element cases
- Modify from_value to preserve entire array for multi-element TensorHandle
- Maintain backward compatibility for single-element cases

This fixes crashes when using `tl.interleave` and similar operations that produce
TensorHandle objects with multiple internal values.
raise ValueError(
f"Unsupported var.data: {var.data} with length more than one!"
)
# Handle TensorHandle with potentially multiple data elements

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which kernel and line will trigger this branch? It's quite weird to me. And var.data should have a single type

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

x = tl.interleave(x_low_bits, x_high_bits)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And var.data should have a single type

Line 1007 to 1019 are assertions that make sure all elements in var.data should have one same type.

@mark14wu mark14wu Sep 26, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which kernel and line will trigger this branch? It's quite weird to me. And var.data should have a single type

It's in #144. Specifically, tl.interleave.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still don't understand.

  1. tl.interleave is an api but not a core op. You should wrap join but not interleave.
  2. we shouldn't iterate over all items in a tensor in any ways.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to wrap the join op and other ops that tl.interleave involves without referring to your current code. If not successful, we can discuss tomorrow.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because here you check the type of TensorHandle

I think I got what you mean. Maybe I should raise an error when sanitizer encounters TensorHandle since we literally replaced every TensorHandle with SymbolicExpr.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And create_join is not wrapped correctly. Let me wrap that first.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Jokeren Please see PR #178.

@mark14wu mark14wu closed this Sep 26, 2025
@mark14wu

Copy link
Copy Markdown
Collaborator Author

Closed due to not wrapping create_join correctly.

@mark14wu
mark14wu deleted the fix_create_reshape branch September 26, 2025 01:58
@mark14wu
mark14wu restored the fix_create_reshape branch October 2, 2025 20:35
@mark14wu
mark14wu deleted the fix_create_reshape branch October 2, 2025 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] create_reshape shape inference error

2 participants