I am trying to implement a mechanism which needs to be detected when parameters are updated, there are three ways to implement it:
- use
register_backward_hook
(problematic, it will not work sometimes, proved by experiment and statement in doc. - use
register_hook
on every parameter (usable, but will not be executed right after parameter update) - find a way to hook onto inplace operations such as
add_
,copy_
andaddcdiv_
, but I am not sure whether inplace operations are gauranteed to be used when you want to update a parameter (using param = some_modify_func(param) is possiple). And is there any clean way to hook onto them whithout creating a wrapper and wrap parameters inside ?
What’s your suggestion? Thanks in advance!