捷徑

RMSNorm

class torch.nn.RMSNorm(normalized_shape, eps=None, elementwise_affine=True, device=None, dtype=None)[source][source]

對輸入的小批量資料應用均方根層歸一化 (Root Mean Square Layer Normalization)。

此層實作了論文 Root Mean Square Layer Normalization 中描述的運算。

yi=xiRMS(x)γi,whereRMS(x)=ϵ+1ni=1nxi2y_i = \frac{x_i}{\mathrm{RMS}(x)} * \gamma_i, \quad \text{where} \quad \text{RMS}(x) = \sqrt{\epsilon + \frac{1}{n} \sum_{i=1}^{n} x_i^2}

RMS 是在最後 D 個維度上計算的,其中 Dnormalized_shape 的維度。 例如,如果 normalized_shape(3, 5)(一個二維形狀),則 RMS 是在輸入的最後 2 個維度上計算的。

參數
  • normalized_shape ( int list torch.Size) –

    期望輸入的 shape (形狀),來自大小為

    [×normalized_shape[0]×normalized_shape[1]××normalized_shape[1]][* \times \text{normalized\_shape}[0] \times \text{normalized\_shape}[1] \times \ldots \times \text{normalized\_shape}[-1]]

    如果使用單一整數,則會將其視為單例列表,並且此模組將在最後一個維度上進行正規化,該維度的預期大小為該特定大小。

  • eps ( Optional[float]) – 加到分母以確保數值穩定性的值。預設值: torch.finfo(x.dtype).eps()

  • elementwise_affine ( bool) – 一個布林值,當設定為 True 時,此模組具有可學習的逐元素仿射參數,這些參數初始化為 1 (對於權重)。預設值: True

Shape (形狀)
  • Input (輸入): (N,)(N, *)

  • Output (輸出): (N,)(N, *) (與輸入相同的形狀)

Examples (範例)

>>> rms_norm = nn.RMSNorm([2, 3])
>>> input = torch.randn(2, 2, 3)
>>> rms_norm(input)
extra_repr()[source][source]

關於模組的額外資訊。

Return type (回傳類型)

str

forward(x)[source][source]

執行前向傳遞。

Return type (回傳類型)

Tensor

reset_parameters()[source][source]

基於 __init__ 中使用的初始化重置參數。

文件

Access comprehensive developer documentation for PyTorch (存取 PyTorch 的完整開發者文件)

View Docs (檢視文件)

Tutorials (教學)

Get in-depth tutorials for beginners and advanced developers (取得為初學者和進階開發者提供的深入教學)

View Tutorials (檢視教學)

Resources (資源)

Find development resources and get your questions answered (尋找開發資源並獲得問題解答)

View Resources (檢視資源)