在PyTorch中,“register”是什么意思?

3
我不是在询问用于存储内容的内存位置的寄存器。
我在询问PyTorch文档中“register”一词的用法。
当我阅读有关PyTorch模块的文档时,我多次遇到了“registers,registered”一词的使用。
使用的上下文如下:
1. tensor (Tensor) – buffer to be registered.

2. Submodules assigned in this way will be registered, and will have their parameters converted too when you call to(), etc.

3. Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

4. Registers a backward hook on the module.

5. Registers a forward hook on the module.

.....

“register”一词已经被用于几种方法的名称中。
1. register_backward_hook(hook)
 
2. register_buffer(name, tensor, persistent=True)
 
3. register_forward_hook(hook)
 
4. register_forward_pre_hook(hook)

5. register_parameter(name, param)
 
......

“register programmatically” 的使用是什么意思?

这是否只是在普通英语中表示将名称或信息记录在官方列表上,还是在编程方面有任何特殊意义?

1个回答

2

在PyTorch文档和方法名称中,“register”一词的意思是“将名称或信息记录在官方列表上的行为”。例如,register_backward_hook(hook)会将函数hook添加到其他函数的列表中,这些函数在执行forward传递期间由nn.Module执行。同样地,register_parameter(name, param)会将一个带有namenn.Parameterparam添加到nn.Module可训练参数的列表中。注册可训练参数非常重要,因此PyTorch会知道要将哪些张量传递给优化器,以及要将哪些张量存储为nn.Modulestate_dict的一部分。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接