本文簡要介紹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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。