AI 모델 자체(가중치)가 아니라, 모델에 대한 정보를 담고 있는 데이터.
"모델의 신분증 + 사용 설명서" 같은 것.
모델 아키텍처 자체를 정의하는 핵심 파일.
같은 정보가 들어있다.
{
"architectures": ["LlamaForCausalLM"],
"hidden_size": 4096,
"num_hidden_layers": 32,
"num_attention_heads": 32,
"vocab_size": 32000,
"max_position_embeddings": 4096,
"torch_dtype": "bfloat16"
}
| 필드 | 의미 |
|---|---|
architectures | 어떤 모델 클래스인지 |
hidden_size | 토큰 임베딩 차원 |
num_hidden_layers | Transformer block 개수 |
num_attention_heads | Attention head 수 |
intermediate_size | FFN 내부 확장 차원 |
vocab_size | vocabulary 크기 |
max_position_embeddings | 최대 context 길이 |
rope_theta | RoPE scaling 관련 |
torch_dtype | fp16/bf16/fp32 등 |
bos_token_id | 문장 시작 토큰 |
eos_token_id | 종료 토큰 |
실제로 inference framework(vLLM, transformers, TGI 등)가
이 파일을 읽고 모델 구조를 생성한다.
weight 파일만으로는 모델 생성 불가능
config.json이 있어야 tensor shape를 맞춰 로딩 가능
토크나이저 전체 정의다.
어떤 단어를 어떤 token id로 매핑할지
BPE merge 규칙
sentencepiece vocabulary
pretokenizer 규칙
등이 전부 들어있다.
{
"version": "1.0",
"truncation": null,
"padding": null,
"model": {
"type": "BPE",
"vocab": {
"hello": 1234,
"world": 5678
},
"merges": [
"h e",
"he llo"
]
}
}
| 역할 | 설명 |
|---|---|
| vocab | token ↔ id 매핑 |
| merges | BPE 병합 규칙 |
| normalizer | unicode normalize |
| pre_tokenizer | 공백 기준 분리 등 |
| decoder | token → text 복원 |
"text" -> [tokens]
[tokens] -> "text"
변환 로직 전체가 들어있다.
토크나이저 동작 옵션입니다.
tokenizer.json 자체는 "토큰화 규칙",
tokenizer_config.json은 "사용 정책" 느낌이다.
{
"model_max_length": 32768,
"padding_side": "left",
"truncation_side": "right",
"bos_token": "<s>",
"eos_token": "</s>",
"clean_up_tokenization_spaces": true
}
| 필드 | 의미 |
|---|---|
model_max_length | 최대 입력 길이 |
padding_side | left/right padding |
truncation_side | 어디 자를지 |
chat_template | chat prompt template |
bos_token | 시작 토큰 |
eos_token | 종료 토큰 |
"chat_template" 예시:
{% for message in messages %}
<|im_start|>{{message.role}}
{{message.content}}
<|im_end|>
{% endfor %}
이게 OpenAI 스타일, ChatML, Llama chat, Qwen chat
등의 prompt formatting을 정의한다.
생성(inference) 기본 파라미터다.
{
"max_new_tokens": 1024,
"temperature": 0.7,
"top_p": 0.9,
"do_sample": true,
"repetition_penalty": 1.1
}
model.generate(...)
할 때 기본값으로 사용됩니다.
| 필드 | 의미 |
|---|---|
temperature | randomness |
top_p | nucleus sampling |
top_k | 상위 k개 제한 |
max_new_tokens | 최대 생성 길이 |
repetition_penalty | 반복 억제 |
do_sample | sampling 여부 |
num_beams | beam search 수 |
이 파일은 없어도 inference 가 가능하다.
단지 default generation behavior 를 제공할 뿐이다.
특수 토큰 정의 파일입니다.
예시:
{
"bos_token": "<s>",
"eos_token": "</s>",
"unk_token": "<unk>",
"pad_token": "<pad>"
}
| 토큰 | 의미 |
|---|---|
bos_token | beginning of sequence |
eos_token | end of sequence |
pad_token | padding |
unk_token | unknown token |
sep_token | 문장 구분 |
cls_token | classification token |
실제 tokenizer 내부 id와 연결된다.
tokenizer.eos_token_id 같은 값이 여기 기반으로 결정된다.
보통:
AutoTokenizer.from_pretrained(...)
AutoModelForCausalLM.from_pretrained(...)
하면 내부적으로
모델 로딩
↓
config.json
↓
weight tensor 로드
↓
tokenizer 로딩
↓
tokenizer.json
↓
tokenizer_config.json
↓
special_tokens_map.json
순으로 읽는다.
실제 디렉토리 예시
model/
├── config.json
├── generation_config.json
├── tokenizer.json
├── tokenizer_config.json
├── special_tokens_map.json
├── model.safetensors
├── model-00001-of-00004.safetensors
└── ...
핵심 차이 요약
| 파일 | 역할 |
|---|---|
config.json | 모델 구조 |
tokenizer.json | 토큰화 규칙 |
tokenizer_config.json | 토크나이저 동작 정책 |
generation_config.json | 생성 기본 옵션 |
special_tokens_map.json | 특수 토큰 정의 |
한 줄로 정리하면:
config.json → "모델 뼈대"
tokenizer.json → "문자 ↔ 토큰 변환기"
tokenizer_config.json → "토크나이저 사용 방식"
generation_config → "생성 스타일 기본값"
special_tokens_map → "특수 토큰 정의"