-
Notifications
You must be signed in to change notification settings - Fork 22
[Dispatch] use dispatch replace getitem, setitem, delitem and bool
#198
[Dispatch] use dispatch replace getitem, setitem, delitem and bool
#198
Conversation
|
Thanks for your contribution! |
| self.value = val_list | ||
|
|
||
| def get_value(self): | ||
| return [self[i].get_value() for i in range(len(self))] |
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.
为了方便,这里就不要改了
def __getitem__(self, idx): # 看情况是只给容器加还是 VariableBase 加
return self.getitem(idx)与 getattr 不同,getattr 只要有 . 就会进入,很容易出问题,但 __getitem__ 不会
| def getitem(self, key): | ||
| return self.graph.call_tensor_method( | ||
| '__getitem__', | ||
| 'getitem', |
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.
这里为什么要改?这样还会对吗?
| return self.__repr__() | ||
|
|
||
| def __getitem__(self, item): | ||
| # TODO: Remove this function after we use builtin dispatcher instead |
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.
这个函数不一定能删吧,这里只是我早期认为可以直接替换掉,实际上可能不是这样
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.
#182 我忘记加 binary op、unary op 相关的了,可以在 test_14_operators 加一下 operator.add(x, y) 这类的
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.
需不需要把list那些也移动到test_14_operators, 比如test_04_list里的list_getitem
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.
可以的
getitem, setitem, delitem and bool
getitem, setitem, delitem and boolgetitem, setitem, delitem and bool
| operator.getitem, | ||
| ( | ||
| "VariableBase | TensorVariable | ListVariable | TupleVariable | DictVariable", | ||
| "int | str | TensorVariable", |
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.
有没有可能是 slice?还有 tuple?
- slice:
a[1:10:3] - tuple:
a[10, 11]
还有其他类型数据可不可以呢?如果都可以的话这里只加这几种类型是有问题的
Co-authored-by: Nyakku Shigure <sigure.qaq@gmail.com>
|
单测的内容我会最后一起整理 |
SigureMo
left a comment
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.
主体逻辑看起来是没啥问题了
| operator.getitem, | ||
| ( | ||
| "VariableBase | TensorVariable | ContainerVariable", | ||
| "int | str | TensorVariable | slice", |
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.
这里 TensorVariable 是不是会出问题呢?现在是不是没有相关的 case,这个问题算是一个遗留问题,和 66 行的 getattr 应该算同一个问题,在 BINARY_SUBSCR 里我们直接将 value 取出来传进 getitem 了,所以 tensor1[tensor2] 假如 tensor2 是一个中间变量的话(value 为 None),是会有问题的,这里应该将其 Variable 传入 getitem,并在 getitem 里做取 value 等操作
这个 PR 先不改这个问题吧,可以下个 PR 统一修改下 getitem、getattr 的问题,这个 PR 记录一下 TODO 即可
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.
Done
| def __init__( | ||
| self, | ||
| val_tuple: list[VariableBase], | ||
| val_tuple: list[VariableBase] | tuple[VariableBase], |
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.
这里就不要允许传入 list[VariableBase] 了,直接强制 tuple[VariableBase] 吧,应该没有什么需求是传入 list?
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.
Done
…o replace_magic_method # Conflicts: # sot/opcode_translator/executor/variable_dispatch.py
| Dispatcher.register( | ||
| operator.getitem, | ||
| ( | ||
| "VariableBase | TensorVariable | ContainerVariable", |
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.
这里 VariableBase 已经包含了 TensorVariable | ContainerVariable,所以后面的需要删掉
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.
Done
| def setitem(self, key, value): | ||
| ''' | ||
| why __setitem__ is ok: | ||
| why __setitem__ or setitem is ok: |
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.
注释里 __setitem__ 就不需要了吧
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.
Done
| ) | ||
|
|
||
| if not isinstance(value, VariableBase): | ||
| if isinstance(value, TensorVariable): |
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.
什么情况会传进来 Tensor 呢?对 Tensor get_value 不对吧
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.
test_04的list_setitem_tensor
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.
那也不应该 get_value,这里不应该修改,这是没有支持 SideEffects 导致的,单测先禁掉加 TODO 即可
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.
Done
sot/utils/magic_methods.py
Outdated
| operator.pow: ("__pow__", "__rpow__"), | ||
| operator.rshift: ("__rshift__", "__rrshift__"), | ||
| operator.sub: ("__sub__", "__rsub__"), | ||
| operator.setitem: ("__setitem__", None), |
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.
setitem 不是 binary op 吧,这个是在什么 case 使用到的呢?
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.
已删除
SigureMo
left a comment
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.
LGTM~
2742195759
left a comment
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.
LGTM
operator.getitem->VariableBase/TensorVariable/ListVariable/TupleVariable/DictVariable.__getitem__operator.setitem->VariableBase/TensorVariable/ListVariable/TupleVariable/DictVariable.__setitem__operator.delitem->ListVariable/TupleVariable/DictVariable.__delitem__bool->ConstantVariable.__bool__close #194