-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[Retiarii] Nest ValueChoice
in LayerChoice
and dict/list in ValueChoice
#3508
[Retiarii] Nest ValueChoice
in LayerChoice
and dict/list in ValueChoice
#3508
Conversation
|
||
def __getitem__(self, item): | ||
access = copy.deepcopy(self) | ||
access._accessor.append(item) |
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.
why use append
?
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.
The underlying implementation is to clone the current instance, and append item to "accessor", which records all the history getitem calls. For example, when accessor is [a, b, c]
, the value choice will return vc[a][b][c]
where vc
is the original value choice.
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.
wow, very fancy, supporting multi-level indices. but does choice
in valuechoice support multi-level choice?
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.
I think I checked that. Will throw an exception in case the multi-level choice on any of the candidates does not work.
target = model.get_node_by_name(node.name) | ||
target.update_operation(target.operation.type, {**target.operation.parameters, argname: chosen}) | ||
target.update_operation(target.operation.type, {**target.operation.parameters, argname: chosen_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.
seems you deal with indices of ValueChoice when ValueChoice is used as initialization parameters. what if the indices are used in forward
function?
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.
You can find this case in the tests.
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.
yes, in test you uses valuechoice as a function's parameter. What if it is used naively? for example, param = vc[0] + 0.1
? does it work?
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 added. It works.
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.
haha, lihaile!
@@ -557,7 +547,8 @@ def _handle_inputchoice(self, module): | |||
def _handle_valuechoice(self, module): | |||
return { | |||
'candidates': module.candidates, | |||
'label': module.label | |||
'label': module.label, | |||
'accessor': module._accessor |
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.
Could you explain the idea of accessor?
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.
Please refer to newly-added comments and response to Quanlu.
ValueChoice
in LayerChoice
and dict/list in ValueChoice
ValueChoice
in LayerChoice
and dict/list in ValueChoice
No description provided.