NLP

[LLM paper review] LLaMA : Open and Efficient Foundation Language Models 리뷰

joannekim0420 2024. 1. 22. 15:38
728x90

제가 생각한 핵심만 요약한 글입니다. 더 자세한 실험 결과나 레퍼런스는 paper를 참고

※ Contribuition

1. Trained on only open source data

2. Smaller models trained longer with bigger tokens

3. Inference capable on a single GPU

1. INTRODUCTION 요약

  1. 근래에는 단순하게 more parameters will elad to better performance. 로 승부를 보는 추세였는데, (Training Compute-Optimal Large Language Models) 논문에 따르면 for a given budget , the best performances are not achieved by the largest models, but by smaller models trained on more data. 라고 주장함.

2. 하지만 위 논문도 inference budget을 고려하진 않았고, llama 저자들은 선호하는 모델이 가장 빠르게 train할 수 있는 모델이 아닌 가장 빠르게 inference 할 수 있는 모델이라고 생각함. 결론적으로 이러한 모델이 a smaller one trained longer will ultimately be cheaper at inference 임.

3. 거대모델인 Chinchilla, PaLM, GPT-3 와는 다르게 오로지 publicly available data 로만 트레이닝 하고, 다른 LLM 에 비하면 상대적으로 적은 파라미터 수로 performance를 이기거나 따라 잡는다.

2. APPROACH

2.1 Pretraining Data

1. 사용한 데이터 proportion을 정리했는데, 자세히 보면 disk size가 2배 정도 차이나는 wikipedia와 github 인데도 sampling prop 은 비슷함. 각각 전체 데이터의 얼마만큼씩 따로 쓴거 같음. 그리고 그 전체 데이터가 BPE(Byte pair encoding) 알고리즘으로 tokenization 했을 때, 1.4T tokens 만큼 된다.

2. 대부분은 1번씩만 데이터를 본다면, wikipedia랑 books만 2번씩 본다.

2.2 Architecture

Pre-normalization[GPT3/GPT2]

(보충 설명)

1. 원래 트랜스포머에서는 normalization layer가 residual block 사이에 있었는데, 이는 large gradients near the output layer 가 발생함. (→ 이를 해결하기 위한 방법으로는 learning rate warm-up stage를 실행하기도 함)

2. 위와 같은 문제를 해결하고 graident initialization을 좀 더 잘하게 하기 위해 pre-layer normalization을 residual block 안에 사용.

3. pre ln 은 post ln 보다 안정적이고 성능도 좋은 faster training 가능함.

SwiGLU activation function[PaLM]

SwiGLU 는 심플하게 보면, Swish acitivation function 과 GLU 를 합친 것.

▷ SWISH activation function 은 또 어디서 왔나,,?

(참고: https://blog.paperspace.com/swish-activation-function/)

https://blog.paperspace.com/swish-activation-function/

→ SILU activation function 의 연장선. "Sigmoid-Weighted Linear Units for Neural Network Function Approximation in Reinforcement Learning"

SILU 는 f(x)=x∗sigmoid(x) 인데 여기서 학습가능한 파라미터 β 를 추가하면, f(x)=x∗sigmoid(βx) swish activation 이 된다.

1. Swish is a smooth continuous function, unlike ReLU which is a piecewise linear function

→ ReLU 와 다르게 continuous function이라 모든 구간에서 미분가능하고 연속된 도함수를 갖는다.

2. 음수 이하의 값을 모두 0으로 해버리는 ReLU function 과 달리 swish 는 작은 값이라도 전달되도록 한다.

3. (self-gated) trainable한 매개변수 β 는 활성화 함수를 더 잘 조정하여 정보 전파를 극대화하고 부드러운 그래디언트를 유도하여 최적화가 쉽게한다. 즉, 입력의 정보량 스스로 조절하기 때문에 self-gating.
→ 더 나은 generalization 과 빠른 학습이 가능

4. 그러나 computationally expensive 해서 cost-efficient 한 ReLU function을 완전히 대체하지 못한....

 

GLU는 우리가 흔히 아는 GatedLinearUnits

import torch.nn as nn
import torch.nn.functional as F

class SwiGLU(nn.Module):
    def forward(self, x):
        x, gate = x.chunk(2, dim=-1) 
        return F.silu(gate) * x 

class Swish(nn.Module):
    def __init__(self):
        super().__init__()
        self.beta = nn.Parameter(torch.Tensor([1.]))

    def forward(self, x):
        return x * F.sigmoid(self.beta * x)

 

Rotary Embeddings[GPT Neo]