-
Notifications
You must be signed in to change notification settings - Fork 74.8k
fix(dtensor): guard against nullptr
from TF_TensorData
in ExtractSmallTensorValue
#96866
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
Conversation
Hi @mihaimaruseac, thank you for your previous feedback in #96866. I've opened this new PR with the same code changes, but with a cleaned-up commit history (now squashed into a single commit to conform with TensorFlow's standards). Appreciate it if you could take a look when you have time. Thanks again! |
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.
It would have been better to keep the same change, as now the import into the internal system will be impacted. git rebase -i
should be used for squashing commits, but LLMs can hardly perform that.
@mihaimaruseac Thanks for the feedback! |
Thanks again for your earlier feedback regarding the commit history. |
Hi @mihaimaruseac , Thank you again for reviewing and merging PR #96429 via the Copybara‑Service—it’s an honor to have made my first contribution to TensorFlow! I’ve just squashed my two commits and force‑pushed on this PR. Could you please take a look and approve again when convenient? Thank you! Also, I noticed that in PR #96429 my three commits were merged into I appreciate your guidance and support! Best regards, |
Hi, #96429 was closed by a merge commit. On master branch there is only the merge commit, your commits are on the merged branch. It is recommended to not edit the PR after the approval, unless really needed (test failures, requested fixes). Remember that the PR is being imported into the internal system and each modification adds additional delays as the new change also needs to be imported and reviewed again. It might happen that the new change is being reviewed by other people, adding more delays as new people also need to get up to date with the history of the change, etc. Please only edit PRs if requested by a reviewer. Don't merge master back into the PR, only rebase if GitHub shows a merge conflict. Right now, because this PR was changed after approval, it needed a new approval here to be imported into the system. I missed that notification, so the PR stalled until today. |
Hi @mihaimaruseac, Thank you so much for the follow-up and re-approval! I appreciate your time and the clear guidance on the review and merge process. I've taken note of the recommendation to avoid modifying PRs post-approval unless necessary, and I’ll be sure to follow that going forward. Looking forward to seeing this merged—thank you again! Best regards, |
Hi @mihaimaruseac , I noticed that the CI failure was caused by a SHA‑256 mismatch error while downloading the
This indicates that the bazel run //:requirements.update or the equivalent lockfile generation, and then commit the updated lock file to resolve the mismatch. Does that approach look good to you? Thanks for your guidance! Best regards, |
I think the actual error to fix is
The dependency hash mismatch should be fixed by a concurrent change (already happening) |
Thanks for pointing out the missing headers flagged by Clang-Tidy. I’ll make the necessary changes and push an update within the next two days. Also, I noticed that these Clang-Tidy issues weren’t visible in the build logs I checked (e.g., Appreciate your time and help! Best regards, |
Actually, no need to change anything, it got fixed internally |
Hi @mihaimaruseac , Thank you for the update! Glad to hear it’s been resolved internally. I’ll leave the PR as is then. Let me know if anything else is needed on my side. Best regards, |
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.
One small change needed, the test file needs a copyright header, please just take it from any other file and update the year as its a new file.
Updates LLVM usage to match [0d5325bb203f](llvm/llvm-project@0d5325bb203f) Reverts changelist 783839015 FUTURE_COPYBARA_INTEGRATE_REVIEW=#96866 from zqw86713:pr96430_ut2 1256fef PiperOrigin-RevId: 783408931
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.
Approving back in with the header change. Request was already reviewed
Thanks, Michael! |
This PR updates test assertions in two XLA C++ test files by replacing `EXPECT_THAT(..., IsOkAndHolds(true)) with ASSERT_THAT(...)`. Rationale: - Consistency: Aligns with other XLA tests, which use ASSERT for pass.Run() calls when subsequent checks depend on successful execution. - Correctness: Ensures test failures are caught immediately, as ASSERT_THAT is fatal and prevents further checks from running on invalid state. FUTURE_COPYBARA_INTEGRATE_REVIEW=#96866 from zqw86713:pr96430_ut2 2fadd84 PiperOrigin-RevId: 783478468
COPYBARA_INTEGRATE_REVIEW=tensorflow#96866 from zqw86713:pr96430_ut2 1256fef PiperOrigin-RevId: 783878611
This PR replaces #96430, which had messy commit history due to local squash and rebase attempts.
The code changes are the same, but now consolidated into a single, clean commit that conforms to TensorFlow’s guidelines.
Summary
Adds a defensive check in
ExtractSmallTensorValue
to handle cases whereTF_TensorData()
may returnnullptr
despite a successfulTFE_TensorHandleResolve()
. This prevents potential segmentation faults when working with invalid, zero-sized, or uninitialized tensors.Also introduces a focused C++ unit test to validate the nullptr handling path. The test uses
Layout::Empty()
to ensure coverage without requiring GPU/TPU hardware, enabling rapid verification across all environments.Local testing:
bazel test //tensorflow/dtensor/... --test_tag_filters=-gpu,-tpu
— All DTensor tests pass on WSL-CPU; full matrix coverage will be validated by CI.
What this PR changes
TF_TensorData(...)
; if it’snullptr
, setINVALID_ARGUMENT
and return early.small_constant_optimization_test
intensorflow/dtensor/cc/BUILD
that asserts the function now returnsnullopt
and the correct error code when givennullptr
. The test relies onLayout::Empty()
to avoid any device-specific setup.TF_INT32
,TF_INT64
,TF_FLOAT
,TF_STRING
.Why this matters
Risk
Low. The patch is a defensive check only; it does not affect behavior for valid tensors.
Recommendation
Safe to merge — improves robustness and now has a self-contained unit-test to prove it.
(Final note for reviewers: see
small_constant_optimization_test.cc
for the minimal reproduction of the null-tensor case.)