评价此页

LazyLinear#

class torch.nn.LazyLinear(out_features, bias=True, device=None, dtype=None)[source]#

一个 torch.nn.Linear 模块,其中 in_features 是推断出来的。

在此模块中,weightbiastorch.nn.UninitializedParameter 类的实例。它们将在首次调用 forward 后进行初始化,然后该模块将变为一个常规的 torch.nn.Linear 模块。 Linearin_features 参数将从 input.shape[-1] 推断。

有关懒惰模块及其限制的更多文档,请参阅 torch.nn.modules.lazy.LazyModuleMixin

参数
  • out_features (int) – 每个输出样本的大小

  • bias (UninitializedParameter) – 如果设置为 False,则该层将不会学习加性偏置。默认为 True

变量
  • weight (torch.nn.parameter.UninitializedParameter) – 模块的可学习权重,形状为 (out_features,in_features)(\text{out\_features}, \text{in\_features})。值从 U(k,k)\mathcal{U}(-\sqrt{k}, \sqrt{k}) 进行初始化,其中 k=1in_featuresk = \frac{1}{\text{in\_features}}

  • bias (torch.nn.parameter.UninitializedParameter) – 模块的可学习偏置,形状为 (out_features)(\text{out\_features})。如果 biasTrue,则值从 U(k,k)\mathcal{U}(-\sqrt{k}, \sqrt{k}) 进行初始化,其中 k=1in_featuresk = \frac{1}{\text{in\_features}}

cls_to_become[源代码]#

的别名: Linear