本文简要介绍python语言中 torch.overrides.wrap_torch_function
的用法。
用法:
torch.overrides.wrap_torch_function(dispatcher)
dispatcher(可调用) -返回传递给函数的 Tensor-likes 的可迭代对象的可调用对象。
使用与
__torch_function__
相关的函数包装给定函数。注意
此装饰器可能会降低代码的性能。通常,将您的代码表达为一系列本身支持 __torch_function__ 的函数就足够了。如果您发现自己处于罕见的情况并非如此,例如如果您正在包装一个低级库并且您还需要它为Tensor-likes 工作,那么这个函数是可用的。
例子
>>> def dispatcher(a): # Must have the same signature as func ... return (a,) >>> @torch.overrides.wrap_torch_function(dispatcher) >>> def func(a): # This will make func dispatchable by __torch_function__ ... return a + 0
参数:
相关用法
- Python PyTorch wrap用法及代码示例
- Python PyTorch wav2vec2_model用法及代码示例
- Python PyTorch weight_norm用法及代码示例
- Python PyTorch where用法及代码示例
- Python PyTorch frexp用法及代码示例
- Python PyTorch jvp用法及代码示例
- Python PyTorch cholesky用法及代码示例
- Python PyTorch vdot用法及代码示例
- Python PyTorch ELU用法及代码示例
- Python PyTorch ScaledDotProduct.__init__用法及代码示例
- Python PyTorch gumbel_softmax用法及代码示例
- Python PyTorch get_tokenizer用法及代码示例
- Python PyTorch saved_tensors_hooks用法及代码示例
- Python PyTorch positive用法及代码示例
- Python PyTorch renorm用法及代码示例
- Python PyTorch AvgPool2d用法及代码示例
- Python PyTorch MaxUnpool3d用法及代码示例
- Python PyTorch Bernoulli用法及代码示例
- Python PyTorch Tensor.unflatten用法及代码示例
- Python PyTorch Sigmoid用法及代码示例
- Python PyTorch Tensor.register_hook用法及代码示例
- Python PyTorch ShardedEmbeddingBagCollection.named_parameters用法及代码示例
- Python PyTorch sqrt用法及代码示例
- Python PyTorch PackageImporter.id用法及代码示例
- Python PyTorch column_stack用法及代码示例
注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torch.overrides.wrap_torch_function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。