pytorch
3c5a825f - [AOTAutograd] Fix is-duplicate check in de-dup guard logic (#98932)

Commit
1 year ago
[AOTAutograd] Fix is-duplicate check in de-dup guard logic (#98932) **Context** The existing check to see if an arg is duped is `if dupe_arg_pos != kept_pos:`. However, this incorrectly considers every arg after a true duped arg to also be a duped arg. Consider `flat_args = [a, b, b, c]`, where indices `1` and `2` are duped. - `add_dupe_map = {0: 0, 1: 1, 2: 1, 3: 2}` - For `dupe_arg_pos=2, kept_pos=1`, `2 != 1`, so the check correctly identifies the second `b` to be a duped arg. - For `dupe_arg_pos=3, kept_pos=2`, `3 != 2`, so the check incorrectly identifies the `c` to be a duped arg. Indeed, if there were more args like `[a, b, b, c, d, e, ...]`, every arg after the second `b` will be considered a duped arg since its `kept_pos` will always be 1 lower than its `dupe_arg_pos`. **Overview** This PR changes `add_dupe_map` to be implemented as a `List[int]`, where the list index implicitly represents the `dupe_arg_pos` and the list element represents the `kept_pos`. We use a list to have stable in-order iteration and because we know the keys to be in `{0, 1, ..., len(flat_args) - 1}`. With `add_dupe_map` as a list, the `is_dupe_arg` condition is whether the entry in `add_dupe_map` shows a new not-yet-seen index in the iteration. One way to do this is to count the number of unique args so far and compare against that. This closes https://github.com/pytorch/pytorch/issues/98883, where now the guards change from ``` GUARDS ___guarded_code.valid and ___check_type_id(L['self'], 93996836333040) and ___check_obj_id(L['self'], 140119034997536) and not ___are_deterministic_algorithms_enabled() and ___check_tensors(L['x']) and L['self']._buf is L['self']._buf_module._buf and L['self']._buf_module._buf is L['self']._param ``` to without the final incorrect `L['self']._buf_module._buf is L['self']._param` guard. Pull Request resolved: https://github.com/pytorch/pytorch/pull/98932 Approved by: https://github.com/ezyang
Author
Committer
Parents
Loading