Skip to content

Conversation

@laithsakka
Copy link
Contributor

@laithsakka laithsakka commented May 23, 2025

Stack from ghstack (oldest at bottom):

This was added in #119562
the idea in this loop seems to be the following.

    if (TORCH_GUARD_SIZE_OBLIVIOUS(size.sym_eq(1))) {
      // NB: we could short circuit this once needs_reduce is true but there's
      // no point since the reduction function will guard on this anyway
      if (!c10::guard_or_false(size.sym_eq(target), __FILE__, __LINE__)) {
        needs_reduce = true;
      }
    } else {
      if (!size.sym_eq(target).expect_true(__FILE__, __LINE__)) {
        fail();
      }
    }
  1. if we know size ==1
    1.1 : if we know for sure size == target --> no reduce needed.
    1.2 : we know for sure that size != target --> we do reduction.
    1.3: we could not tell if size == target or not --> we do reduction.
  2. if we do now know if size ==1 or not
    we add a runtime assertions that size ==target and we fail at runtime if size is not equal to target.

We could have simplified 1.1 and always do reduction under 1.1, since doing 1.3 without runtime checks implies
that it is safe, but i feel the reason could be perf here? idk.

anyway using TORCH_GUARD_OR_FALSE instead of TORCH_GUARD_SIZE_OBLIVIOUS here is appropriate.
there is really no clear reason for size oblivious reasoning. or for this logic not to apply when size is not size like
size is always >=0 anyway. but bad reasoning can make us not able to infer that although we know its true here.

python test/dynamo/test_misc.py -k test_validate_outputs_unbacked

@pytorch-bot
Copy link

pytorch-bot bot commented May 23, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/154172

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 359e53a with merge base 413664b (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

laithsakka added a commit that referenced this pull request May 23, 2025
ghstack-source-id: 180fa20
Pull Request resolved: #154172
@laithsakka laithsakka marked this pull request as draft May 23, 2025 00:50
@laithsakka laithsakka changed the title remove guard_size_obl from maybe_reduce [WIP] used guard_or_false guard_size_oblivious from maybe_reduce May 23, 2025
@laithsakka laithsakka changed the title [WIP] used guard_or_false guard_size_oblivious from maybe_reduce used guard_or_false guard_size_oblivious from maybe_reduce May 23, 2025
@laithsakka laithsakka marked this pull request as ready for review May 23, 2025 01:03
@laithsakka laithsakka requested a review from bobrenjc93 May 23, 2025 01:08
@laithsakka laithsakka changed the title used guard_or_false guard_size_oblivious from maybe_reduce used guard_or_false instead of guard_size_oblivious inside maybe_reduce May 23, 2025
@laithsakka laithsakka added the topic: not user facing topic category label May 23, 2025
@pytorchmergebot
Copy link
Collaborator

Starting merge as part of PR stack under #154234

2 similar comments
@pytorchmergebot
Copy link
Collaborator

Starting merge as part of PR stack under #154234

@pytorchmergebot
Copy link
Collaborator

Starting merge as part of PR stack under #154234

pytorchmergebot pushed a commit that referenced this pull request May 26, 2025
this was added in #141659, the current change keep the same intention
"i do not want to fail here if i cant tell if the size is zero or not"
i am not familiar enough in the code to know if we need here a runtime check, but looking at current
impl it seems that guard_or_false is appropriate to match current behaviour  and have the same effect of guard_size_oblivious here.
Pull Request resolved: #154234
Approved by: https://github.com/bobrenjc93
ghstack dependencies: #154154, #154164, #154167, #154172
@github-actions github-actions bot deleted the gh/laithsakka/186/head branch June 27, 2025 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants