当前位置: 首页> 健康> 养生 > 快速建网站工具_智慧团建pc端官网_seo的内容有哪些_达州seo

快速建网站工具_智慧团建pc端官网_seo的内容有哪些_达州seo

时间:2025/7/11 4:12:52来源:https://blog.csdn.net/scar2016/article/details/144864711 浏览次数:0次
快速建网站工具_智慧团建pc端官网_seo的内容有哪些_达州seo
  • 当我们查看 Pytorch 里面源代码时候,发现无法查看里面的源码,比如我们想查看Pytorch中的如下代码:
torch.nn.functional._canonical_mask
  • 方法: 引入inspect方法查看源码
import torch
import inspect# 查找并查看 _canonical_mask 函数的源码
print(inspect.getsource(torch.nn.functional._canonical_mask))
  • 结果:
def _canonical_mask(mask: Optional[Tensor],mask_name: str,other_type: Optional[DType],other_name: str,target_type: DType,check_other: bool = True,
) -> Optional[Tensor]:if mask is not None:_mask_dtype = mask.dtype_mask_is_float = torch.is_floating_point(mask)if _mask_dtype != torch.bool and not _mask_is_float:raise AssertionError(f"only bool and floating types of {mask_name} are supported")if check_other and other_type is not None:if _mask_dtype != other_type:warnings.warn(f"Support for mismatched {mask_name} and {other_name} ""is deprecated. Use same type for both instead.")if not _mask_is_float:mask = (torch.zeros_like(mask, dtype=target_type).masked_fill_(mask, float("-inf")))return mask
  • github 查看:
    github链接
def _canonical_mask(mask: Optional[Tensor],mask_name: str,other_type: Optional[DType],other_name: str,target_type: DType,check_other: bool = True,
) -> Optional[Tensor]:if mask is not None:_mask_dtype = mask.dtype_mask_is_float = torch.is_floating_point(mask)if _mask_dtype != torch.bool and not _mask_is_float:raise AssertionError(f"only bool and floating types of {mask_name} are supported")if check_other and other_type is not None:if _mask_dtype != other_type:warnings.warn(f"Support for mismatched {mask_name} and {other_name} ""is deprecated. Use same type for both instead.")if not _mask_is_float:mask = torch.zeros_like(mask, dtype=target_type).masked_fill_(mask, float("-inf"))return mask

在这里插入图片描述

  • 两种方法结果一样,有利于后续代码复现,非常方便!!!
关键字:快速建网站工具_智慧团建pc端官网_seo的内容有哪些_达州seo

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: