-
Notifications
You must be signed in to change notification settings - Fork 341
[Cython] Remove an incorrect check #880
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -197,12 +197,14 @@ cdef class CythonKernelWrapper: | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| tensor = inputs[ins_idx] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ins_idx += 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # TODO(chenggang): remove this check or rewrite by ourselves? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ''' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if isinstance(tensor, torch.Tensor) and tensor._base is not None and not tensor.is_contiguous(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| base_tensor = tensor._base.as_strided(tensor._base.shape, tensor.stride()) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if torch._debug_has_internal_overlap(base_tensor): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| raise ValueError(f"Cannot use an overlapping tensor" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"(shape={tensor.shape}, strides={tensor.stride()}, " | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"overlap={torch._debug_has_internal_overlap(base_tensor)}) as the kernel input") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ''' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+200
to
+207
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Restore the overlapping-tensor guard Commenting out this block lets overlapping views (e.g., results of - '''
- if isinstance(tensor, torch.Tensor) and tensor._base is not None and not tensor.is_contiguous():
- base_tensor = tensor._base.as_strided(tensor._base.shape, tensor.stride())
- if torch._debug_has_internal_overlap(base_tensor):
- raise ValueError(f"Cannot use an overlapping tensor"
- f"(shape={tensor.shape}, strides={tensor.stride()}, "
- f"overlap={torch._debug_has_internal_overlap(base_tensor)}) as the kernel input")
- '''
+ if (
+ isinstance(tensor, torch.Tensor)
+ and tensor._base is not None
+ and not tensor.is_contiguous()
+ ):
+ try:
+ has_overlap = torch._debug_has_internal_overlap(tensor)
+ except RuntimeError as err:
+ raise ValueError(
+ f"Cannot use an overlapping tensor "
+ f"(shape={tensor.shape}, strides={tensor.stride()}) as the kernel input"
+ ) from err
+ if has_overlap:
+ raise ValueError(
+ f"Cannot use an overlapping tensor "
+ f"(shape={tensor.shape}, strides={tensor.stride()}, "
+ f"overlap={has_overlap}) as the kernel input"
+ )📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tensor_list.append(tensor) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Convert tensor pointers to C void pointers for kernel call | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of commenting out this code using a multi-line string, it's better to remove it entirely, along with the now-obsolete
TODOcomment. This improves code clarity and avoids clutter. If the code needs to be restored later, version control history can be used.