本文简要介绍python语言中 torch.fx.wrap
的用法。
用法:
torch.fx.wrap(fn_or_name)
fn_or_name(联盟[str,可调用]) -调用时插入到图中的全局函数的函数或名称
可以在模块级范围调用此函数,将fn_or_name注册为“leaf function”。 “leaf function” 将在 FX 跟踪中保留为 CallFunction 节点,而不是通过以下方式进行跟踪:
# foo/bar/baz.py def my_custom_function(x, y): return x * x + y * y torch.fx.wrap('my_custom_function') def fn_to_be_traced(x, y): # When symbolic tracing, the below call to my_custom_function will be inserted into # the graph rather than tracing it. return my_custom_function(x, y)
此函数也可以等效地用作装饰器:
# foo/bar/baz.py @torch.fx.wrap def my_custom_function(x, y): return x * x + y * y
包装函数可以被认为是“leaf function”,类似于“leaf modules” 的概念,也就是说,它们是作为调用留在FX 跟踪中而不是通过跟踪的函数。
注意
保证此 API 的向后兼容性。
参数:
相关用法
- Python PyTorch wrap_torch_function用法及代码示例
- 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.fx.wrap。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。