Full Code of onlybooks/llm for AI

main f64a19066504 cached
16 files
885.1 KB
290.8k tokens
12 symbols
1 requests
Download .txt
Showing preview only (948K chars total). Download the full file or copy to clipboard to get everything.
Repository: onlybooks/llm
Branch: main
Commit: f64a19066504
Files: 16
Total size: 885.1 KB

Directory structure:
gitextract_axs9sb0j/

├── 02장/
│   └── chapter_2_transformer_with_code.ipynb
├── 03장/
│   └── chapter_3.ipynb
├── 05장/
│   └── chapter_5.ipynb
├── 06장/
│   ├── api_request_parallel_processor.py
│   ├── chapter_6.ipynb
│   └── utils.py
├── 07장/
│   └── chapter_7.ipynb
├── 08장/
│   └── chapter_8.ipynb
├── 09장/
│   └── chapter_9.ipynb
├── 10장/
│   └── chapter_10.ipynb
├── 11장/
│   └── chapter_11.ipynb
├── 12장/
│   └── chapter_12.ipynb
├── 14장/
│   └── chapter_14.ipynb
├── 15장/
│   └── chapter_15.ipynb
├── 16장/
│   └── chapter_16.ipynb
└── README.md

================================================
FILE CONTENTS
================================================

================================================
FILE: 02장/chapter_2_transformer_with_code.ipynb
================================================
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "mr7FmYqAi6y2"
   },
   "source": [
    "## 예제 2.1 토큰화 코드"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "f3K1on7SMnXj",
    "outputId": "a4b9cbbd-279d-4f1b-a0f8-fc5e32bb70db"
   },
   "outputs": [],
   "source": [
    "# 띄어쓰기 단위로 분리\n",
    "input_text = \"나는 최근 파리 여행을 다녀왔다\"\n",
    "input_text_list = input_text.split()\n",
    "print(\"input_text_list: \", input_text_list)\n",
    "\n",
    "# 토큰 -> 아이디 딕셔너리와 아이디 -> 토큰 딕셔너리 만들기\n",
    "str2idx = {word:idx for idx, word in enumerate(input_text_list)}\n",
    "idx2str = {idx:word for idx, word in enumerate(input_text_list)}\n",
    "print(\"str2idx: \", str2idx)\n",
    "print(\"idx2str: \", idx2str)\n",
    "\n",
    "# 토큰을 토큰 아이디로 변환\n",
    "input_ids = [str2idx[word] for word in input_text_list]\n",
    "print(\"input_ids: \", input_ids)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "CX95psBGjELL"
   },
   "source": [
    "## 예제 2.2 토큰 아이디에서 벡터로 변환"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "dCKTtOt9NvFA",
    "outputId": "66e59720-871a-475f-e966-9a1fc31e37a9"
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "import torch.nn as nn\n",
    "\n",
    "embedding_dim = 16\n",
    "embed_layer = nn.Embedding(len(str2idx), embedding_dim)\n",
    "\n",
    "input_embeddings = embed_layer(torch.tensor(input_ids)) # (5, 16)\n",
    "input_embeddings = input_embeddings.unsqueeze(0) # (1, 5, 16)\n",
    "input_embeddings.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "FwClYMSSjLjp"
   },
   "source": [
    "## 예제 2.3 절대적 위치 인코딩"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "ws1A-ALkjLWH",
    "outputId": "a83d2e96-8bad-461c-bc7f-ac59e65a2fcf"
   },
   "outputs": [],
   "source": [
    "embedding_dim = 16\n",
    "max_position = 12\n",
    "# 토큰 임베딩 층 생성\n",
    "embed_layer = nn.Embedding(len(str2idx), embedding_dim)\n",
    "# 위치 인코딩 층 생성\n",
    "position_embed_layer = nn.Embedding(max_position, embedding_dim)\n",
    "\n",
    "position_ids = torch.arange(len(input_ids), dtype=torch.long).unsqueeze(0)\n",
    "position_encodings = position_embed_layer(position_ids)\n",
    "token_embeddings = embed_layer(torch.tensor(input_ids)) # (5, 16)\n",
    "token_embeddings = token_embeddings.unsqueeze(0) # (1, 5, 16)\n",
    "# 토큰 임베딩과 위치 인코딩을 더해 최종 입력 임베딩 생성\n",
    "input_embeddings = token_embeddings + position_encodings\n",
    "input_embeddings.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "0MBYHKRMkCDs"
   },
   "source": [
    "## 예제 2.4 쿼리, 키, 값 벡터를 만드는 nn.Linear 층"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "Rse5Xy6_jhok"
   },
   "outputs": [],
   "source": [
    "head_dim = 16\n",
    "\n",
    "# 쿼리, 키, 값을 계산하기 위한 변환\n",
    "weight_q = nn.Linear(embedding_dim, head_dim)\n",
    "weight_k = nn.Linear(embedding_dim, head_dim)\n",
    "weight_v = nn.Linear(embedding_dim, head_dim)\n",
    "# 변환 수행\n",
    "querys = weight_q(input_embeddings) # (1, 5, 16)\n",
    "keys = weight_k(input_embeddings) # (1, 5, 16)\n",
    "values = weight_v(input_embeddings) # (1, 5, 16)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "wfitct-lkSP2"
   },
   "source": [
    "## 예제 2.5. 스케일 점곱 방식의 어텐션"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "nftEA3lFkSwl"
   },
   "outputs": [],
   "source": [
    "from math import sqrt\n",
    "import torch.nn.functional as F\n",
    "\n",
    "def compute_attention(querys, keys, values, is_causal=False):\n",
    "\tdim_k = querys.size(-1) # 16\n",
    "\tscores = querys @ keys.transpose(-2, -1) / sqrt(dim_k)\n",
    "\tweights = F.softmax(scores, dim=-1)\n",
    "\treturn weights @ values"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "CzHY8tvlkiTl"
   },
   "source": [
    "## 예제 2.6. 어텐션 연산의 입력과 출력"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "h4evxbjRkfIi",
    "outputId": "44629901-1451-4491-a86b-25abc8a3e858"
   },
   "outputs": [],
   "source": [
    "print(\"원본 입력 형태: \", input_embeddings.shape)\n",
    "\n",
    "after_attention_embeddings = compute_attention(querys, keys, values)\n",
    "\n",
    "print(\"어텐션 적용 후 형태: \", after_attention_embeddings.shape)\n",
    "# 원본 입력 형태:  torch.Size([1, 5, 16])\n",
    "# 어텐션 적용 후 형태:  torch.Size([1, 5, 16])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "OKv4X9rsknXs"
   },
   "source": [
    "## 예제 2.7. 어텐션 연산을 수행하는 AttentionHead 클래스"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "3HWTZ4jukn5p"
   },
   "outputs": [],
   "source": [
    "class AttentionHead(nn.Module):\n",
    "  def __init__(self, token_embed_dim, head_dim, is_causal=False):\n",
    "    super().__init__()\n",
    "    self.is_causal = is_causal\n",
    "    self.weight_q = nn.Linear(token_embed_dim, head_dim) # 쿼리 벡터 생성을 위한 선형 층\n",
    "    self.weight_k = nn.Linear(token_embed_dim, head_dim) # 키 벡터 생성을 위한 선형 층\n",
    "    self.weight_v = nn.Linear(token_embed_dim, head_dim) # 값 벡터 생성을 위한 선형 층\n",
    "\n",
    "  def forward(self, querys, keys, values):\n",
    "    outputs = compute_attention(\n",
    "        self.weight_q(querys),  # 쿼리 벡터\n",
    "        self.weight_k(keys),    # 키 벡터\n",
    "        self.weight_v(values),  # 값 벡터\n",
    "        is_causal=self.is_causal\n",
    "    )\n",
    "    return outputs\n",
    "\n",
    "attention_head = AttentionHead(embedding_dim, embedding_dim)\n",
    "after_attention_embeddings = attention_head(input_embeddings, input_embeddings, input_embeddings)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "30IXVnNElE2O"
   },
   "source": [
    "## 예제 2.8. 멀티 헤드 어텐션 구현"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "a-qTbFVMlFND",
    "outputId": "cd7a3848-11ea-4e8e-cee4-8110592fd9a0"
   },
   "outputs": [],
   "source": [
    "class MultiheadAttention(nn.Module):\n",
    "  def __init__(self, token_embed_dim, d_model, n_head, is_causal=False):\n",
    "    super().__init__()\n",
    "    self.n_head = n_head\n",
    "    self.is_causal = is_causal\n",
    "    self.weight_q = nn.Linear(token_embed_dim, d_model)\n",
    "    self.weight_k = nn.Linear(token_embed_dim, d_model)\n",
    "    self.weight_v = nn.Linear(token_embed_dim, d_model)\n",
    "    self.concat_linear = nn.Linear(d_model, d_model)\n",
    "\n",
    "  def forward(self, querys, keys, values):\n",
    "    B, T, C = querys.size()\n",
    "    querys = self.weight_q(querys).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)\n",
    "    keys = self.weight_k(keys).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)\n",
    "    values = self.weight_v(values).view(B, T, self.n_head, C // self.n_head).transpose(1, 2)\n",
    "    attention = compute_attention(querys, keys, values, self.is_causal)\n",
    "    output = attention.transpose(1, 2).contiguous().view(B, T, C)\n",
    "    output = self.concat_linear(output)\n",
    "    return output\n",
    "\n",
    "n_head = 4\n",
    "mh_attention = MultiheadAttention(embedding_dim, embedding_dim, n_head)\n",
    "after_attention_embeddings = mh_attention(input_embeddings, input_embeddings, input_embeddings)\n",
    "after_attention_embeddings.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "iWtHyqa_mAtB"
   },
   "source": [
    "## 예제 2.9. 층 정규화 코드"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "ikXwtWFBl5zw",
    "outputId": "93392ff7-2e59-4ac0-b817-615858508a3e"
   },
   "outputs": [],
   "source": [
    "norm = nn.LayerNorm(embedding_dim)\n",
    "norm_x = norm(input_embeddings)\n",
    "norm_x.shape # torch.Size([1, 5, 16])\n",
    "\n",
    "norm_x.mean(dim=-1).data, norm_x.std(dim=-1).data\n",
    "\n",
    "# (tensor([[ 2.2352e-08, -1.1176e-08, -7.4506e-09, -3.9116e-08, -1.8626e-08]]),\n",
    "#  tensor([[1.0328, 1.0328, 1.0328, 1.0328, 1.0328]]))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "nkeIvwCYnSOs"
   },
   "source": [
    "## 예제 2.10. 피드 포워드 층 코드"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "3e9702XvnSrT"
   },
   "outputs": [],
   "source": [
    "class PreLayerNormFeedForward(nn.Module):\n",
    "  def __init__(self, d_model, dim_feedforward, dropout):\n",
    "    super().__init__()\n",
    "    self.linear1 = nn.Linear(d_model, dim_feedforward) # 선형 층 1\n",
    "    self.linear2 = nn.Linear(dim_feedforward, d_model) # 선형 층 2\n",
    "    self.dropout1 = nn.Dropout(dropout) # 드랍아웃 층 1\n",
    "    self.dropout2 = nn.Dropout(dropout) # 드랍아웃 층 2\n",
    "    self.activation = nn.GELU() # 활성 함수\n",
    "    self.norm = nn.LayerNorm(d_model) # 층 정규화\n",
    "\n",
    "  def forward(self, src):\n",
    "    x = self.norm(src)\n",
    "    x = x + self.linear2(self.dropout1(self.activation(self.linear1(x))))\n",
    "    x = self.dropout2(x)\n",
    "    return x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "qq3eJqRInWWS"
   },
   "source": [
    "## 예제 2.11. 인코더 층"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "QNCFpdVknUVa"
   },
   "outputs": [],
   "source": [
    "class TransformerEncoderLayer(nn.Module):\n",
    "  def __init__(self, d_model, nhead, dim_feedforward, dropout):\n",
    "    super().__init__()\n",
    "    self.attn = MultiheadAttention(d_model, d_model, nhead) # 멀티 헤드 어텐션 클래스\n",
    "    self.norm1 = nn.LayerNorm(d_model) # 층 정규화\n",
    "    self.dropout1 = nn.Dropout(dropout) # 드랍아웃\n",
    "    self.feed_forward = PreLayerNormFeedForward(d_model, dim_feedforward, dropout) # 피드포워드\n",
    "\n",
    "  def forward(self, src):\n",
    "    norm_x = self.norm1(src)\n",
    "    attn_output = self.attn(norm_x, norm_x, norm_x)\n",
    "    x = src + self.dropout1(attn_output) # 잔차 연결\n",
    "\n",
    "    # 피드 포워드\n",
    "    x = self.feed_forward(x)\n",
    "    return x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "W7acyE0lnc5L"
   },
   "source": [
    "## 예제 2.12. 인코더 구현"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "Ty7TTF55nYDr"
   },
   "outputs": [],
   "source": [
    "import copy\n",
    "def get_clones(module, N):\n",
    "  return nn.ModuleList([copy.deepcopy(module) for i in range(N)])\n",
    "\n",
    "class TransformerEncoder(nn.Module):\n",
    "  def __init__(self, encoder_layer, num_layers):\n",
    "    super().__init__()\n",
    "    self.layers = get_clones(encoder_layer, num_layers)\n",
    "    self.num_layers = num_layers\n",
    "    self.norm = norm\n",
    "\n",
    "  def forward(self, src):\n",
    "    output = src\n",
    "    for mod in self.layers:\n",
    "        output = mod(output)\n",
    "    return output"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "2dJpZJGrnhMI"
   },
   "source": [
    "## 예제 2.13. 디코더에서 어텐션 연산(마스크 어텐션)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "y2nBX5monelI"
   },
   "outputs": [],
   "source": [
    "def compute_attention(querys, keys, values, is_causal=False):\n",
    "\tdim_k = querys.size(-1) # 16\n",
    "\tscores = querys @ keys.transpose(-2, -1) / sqrt(dim_k) # (1, 5, 5)\n",
    "\tif is_causal:\n",
    "\t\tquery_length = querys.size(2)\n",
    "\t\tkey_length = keys.size(2)\n",
    "\t\ttemp_mask = torch.ones(query_length, key_length, dtype=torch.bool).tril(diagonal=0)\n",
    "\t\tscores = scores.masked_fill(temp_mask == False, float(\"-inf\"))\n",
    "\tweights = F.softmax(scores, dim=-1) # (1, 5, 5)\n",
    "\treturn weights @ values # (1, 5, 16)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "5jxCS_lunl_7"
   },
   "source": [
    "## 예제 2.14. 크로스 어텐션이 포함된 디코더 층"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "b7youbG9njnW"
   },
   "outputs": [],
   "source": [
    "class TransformerDecoderLayer(nn.Module):\n",
    "  def __init__(self, d_model, nhead, dim_feedforward=2048, dropout=0.1):\n",
    "    super().__init__()\n",
    "    self.self_attn = MultiheadAttention(d_model, d_model, nhead)\n",
    "    self.multihead_attn = MultiheadAttention(d_model, d_model, nhead)\n",
    "    self.feed_forward = PreLayerNormFeedForward(d_model, dim_feedforward, dropout)\n",
    "\n",
    "    self.norm1 = nn.LayerNorm(d_model)\n",
    "    self.norm2 = nn.LayerNorm(d_model)\n",
    "    self.dropout1 = nn.Dropout(dropout)\n",
    "    self.dropout2 = nn.Dropout(dropout)\n",
    "\n",
    "  def forward(self, tgt, encoder_output, is_causal=True):\n",
    "    # 셀프 어텐션 연산\n",
    "    x = self.norm1(tgt)\n",
    "    x = x + self.dropout1(self.self_attn(x, x, x, is_causal=is_causal))\n",
    "    # 크로스 어텐션 연산\n",
    "    x = self.norm2(x)\n",
    "    x = x + self.dropout2(self.multihead_attn(x, encoder_output, encoder_output))\n",
    "    # 피드 포워드 연산\n",
    "    x = self.feed_forward(x)\n",
    "    return x"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "id": "l218C0ZOnqDO"
   },
   "source": [
    "## 예제 2.15. 디코더 구현"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "7meGa10vnnw1"
   },
   "outputs": [],
   "source": [
    "import copy\n",
    "def get_clones(module, N):\n",
    "  return nn.ModuleList([copy.deepcopy(module) for i in range(N)])\n",
    "\n",
    "class TransformerDecoder(nn.Module):\n",
    "  def __init__(self, decoder_layer, num_layers):\n",
    "    super().__init__()\n",
    "    self.layers = get_clones(decoder_layer, num_layers)\n",
    "    self.num_layers = num_layers\n",
    "\n",
    "  def forward(self, tgt, src):\n",
    "    output = tgt\n",
    "    for mod in self.layers:\n",
    "        output = mod(output, src)\n",
    "    return output"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}


================================================
FILE: 03장/chapter_3.ipynb
================================================
{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "8Gd5PVm7H7o7"
      },
      "outputs": [],
      "source": [
        "!pip install transformers==4.50.0 datasets==3.5.0 huggingface_hub==0.29.0 -qqq"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6dgKU45fCffl"
      },
      "source": [
        "# 3.1절 허깅페이스 트랜스포머란?"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "s6olgr_ite6K"
      },
      "source": [
        "## 예제 3.1. BERT와 GPT-2 모델을 활용할 때 허깅페이스 트랜스포머 코드 비교"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "kAwjIEiKIBVj"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoTokenizer, AutoModel\n",
        "\n",
        "text = \"What is Huggingface Transformers?\"\n",
        "# BERT 모델 활용\n",
        "bert_model = AutoModel.from_pretrained(\"bert-base-uncased\")\n",
        "bert_tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased')\n",
        "encoded_input = bert_tokenizer(text, return_tensors='pt')\n",
        "bert_output = bert_model(**encoded_input)\n",
        "# GPT-2 모델 활용\n",
        "gpt_model = AutoModel.from_pretrained('gpt2')\n",
        "gpt_tokenizer = AutoTokenizer.from_pretrained('gpt2')\n",
        "encoded_input = gpt_tokenizer(text, return_tensors='pt')\n",
        "gpt_output = gpt_model(**encoded_input)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "cUIzXEp9CleZ"
      },
      "source": [
        "# 3.3절 허깅페이스 라이브러리 사용법 익히기"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6oo8e5smt8gB"
      },
      "source": [
        "## 예제 3.2. 모델 아이디로 모델 불러오기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "vsj_ZOu-CobD"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoModel\n",
        "model_id = 'klue/roberta-base'\n",
        "model = AutoModel.from_pretrained(model_id)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TDARA5SpuJgt"
      },
      "source": [
        "## 예제 3.4. 분류 헤드가 포함된 모델 불러오기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "XdfQpfUuCrdy"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoModelForSequenceClassification\n",
        "model_id = 'SamLowe/roberta-base-go_emotions'\n",
        "classification_model = AutoModelForSequenceClassification.from_pretrained(model_id)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "XPfN9HZluWeW"
      },
      "source": [
        "## 예제 3.6. 분류 헤드가 랜덤으로 초기화된 모델 불러오기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "KnQbDV3JCtwE"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoModelForSequenceClassification\n",
        "model_id = 'klue/roberta-base'\n",
        "classification_model = AutoModelForSequenceClassification.from_pretrained(model_id)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WeYgt5UzuwGC"
      },
      "source": [
        "## 예제 3.8. 토크나이저 불러오기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "GOS1p907u1CO"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoTokenizer\n",
        "model_id = 'klue/roberta-base'\n",
        "tokenizer = AutoTokenizer.from_pretrained(model_id)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "DKssSh_tu8v-"
      },
      "source": [
        "## 예제 3.9. 토크나이저 사용하기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "iaX4LD4Eu3RL"
      },
      "outputs": [],
      "source": [
        "tokenized = tokenizer(\"토크나이저는 텍스트를 토큰 단위로 나눈다\")\n",
        "print(tokenized)\n",
        "# {'input_ids': [0, 9157, 7461, 2190, 2259, 8509, 2138, 1793, 2855, 5385, 2200, 20950, 2],\n",
        "#  'token_type_ids': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],\n",
        "#  'attention_mask': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}\n",
        "\n",
        "print(tokenizer.convert_ids_to_tokens(tokenized['input_ids']))\n",
        "# ['[CLS]', '토크', '##나이', '##저', '##는', '텍스트', '##를', '토', '##큰', '단위', '##로', '나눈다', '[SEP]']\n",
        "\n",
        "print(tokenizer.decode(tokenized['input_ids']))\n",
        "# [CLS] 토크나이저는 텍스트를 토큰 단위로 나눈다 [SEP]\n",
        "\n",
        "print(tokenizer.decode(tokenized['input_ids'], skip_special_tokens=True))\n",
        "# 토크나이저는 텍스트를 토큰 단위로 나눈다"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "YjqS0r-avFl-"
      },
      "source": [
        "## 예제 3.10. 토크나이저에 여러 문장 넣기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "vmcZndW0vGqC"
      },
      "outputs": [],
      "source": [
        "tokenizer(['첫 번째 문장', '두 번째 문장'])\n",
        "\n",
        "# {'input_ids': [[0, 1656, 1141, 3135, 6265, 2], [0, 864, 1141, 3135, 6265, 2]],\n",
        "# 'token_type_ids': [[0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]],\n",
        "# 'attention_mask': [[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 1, 1]]}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "On7iLMjHvMQd"
      },
      "source": [
        "## 예제 3.11. 하나의 데이터에 여러 문장이 들어가는 경우"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "oe9aqgr-vTOv"
      },
      "outputs": [],
      "source": [
        "tokenizer([['첫 번째 문장', '두 번째 문장']])\n",
        "\n",
        "# {'input_ids': [[0, 1656, 1141, 3135, 6265, 2, 864, 1141, 3135, 6265, 2]],\n",
        "# 'token_type_ids': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],\n",
        "# 'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "3oaV-a3lvcQK"
      },
      "source": [
        "## 예제 3.12. 토큰 아이디를 문자열로 복원"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "GxIG352EvdDi"
      },
      "outputs": [],
      "source": [
        "first_tokenized_result = tokenizer(['첫 번째 문장', '두 번째 문장'])['input_ids']\n",
        "tokenizer.batch_decode(first_tokenized_result)\n",
        "# ['[CLS] 첫 번째 문장 [SEP]', '[CLS] 두 번째 문장 [SEP]']\n",
        "\n",
        "second_tokenized_result = tokenizer([['첫 번째 문장', '두 번째 문장']])['input_ids']\n",
        "tokenizer.batch_decode(second_tokenized_result)\n",
        "# ['[CLS] 첫 번째 문장 [SEP] 두 번째 문장 [SEP]']"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "e22TcuvUvk3E"
      },
      "source": [
        "## 예제 3.13. BERT 토크나이저와 RoBERTa 토크나이저"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "0vDO4KJ_vlUv"
      },
      "outputs": [],
      "source": [
        "bert_tokenizer = AutoTokenizer.from_pretrained('klue/bert-base')\n",
        "bert_tokenizer([['첫 번째 문장', '두 번째 문장']])\n",
        "# {'input_ids': [[2, 1656, 1141, 3135, 6265, 3, 864, 1141, 3135, 6265, 3]],\n",
        "# 'token_type_ids': [[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]],\n",
        "# 'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}\n",
        "\n",
        "roberta_tokenizer = AutoTokenizer.from_pretrained('klue/roberta-base')\n",
        "roberta_tokenizer([['첫 번째 문장', '두 번째 문장']])\n",
        "# {'input_ids': [[0, 1656, 1141, 3135, 6265, 2, 864, 1141, 3135, 6265, 2]],\n",
        "# 'token_type_ids': [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],\n",
        "# 'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}\n",
        "\n",
        "en_roberta_tokenizer = AutoTokenizer.from_pretrained('roberta-base')\n",
        "en_roberta_tokenizer([['first sentence', 'second sentence']])\n",
        "# {'input_ids': [[0, 9502, 3645, 2, 2, 10815, 3645, 2]],\n",
        "# 'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1]]}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F8TSCJ_rvux1"
      },
      "source": [
        "## 예제 3.14. attention_mask 확인"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Lj8XkTM9vvwu"
      },
      "outputs": [],
      "source": [
        "tokenizer(['첫 번째 문장은 짧다.', '두 번째 문장은 첫 번째 문장 보다 더 길다.'], padding='longest')\n",
        "\n",
        "# {'input_ids': [[0, 1656, 1141, 3135, 6265, 2073, 1599, 2062, 18, 2, 1, 1, 1, 1, 1, 1],\n",
        "# [0, 864, 1141, 3135, 6265, 2073, 1656, 1141, 3135, 6265, 3632, 831, 647, 2062, 18, 2]],\n",
        "# 'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],\n",
        "# [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "e9hRNhL6v8J3"
      },
      "source": [
        "## 예제 3.15. KLUE MRC 데이터셋 다운로드"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "h6rED4n6v-dg"
      },
      "outputs": [],
      "source": [
        "from datasets import load_dataset\n",
        "klue_mrc_dataset = load_dataset('klue', 'mrc')\n",
        "# klue_mrc_dataset_only_train = load_dataset('klue', 'mrc', split='train')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "28cdd3vPwF-x"
      },
      "source": [
        "## 예제 3.16. 로컬의 데이터 활용하기\n",
        "(안내) 아래 코드를 실행하기 위해서는 구글 코랩에 csv 파일이 업로드 되어야 합니다. 허깅페이스 datasets 형식으로 쉽게 변환할 수 있다는 점을 보여주기 위한 예시 코드입니다."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "c7FfgbFUDBQg"
      },
      "outputs": [],
      "source": [
        "from datasets import load_dataset\n",
        "# 로컬의 데이터 파일을 활용\n",
        "dataset = load_dataset(\"csv\", data_files=\"my_file.csv\")\n",
        "\n",
        "# 파이썬 딕셔너리 활용\n",
        "from datasets import Dataset\n",
        "my_dict = {\"a\": [1, 2, 3]}\n",
        "dataset = Dataset.from_dict(my_dict)\n",
        "\n",
        "# 판다스 데이터프레임 활용\n",
        "from datasets import Dataset\n",
        "import pandas as pd\n",
        "df = pd.DataFrame({\"a\": [1, 2, 3]})\n",
        "dataset = Dataset.from_pandas(df)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "kbdIGz7YDQ8q"
      },
      "source": [
        "# 3.4절 모델 학습시키기"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "OE1cIGmdwT8n"
      },
      "source": [
        "## 예제 3.17. 모델 학습에 사용할 연합뉴스 데이터셋 다운로드"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "uHjb8Rd6DSDh"
      },
      "outputs": [],
      "source": [
        "from datasets import load_dataset\n",
        "klue_tc_train = load_dataset('klue', 'ynat', split='train')\n",
        "klue_tc_eval = load_dataset('klue', 'ynat', split='validation')\n",
        "klue_tc_train"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "z90M9sisDUmr"
      },
      "outputs": [],
      "source": [
        "klue_tc_train[0]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "HpQ3OqhoDWPY"
      },
      "outputs": [],
      "source": [
        "klue_tc_train.features['label'].names\n",
        "# ['IT과학', '경제', '사회', '생활문화', '세계', '스포츠', '정치']"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Qnb6SqInweAW"
      },
      "source": [
        "## 예제 3.18. 실습에 사용하지 않는 불필요한 컬럼 제거"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "wr6cX9laDX9Z"
      },
      "outputs": [],
      "source": [
        "klue_tc_train = klue_tc_train.remove_columns(['guid', 'url', 'date'])\n",
        "klue_tc_eval = klue_tc_eval.remove_columns(['guid', 'url', 'date'])\n",
        "klue_tc_train"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "MAjvDdjqwoXY"
      },
      "source": [
        "## 예제 3.19. 카테고리를 문자로 표기한 label_str 컬럼 추가"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "W2YoqY7jDZVN"
      },
      "outputs": [],
      "source": [
        "klue_tc_train.features['label']\n",
        "# ClassLabel(names=['IT과학', '경제', '사회', '생활문화', '세계', '스포츠', '정치'], id=None)\n",
        "\n",
        "klue_tc_train.features['label'].int2str(1)\n",
        "# '경제'\n",
        "\n",
        "klue_tc_label = klue_tc_train.features['label']\n",
        "\n",
        "def make_str_label(batch):\n",
        "  batch['label_str'] = klue_tc_label.int2str(batch['label'])\n",
        "  return batch\n",
        "\n",
        "klue_tc_train = klue_tc_train.map(make_str_label, batched=True, batch_size=1000)\n",
        "\n",
        "klue_tc_train[0]\n",
        "# {'title': '유튜브 내달 2일까지 크리에이터 지원 공간 운영', 'label': 3, 'label_str': '생활문화'}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nzAkPNnmwumM"
      },
      "source": [
        "## 예제 3.20. 학습/검증/테스트 데이터셋 분할"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "xNbew6U5Da9r"
      },
      "outputs": [],
      "source": [
        "train_dataset = klue_tc_train.train_test_split(test_size=10000, shuffle=True, seed=42)['test']\n",
        "dataset = klue_tc_eval.train_test_split(test_size=1000, shuffle=True, seed=42)\n",
        "test_dataset = dataset['test']\n",
        "valid_dataset = dataset['train'].train_test_split(test_size=1000, shuffle=True, seed=42)['test']"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Fd7D7qxEw1mS"
      },
      "source": [
        "## 예제 3.21. Trainer를 사용한 학습: (1) 준비"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "OYfOFc06w37p"
      },
      "outputs": [],
      "source": [
        "import torch\n",
        "import numpy as np\n",
        "from transformers import (\n",
        "    Trainer,\n",
        "    TrainingArguments,\n",
        "    AutoModelForSequenceClassification,\n",
        "    AutoTokenizer\n",
        ")\n",
        "\n",
        "def tokenize_function(examples):\n",
        "    return tokenizer(examples[\"title\"], padding=\"max_length\", truncation=True)\n",
        "\n",
        "model_id = \"klue/roberta-base\"\n",
        "model = AutoModelForSequenceClassification.from_pretrained(model_id, num_labels=len(train_dataset.features['label'].names))\n",
        "tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
        "\n",
        "train_dataset = train_dataset.map(tokenize_function, batched=True)\n",
        "valid_dataset = valid_dataset.map(tokenize_function, batched=True)\n",
        "test_dataset = test_dataset.map(tokenize_function, batched=True)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dOH98qOLw9yn"
      },
      "source": [
        "## 예제 3.22. Trainer를 사용한 학습: (2) 학습 인자와 평가 함수 정의"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "ryZVReVmxAn0"
      },
      "outputs": [],
      "source": [
        "training_args = TrainingArguments(\n",
        "    output_dir=\"./results\",\n",
        "    num_train_epochs=1,\n",
        "    per_device_train_batch_size=8,\n",
        "    per_device_eval_batch_size=8,\n",
        "    evaluation_strategy=\"epoch\",\n",
        "    learning_rate=5e-5,\n",
        "    push_to_hub=False\n",
        ")\n",
        "\n",
        "def compute_metrics(eval_pred):\n",
        "    logits, labels = eval_pred\n",
        "    predictions = np.argmax(logits, axis=-1)\n",
        "    return {\"accuracy\": (predictions == labels).mean()}"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "ALNfYD95xGsq"
      },
      "source": [
        "## 예제 3.23. Trainer를 사용한 학습 - (3) 학습 진행"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "sGBbSFcAE2mm"
      },
      "outputs": [],
      "source": [
        "trainer = Trainer(\n",
        "    model=model,\n",
        "    args=training_args,\n",
        "    train_dataset=train_dataset,\n",
        "    eval_dataset=valid_dataset,\n",
        "    tokenizer=tokenizer,\n",
        "    compute_metrics=compute_metrics,\n",
        ")\n",
        "\n",
        "trainer.train()\n",
        "\n",
        "trainer.evaluate(test_dataset) # 정확도 0.84"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "oHVobEq8xS0j"
      },
      "source": [
        "## 예제 3.24. Trainer를 사용하지 않는 학습: (1) 학습을 위한 모델과 토크나이저 준비"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "pdTjuT3txUeX"
      },
      "outputs": [],
      "source": [
        "import torch\n",
        "from tqdm.auto import tqdm\n",
        "from torch.utils.data import DataLoader\n",
        "from torch.optim import AdamW\n",
        "\n",
        "def tokenize_function(examples): # 제목(title) 컬럼에 대한 토큰화\n",
        "    return tokenizer(examples[\"title\"], padding=\"max_length\", truncation=True)\n",
        "\n",
        "# 모델과 토크나이저 불러오기\n",
        "device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
        "model_id = \"klue/roberta-base\"\n",
        "model = AutoModelForSequenceClassification.from_pretrained(model_id, num_labels=len(train_dataset.features['label'].names))\n",
        "tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
        "model.to(device)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "4I4D0Vs_xamC"
      },
      "source": [
        "## 예제 3.25 Trainer를 사용하지 않는 학습: (2) 학습을 위한 데이터 준비"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "3UA738ljxcmh"
      },
      "outputs": [],
      "source": [
        "def make_dataloader(dataset, batch_size, shuffle=True):\n",
        "    dataset = dataset.map(tokenize_function, batched=True).with_format(\"torch\") # 데이터셋에 토큰화 수행\n",
        "    dataset = dataset.rename_column(\"label\", \"labels\") # 컬럼 이름 변경\n",
        "    dataset = dataset.remove_columns(column_names=['title']) # 불필요한 컬럼 제거\n",
        "    return DataLoader(dataset, batch_size=batch_size, shuffle=shuffle)\n",
        "\n",
        "# 데이터로더 만들기\n",
        "train_dataloader = make_dataloader(train_dataset, batch_size=8, shuffle=True)\n",
        "valid_dataloader = make_dataloader(valid_dataset, batch_size=8, shuffle=False)\n",
        "test_dataloader = make_dataloader(test_dataset, batch_size=8, shuffle=False)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tg5ertQLxtSK"
      },
      "source": [
        "## 예제 3.26. Trainer를 사용하지 않는 학습: (3) 학습을 위한 함수 정의"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "my5ujdBkxvQX"
      },
      "outputs": [],
      "source": [
        "def train_epoch(model, data_loader, optimizer):\n",
        "    model.train()\n",
        "    total_loss = 0\n",
        "    for batch in tqdm(data_loader):\n",
        "        optimizer.zero_grad()\n",
        "        input_ids = batch['input_ids'].to(device) # 모델에 입력할 토큰 아이디\n",
        "        attention_mask = batch['attention_mask'].to(device) # 모델에 입력할 어텐션 마스크\n",
        "        labels = batch['labels'].to(device) # 모델에 입력할 레이블\n",
        "        outputs = model(input_ids, attention_mask=attention_mask, labels=labels) # 모델 계산\n",
        "        loss = outputs.loss # 손실\n",
        "        loss.backward() # 역전파\n",
        "        optimizer.step() # 모델 업데이트\n",
        "        total_loss += loss.item()\n",
        "    avg_loss = total_loss / len(data_loader)\n",
        "    return avg_loss"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "HqfUWSpYxv6w"
      },
      "source": [
        "## 예제 3.27. Trainer를 사용하지 않는 학습: (4) 평가를 위한 함수 정의"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "a4Vo66qkx0LK"
      },
      "outputs": [],
      "source": [
        "def evaluate(model, data_loader):\n",
        "    model.eval()\n",
        "    total_loss = 0\n",
        "    predictions = []\n",
        "    true_labels = []\n",
        "    with torch.no_grad():\n",
        "        for batch in tqdm(data_loader):\n",
        "            input_ids = batch['input_ids'].to(device)\n",
        "            attention_mask = batch['attention_mask'].to(device)\n",
        "            labels = batch['labels'].to(device)\n",
        "            outputs = model(input_ids, attention_mask=attention_mask, labels=labels)\n",
        "            logits = outputs.logits\n",
        "            loss = outputs.loss\n",
        "            total_loss += loss.item()\n",
        "            preds = torch.argmax(logits, dim=-1)\n",
        "            predictions.extend(preds.cpu().numpy())\n",
        "            true_labels.extend(labels.cpu().numpy())\n",
        "    avg_loss = total_loss / len(data_loader)\n",
        "    accuracy = np.mean(np.asarray(predictions) == np.asarray(true_labels))\n",
        "    return avg_loss, accuracy"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "Hi1pEAU8x17j"
      },
      "source": [
        "## 예제 3.28 Trainer를 사용하지 않는 학습: (5) 학습 수행"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "m7mXY8iBx6un",
        "collapsed": true
      },
      "outputs": [],
      "source": [
        "num_epochs = 1\n",
        "optimizer = AdamW(model.parameters(), lr=5e-5)\n",
        "\n",
        "# 학습 루프\n",
        "for epoch in range(num_epochs):\n",
        "    print(f\"Epoch {epoch+1}/{num_epochs}\")\n",
        "    train_loss = train_epoch(model, train_dataloader, optimizer)\n",
        "    print(f\"Training loss: {train_loss}\")\n",
        "    valid_loss, valid_accuracy = evaluate(model, valid_dataloader)\n",
        "    print(f\"Validation loss: {valid_loss}\")\n",
        "    print(f\"Validation accuracy: {valid_accuracy}\")\n",
        "\n",
        "# Testing\n",
        "_, test_accuracy = evaluate(model, test_dataloader)\n",
        "print(f\"Test accuracy: {test_accuracy}\") # 정확도 0.82"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mqanaywJyDOq"
      },
      "source": [
        "## 예제 3.29. 허깅페이스 허브에 모델 업로드"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "rj62Q5Dm4wDN"
      },
      "outputs": [],
      "source": [
        "# 모델의 예측 아이디와 문자열 레이블을 연결할 데이터를 모델 config에 저장\n",
        "id2label = {i: label for i, label in enumerate(train_dataset.features['label'].names)}\n",
        "label2id = {label: i for i, label in id2label.items()}\n",
        "model.config.id2label = id2label\n",
        "model.config.label2id = label2id"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "03EY1lJ0ISzC"
      },
      "outputs": [],
      "source": [
        "from huggingface_hub import login\n",
        "\n",
        "login(token=\"본인의 허깅페이스 토큰 입력\")\n",
        "repo_id = f\"본인의 아이디 입력/roberta-base-klue-ynat-classification\"\n",
        "# Trainer를 사용한 경우\n",
        "trainer.push_to_hub(repo_id)\n",
        "# 직접 학습한 경우\n",
        "model.push_to_hub(repo_id)\n",
        "tokenizer.push_to_hub(repo_id)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "WheFaA_obmWG"
      },
      "source": [
        "# 3.5절 모델 추론하기"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "hrzXul13ygjb"
      },
      "source": [
        "## 예제 3.30. 학습한 모델을 불러와 pipeline을 활용해 추론하기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "_Gzm7n_fgjnO"
      },
      "outputs": [],
      "source": [
        "# 실습을 새롭게 시작하는 경우 데이터셋 다시 불러오기 실행\n",
        "# import torch\n",
        "# import torch.nn.functional as F\n",
        "# from datasets import load_dataset\n",
        "\n",
        "# dataset = load_dataset(\"klue\", \"ynat\", split=\"validation\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "hQojQCo9boGv"
      },
      "outputs": [],
      "source": [
        "from transformers import pipeline\n",
        "\n",
        "model_id = \"본인의 아이디 입력/roberta-base-klue-ynat-classification\"\n",
        "\n",
        "model_pipeline = pipeline(\"text-classification\", model=model_id)\n",
        "\n",
        "model_pipeline(dataset[\"title\"][:5])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "BJoFN-mEysQF"
      },
      "source": [
        "## 예제 3.31. 커스텀 파이프라인 구현"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "3k6Q34dJjkC3"
      },
      "outputs": [],
      "source": [
        "import torch\n",
        "from torch.nn.functional import softmax\n",
        "from transformers import AutoModelForSequenceClassification, AutoTokenizer\n",
        "\n",
        "class CustomPipeline:\n",
        "    def __init__(self, model_id):\n",
        "        self.model = AutoModelForSequenceClassification.from_pretrained(model_id)\n",
        "        self.tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
        "        self.model.eval()\n",
        "\n",
        "    def __call__(self, texts):\n",
        "        tokenized = self.tokenizer(texts, return_tensors=\"pt\", padding=True, truncation=True)\n",
        "\n",
        "        with torch.no_grad():\n",
        "            outputs = self.model(**tokenized)\n",
        "            logits = outputs.logits\n",
        "\n",
        "        probabilities = softmax(logits, dim=-1)\n",
        "        scores, labels = torch.max(probabilities, dim=-1)\n",
        "        labels_str = [self.model.config.id2label[label_idx] for label_idx in labels.tolist()]\n",
        "\n",
        "        return [{\"label\": label, \"score\": score.item()} for label, score in zip(labels_str, scores)]\n",
        "\n",
        "custom_pipeline = CustomPipeline(model_id)\n",
        "custom_pipeline(dataset['title'][:5])"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "T4",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.11.4"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}

================================================
FILE: 05장/chapter_5.ipynb
================================================
{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "PJ2VObxKndUv"
      },
      "outputs": [],
      "source": [
        "!pip install transformers==4.50.0 datasets==3.5.0 accelerate==1.6.0 peft==0.15.0 bitsandbytes==0.45.2 -qqq"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "EwgR3I7tvkGY"
      },
      "outputs": [],
      "source": [
        "import transformers\n",
        "import datasets\n",
        "import accelerate\n",
        "import peft\n",
        "import bitsandbytes\n",
        "import warnings\n",
        "warnings.filterwarnings('ignore')"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "1kCUlXvRghay"
      },
      "source": [
        "## 예제 5.1. 메모리 사용량 측정을 위한 함수 구현"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "2B8DIPZVmsgj"
      },
      "outputs": [],
      "source": [
        "import torch\n",
        "\n",
        "def print_gpu_utilization():\n",
        "    if torch.cuda.is_available():\n",
        "        used_memory = torch.cuda.memory_allocated() / 1024**3\n",
        "        print(f\"GPU 메모리 사용량: {used_memory:.3f} GB\")\n",
        "    else:\n",
        "        print(\"런타임 유형을 GPU로 변경하세요\")\n",
        "\n",
        "print_gpu_utilization()\n",
        "# 출력 결과\n",
        "# GPU 메모리 사용량: 0.000 GB"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "K2xD7tW0gjpw"
      },
      "source": [
        "## 예제 5.2. 모델을 불러오고 GPU 메모리와 데이터 타입 확인"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "sKxVEADBm-_o"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
        "\n",
        "def load_model_and_tokenizer(model_id, peft=None):\n",
        "    tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
        "    if peft is None:\n",
        "        model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=\"auto\", device_map={\"\":0})\n",
        "\n",
        "    print_gpu_utilization()\n",
        "    return model, tokenizer\n",
        "\n",
        "model_id = \"EleutherAI/polyglot-ko-1.3b\"\n",
        "model, tokenizer = load_model_and_tokenizer(model_id) # GPU 메모리 사용량: 2.599 GB\n",
        "print(\"모델 파라미터 데이터 타입: \", model.dtype) # torch.float16"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "0kcI2zbHglq0"
      },
      "source": [
        "## 예제 5.3. 그레이디언트와 옵티마이저 상태의 메모리 사용량을 계산하는 함수"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "wO3BN3Ayvor0"
      },
      "outputs": [],
      "source": [
        "from torch.optim import AdamW\n",
        "from torch.utils.data import DataLoader\n",
        "\n",
        "def estimate_memory_of_gradients(model):\n",
        "    total_memory = 0\n",
        "    for param in model.parameters():\n",
        "        if param.grad is not None:\n",
        "            total_memory += param.grad.nelement() * param.grad.element_size()\n",
        "    return total_memory\n",
        "\n",
        "def estimate_memory_of_optimizer(optimizer):\n",
        "    total_memory = 0\n",
        "    for state in optimizer.state.values():\n",
        "        for k, v in state.items():\n",
        "            if torch.is_tensor(v):\n",
        "                total_memory += v.nelement() * v.element_size()\n",
        "    return total_memory"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "gaYbUqvrgoAV"
      },
      "source": [
        "## 예제 5.4. 모델의 학습 과정에서 메모리 사용량을 확인하는 train_model 정의"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "9QvS6FL2VGvq"
      },
      "outputs": [],
      "source": [
        "def train_model(model, dataset, training_args):\n",
        "    if training_args.gradient_checkpointing:\n",
        "        model.gradient_checkpointing_enable()\n",
        "\n",
        "    train_dataloader = DataLoader(dataset, batch_size=training_args.per_device_train_batch_size)\n",
        "    optimizer = AdamW(model.parameters())\n",
        "    model.train()\n",
        "    gpu_utilization_printed = False\n",
        "    for step, batch in enumerate(train_dataloader, start=1):\n",
        "        batch = {k: v.to(model.device) for k, v in batch.items()}\n",
        "\n",
        "        outputs = model(**batch)\n",
        "        loss = outputs.loss\n",
        "        loss = loss / training_args.gradient_accumulation_steps\n",
        "        loss.backward()\n",
        "\n",
        "        if step % training_args.gradient_accumulation_steps == 0:\n",
        "            optimizer.step()\n",
        "            gradients_memory = estimate_memory_of_gradients(model)\n",
        "            optimizer_memory = estimate_memory_of_optimizer(optimizer)\n",
        "            if not gpu_utilization_printed:\n",
        "                print_gpu_utilization()\n",
        "                gpu_utilization_printed = True\n",
        "            optimizer.zero_grad()\n",
        "\n",
        "    print(f\"옵티마이저 상태의 메모리 사용량: {optimizer_memory / (1024 ** 3):.3f} GB\")\n",
        "    print(f\"그레디언트 메모리 사용량: {gradients_memory / (1024 ** 3):.3f} GB\")"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "TmABYRmFgqb1"
      },
      "source": [
        "## 예제 5.5. 랜덤 데이터셋을 생성하는 make_dummy_dataset 정의"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "V4cL_huKxF0z"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "from datasets import Dataset\n",
        "\n",
        "def make_dummy_dataset():\n",
        "  seq_len, dataset_size = 256, 64\n",
        "  dummy_data = {\n",
        "      \"input_ids\": np.random.randint(100, 30000, (dataset_size, seq_len)),\n",
        "      \"labels\": np.random.randint(100, 30000, (dataset_size, seq_len)),\n",
        "  }\n",
        "  dataset = Dataset.from_dict(dummy_data)\n",
        "  dataset.set_format(\"pt\")\n",
        "  return dataset"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nNaQ-ijXgsZS"
      },
      "source": [
        "## 예제 5.6. 더이상 사용하지 않는 GPU 메모리를 반환하는 cleanup 함수"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "7EG1VGsE3--n"
      },
      "outputs": [],
      "source": [
        "import gc\n",
        "\n",
        "def cleanup():\n",
        "    if 'model' in globals():\n",
        "        del globals()['model']\n",
        "    if 'dataset' in globals():\n",
        "        del globals()['dataset']\n",
        "    gc.collect()\n",
        "    torch.cuda.empty_cache()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "mD4Ny4o4g8xp"
      },
      "source": [
        "## 예제 5.7. GPU 사용량을 확인하는 gpu_memory_experiment 함수 정의"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "IOITvps5okzy"
      },
      "outputs": [],
      "source": [
        "from transformers import TrainingArguments, Trainer\n",
        "\n",
        "def gpu_memory_experiment(batch_size,\n",
        "                          gradient_accumulation_steps=1,\n",
        "                          gradient_checkpointing=False,\n",
        "                          model_id=\"EleutherAI/polyglot-ko-1.3b\",\n",
        "                          peft=None):\n",
        "\n",
        "    print(f\"배치 사이즈: {batch_size}\")\n",
        "    model, tokenizer = load_model_and_tokenizer(model_id, peft=peft)\n",
        "    if gradient_checkpointing == True or peft == 'qlora':\n",
        "        model.config.use_cache = False\n",
        "\n",
        "    dataset = make_dummy_dataset()\n",
        "\n",
        "    training_args = TrainingArguments(\n",
        "        per_device_train_batch_size=batch_size,\n",
        "        gradient_accumulation_steps=gradient_accumulation_steps,\n",
        "        gradient_checkpointing=gradient_checkpointing,\n",
        "        output_dir=\"./result\",\n",
        "        num_train_epochs=1\n",
        "      )\n",
        "\n",
        "    try:\n",
        "        train_model(model, dataset, training_args)\n",
        "    except RuntimeError as e:\n",
        "        if \"CUDA out of memory\" in str(e):\n",
        "            print(e)\n",
        "        else:\n",
        "            raise e\n",
        "    finally:\n",
        "        del model, dataset\n",
        "        gc.collect()\n",
        "        torch.cuda.empty_cache()\n",
        "        print_gpu_utilization()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "tDg029vEhAsH"
      },
      "source": [
        "## 예제 5.8. 배치 사이즈를 변경하며 메모리 사용량 측정"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "MtP76Bvt9MHu"
      },
      "outputs": [],
      "source": [
        "cleanup()\n",
        "print_gpu_utilization()\n",
        "\n",
        "for batch_size in [4, 8, 16]:\n",
        "    gpu_memory_experiment(batch_size)\n",
        "\n",
        "    torch.cuda.empty_cache()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "FxufLwLlhRvl"
      },
      "source": [
        "## 예제 5.10. 그레이디언트 누적을 적용했을 때 메모리 사용량"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "q03_I4BoE0LK"
      },
      "outputs": [],
      "source": [
        "cleanup()\n",
        "print_gpu_utilization()\n",
        "\n",
        "gpu_memory_experiment(batch_size=4, gradient_accumulation_steps=4)\n",
        "\n",
        "torch.cuda.empty_cache()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "dptic2nThW0h"
      },
      "source": [
        "## 예제 5.11. 그레이디언트 체크포인팅 사용 시 메모리 사용량"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "PQADaxmvFO3H"
      },
      "outputs": [],
      "source": [
        "cleanup()\n",
        "print_gpu_utilization()\n",
        "\n",
        "gpu_memory_experiment(batch_size=16, gradient_checkpointing=True)\n",
        "\n",
        "torch.cuda.empty_cache()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "icqVPpu-hjn0"
      },
      "source": [
        "## 예제 5.12. 모델을 불러오면서 LoRA 적용하기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "BVhrEQg7H_dh"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
        "from peft import LoraConfig, get_peft_model\n",
        "\n",
        "def load_model_and_tokenizer(model_id, peft=None):\n",
        "    tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
        "\n",
        "    if peft is None:\n",
        "        model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=\"auto\", device_map={\"\":0})\n",
        "\n",
        "    elif peft == 'lora':\n",
        "        model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=\"auto\", device_map={\"\":0})\n",
        "        lora_config = LoraConfig(\n",
        "                    r=8,\n",
        "                    lora_alpha=32,\n",
        "                    target_modules=[\"query_key_value\"],\n",
        "                    lora_dropout=0.05,\n",
        "                    bias=\"none\",\n",
        "                    task_type=\"CAUSAL_LM\"\n",
        "                )\n",
        "\n",
        "        model = get_peft_model(model, lora_config)\n",
        "        model.print_trainable_parameters()\n",
        "\n",
        "    print_gpu_utilization()\n",
        "    return model, tokenizer"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "qK6zCAhehqgT"
      },
      "source": [
        "## 예제 5.13. LoRA를 적용했을 때 GPU 메모리 사용량 확인"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "FOY0LASuIZOB"
      },
      "outputs": [],
      "source": [
        "cleanup()\n",
        "print_gpu_utilization()\n",
        "\n",
        "gpu_memory_experiment(batch_size=16, peft='lora')\n",
        "\n",
        "torch.cuda.empty_cache()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "F_V-mWDhYvLG"
      },
      "source": [
        "## 예제 5.14. 4비트 양자화 모델 불러오기"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "PGAJ3v0FYvLG"
      },
      "outputs": [],
      "source": [
        "from transformers import BitsAndBytesConfig\n",
        "nf4_config = BitsAndBytesConfig(\n",
        "    load_in_4bit=True,\n",
        "    bnb_4bit_quant_type=\"nf4\",\n",
        "    bnb_4bit_use_double_quant=True,\n",
        "    bnb_4bit_compute_dtype=torch.bfloat16\n",
        ")\n",
        "model_nf4 = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=nf4_config)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "6l0Q9zslh5Bw"
      },
      "source": [
        "## 예제 5.15. 예제 5.11에서 QLoRA 모델을 불러오는 부분을 추가"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "Z13B3SwCI-CL"
      },
      "outputs": [],
      "source": [
        "from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig\n",
        "from peft import LoraConfig, get_peft_model, prepare_model_for_kbit_training\n",
        "\n",
        "def load_model_and_tokenizer(model_id, peft=None):\n",
        "    tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
        "\n",
        "    if peft is None:\n",
        "        model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=\"auto\", device_map={\"\":0})\n",
        "\n",
        "    elif peft == 'lora':\n",
        "        model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=\"auto\", device_map={\"\":0})\n",
        "        lora_config = LoraConfig(\n",
        "                    r=8,\n",
        "                    lora_alpha=32,\n",
        "                    target_modules=[\"query_key_value\"],\n",
        "                    lora_dropout=0.05,\n",
        "                    bias=\"none\",\n",
        "                    task_type=\"CAUSAL_LM\"\n",
        "                )\n",
        "\n",
        "        model = get_peft_model(model, lora_config)\n",
        "        model.print_trainable_parameters()\n",
        "    elif peft == 'qlora':\n",
        "        lora_config = LoraConfig(\n",
        "                    r=8,\n",
        "                    lora_alpha=32,\n",
        "                    target_modules=[\"query_key_value\"],\n",
        "                    lora_dropout=0.05,\n",
        "                    bias=\"none\",\n",
        "                    task_type=\"CAUSAL_LM\"\n",
        "                )\n",
        "        bnb_config = BitsAndBytesConfig(\n",
        "                  load_in_4bit=True,\n",
        "                  bnb_4bit_use_double_quant=True,\n",
        "                  bnb_4bit_quant_type=\"nf4\",\n",
        "                  bnb_4bit_compute_dtype=torch.float16\n",
        "              )\n",
        "        model = AutoModelForCausalLM.from_pretrained(model_id, quantization_config=bnb_config, device_map={\"\":0})\n",
        "        model.gradient_checkpointing_enable()\n",
        "        model = prepare_model_for_kbit_training(model)\n",
        "        model = get_peft_model(model, lora_config)\n",
        "        model.print_trainable_parameters()\n",
        "\n",
        "    print_gpu_utilization()\n",
        "    return model, tokenizer"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "UfqY4675h9Tf"
      },
      "source": [
        "## 예제 5.16. QLoRA를 적용했을 때 GPU 메모리 사용량 확인"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "X7lwejFmJdrv"
      },
      "outputs": [],
      "source": [
        "cleanup()\n",
        "print_gpu_utilization()\n",
        "\n",
        "gpu_memory_experiment(batch_size=16, peft='qlora')\n",
        "\n",
        "torch.cuda.empty_cache()"
      ]
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "T4",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3 (ipykernel)",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.11.4"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}

================================================
FILE: 06장/api_request_parallel_processor.py
================================================
# %%
# imports
import aiohttp  # for making API calls concurrently
import argparse  # for running script from command line
import asyncio  # for running API calls concurrently
import json  # for saving results to a jsonl file
import logging  # for logging rate limit warnings and other messages
import os  # for reading API key
import re  # for matching endpoint from request URL
import tiktoken  # for counting tokens
import time  # for sleeping after rate limit is hit
from dataclasses import (
    dataclass,
    field,
)  # for storing API inputs, outputs, and metadata


async def process_api_requests_from_file(
    requests_filepath: str,
    save_filepath: str,
    request_url: str,
    api_key: str,
    max_requests_per_minute: float,
    max_tokens_per_minute: float,
    token_encoding_name: str,
    max_attempts: int,
    logging_level: int,
):
    """Processes API requests in parallel, throttling to stay under rate limits."""
    # constants
    seconds_to_pause_after_rate_limit_error = 15
    seconds_to_sleep_each_loop = (
        0.001  # 1 ms limits max throughput to 1,000 requests per second
    )

    # initialize logging
    logging.basicConfig(level=logging_level)
    logging.debug(f"Logging initialized at level {logging_level}")

    # infer API endpoint and construct request header
    api_endpoint = api_endpoint_from_url(request_url)
    request_header = {"Authorization": f"Bearer {api_key}"}
    # use api-key header for Azure deployments
    if '/deployments' in request_url:
        request_header = {"api-key": f"{api_key}"}

    # initialize trackers
    queue_of_requests_to_retry = asyncio.Queue()
    task_id_generator = (
        task_id_generator_function()
    )  # generates integer IDs of 0, 1, 2, ...
    status_tracker = (
        StatusTracker()
    )  # single instance to track a collection of variables
    next_request = None  # variable to hold the next request to call

    # initialize available capacity counts
    available_request_capacity = max_requests_per_minute
    available_token_capacity = max_tokens_per_minute
    last_update_time = time.time()

    # initialize flags
    file_not_finished = True  # after file is empty, we'll skip reading it
    logging.debug(f"Initialization complete.")

    # initialize file reading
    with open(requests_filepath) as file:
        # `requests` will provide requests one at a time
        requests = file.__iter__()
        logging.debug(f"File opened. Entering main loop")
        async with aiohttp.ClientSession() as session:  # Initialize ClientSession here
            while True:
                # get next request (if one is not already waiting for capacity)
                if next_request is None:
                    if not queue_of_requests_to_retry.empty():
                        next_request = queue_of_requests_to_retry.get_nowait()
                        logging.debug(
                            f"Retrying request {next_request.task_id}: {next_request}"
                        )
                    elif file_not_finished:
                        try:
                            # get new request
                            request_json = json.loads(next(requests))
                            next_request = APIRequest(
                                task_id=next(task_id_generator),
                                request_json=request_json,
                                token_consumption=num_tokens_consumed_from_request(
                                    request_json, api_endpoint, token_encoding_name
                                ),
                                attempts_left=max_attempts,
                                metadata=request_json.pop("metadata", None),
                            )
                            status_tracker.num_tasks_started += 1
                            status_tracker.num_tasks_in_progress += 1
                            logging.debug(
                                f"Reading request {next_request.task_id}: {next_request}"
                            )
                        except StopIteration:
                            # if file runs out, set flag to stop reading it
                            logging.debug("Read file exhausted")
                            file_not_finished = False

                # update available capacity
                current_time = time.time()
                seconds_since_update = current_time - last_update_time
                available_request_capacity = min(
                    available_request_capacity
                    + max_requests_per_minute * seconds_since_update / 60.0,
                    max_requests_per_minute,
                )
                available_token_capacity = min(
                    available_token_capacity
                    + max_tokens_per_minute * seconds_since_update / 60.0,
                    max_tokens_per_minute,
                )
                last_update_time = current_time

                # if enough capacity available, call API
                if next_request:
                    next_request_tokens = next_request.token_consumption
                    if (
                        available_request_capacity >= 1
                        and available_token_capacity >= next_request_tokens
                    ):
                        # update counters
                        available_request_capacity -= 1
                        available_token_capacity -= next_request_tokens
                        next_request.attempts_left -= 1

                        # call API
                        asyncio.create_task(
                            next_request.call_api(
                                session=session,
                                request_url=request_url,
                                request_header=request_header,
                                retry_queue=queue_of_requests_to_retry,
                                save_filepath=save_filepath,
                                status_tracker=status_tracker,
                            )
                        )
                        next_request = None  # reset next_request to empty

                # if all tasks are finished, break
                if status_tracker.num_tasks_in_progress == 0:
                    break

                # main loop sleeps briefly so concurrent tasks can run
                await asyncio.sleep(seconds_to_sleep_each_loop)

                # if a rate limit error was hit recently, pause to cool down
                seconds_since_rate_limit_error = (
                    time.time() - status_tracker.time_of_last_rate_limit_error
                )
                if (
                    seconds_since_rate_limit_error
                    < seconds_to_pause_after_rate_limit_error
                ):
                    remaining_seconds_to_pause = (
                        seconds_to_pause_after_rate_limit_error
                        - seconds_since_rate_limit_error
                    )
                    await asyncio.sleep(remaining_seconds_to_pause)
                    # ^e.g., if pause is 15 seconds and final limit was hit 5 seconds ago
                    logging.warn(
                        f"Pausing to cool down until {time.ctime(status_tracker.time_of_last_rate_limit_error + seconds_to_pause_after_rate_limit_error)}"
                    )

        # after finishing, log final status
        logging.info(
            f"""Parallel processing complete. Results saved to {save_filepath}"""
        )
        if status_tracker.num_tasks_failed > 0:
            logging.warning(
                f"{status_tracker.num_tasks_failed} / {status_tracker.num_tasks_started} requests failed. Errors logged to {save_filepath}."
            )
        if status_tracker.num_rate_limit_errors > 0:
            logging.warning(
                f"{status_tracker.num_rate_limit_errors} rate limit errors received. Consider running at a lower rate."
            )


# dataclasses


@dataclass
class StatusTracker:
    """Stores metadata about the script's progress. Only one instance is created."""

    num_tasks_started: int = 0
    num_tasks_in_progress: int = 0  # script ends when this reaches 0
    num_tasks_succeeded: int = 0
    num_tasks_failed: int = 0
    num_rate_limit_errors: int = 0
    num_api_errors: int = 0  # excluding rate limit errors, counted above
    num_other_errors: int = 0
    time_of_last_rate_limit_error: int = 0  # used to cool off after hitting rate limits


@dataclass
class APIRequest:
    """Stores an API request's inputs, outputs, and other metadata. Contains a method to make an API call."""

    task_id: int
    request_json: dict
    token_consumption: int
    attempts_left: int
    metadata: dict
    result: list = field(default_factory=list)

    async def call_api(
        self,
        session: aiohttp.ClientSession,
        request_url: str,
        request_header: dict,
        retry_queue: asyncio.Queue,
        save_filepath: str,
        status_tracker: StatusTracker,
    ):
        """Calls the OpenAI API and saves results."""
        logging.info(f"Starting request #{self.task_id}")
        error = None
        try:
            async with session.post(
                url=request_url, headers=request_header, json=self.request_json
            ) as response:
                response = await response.json()
            if "error" in response:
                logging.warning(
                    f"Request {self.task_id} failed with error {response['error']}"
                )
                status_tracker.num_api_errors += 1
                error = response
                if "Rate limit" in response["error"].get("message", ""):
                    status_tracker.time_of_last_rate_limit_error = time.time()
                    status_tracker.num_rate_limit_errors += 1
                    status_tracker.num_api_errors -= (
                        1  # rate limit errors are counted separately
                    )

        except (
            Exception
        ) as e:  # catching naked exceptions is bad practice, but in this case we'll log & save them
            logging.warning(f"Request {self.task_id} failed with Exception {e}")
            status_tracker.num_other_errors += 1
            error = e
        if error:
            self.result.append(error)
            if self.attempts_left:
                retry_queue.put_nowait(self)
            else:
                logging.error(
                    f"Request {self.request_json} failed after all attempts. Saving errors: {self.result}"
                )
                data = (
                    [self.request_json, [str(e) for e in self.result], self.metadata]
                    if self.metadata
                    else [self.request_json, [str(e) for e in self.result]]
                )
                append_to_jsonl(data, save_filepath)
                status_tracker.num_tasks_in_progress -= 1
                status_tracker.num_tasks_failed += 1
        else:
            data = (
                [self.request_json, response, self.metadata]
                if self.metadata
                else [self.request_json, response]
            )
            append_to_jsonl(data, save_filepath)
            status_tracker.num_tasks_in_progress -= 1
            status_tracker.num_tasks_succeeded += 1
            logging.debug(f"Request {self.task_id} saved to {save_filepath}")


# functions


def api_endpoint_from_url(request_url):
    """Extract the API endpoint from the request URL."""
    match = re.search("^https://[^/]+/v\\d+/(.+)$", request_url)
    if match is None:
        # for Azure OpenAI deployment urls
        match = re.search(r"^https://[^/]+/openai/deployments/[^/]+/(.+?)(\?|$)", request_url)
    return match[1]


def append_to_jsonl(data, filename: str) -> None:
    """Append a json payload to the end of a jsonl file."""
    json_string = json.dumps(data)
    with open(filename, "a") as f:
        f.write(json_string + "\n")


def num_tokens_consumed_from_request(
    request_json: dict,
    api_endpoint: str,
    token_encoding_name: str,
):
    """Count the number of tokens in the request. Only supports completion and embedding requests."""
    encoding = tiktoken.get_encoding(token_encoding_name)
    # if completions request, tokens = prompt + n * max_tokens
    if api_endpoint.endswith("completions"):
        max_tokens = request_json.get("max_tokens", 15)
        n = request_json.get("n", 1)
        completion_tokens = n * max_tokens

        # chat completions
        if api_endpoint.startswith("chat/"):
            num_tokens = 0
            for message in request_json["messages"]:
                num_tokens += 4  # every message follows <im_start>{role/name}\n{content}<im_end>\n
                for key, value in message.items():
                    num_tokens += len(encoding.encode(value))
                    if key == "name":  # if there's a name, the role is omitted
                        num_tokens -= 1  # role is always required and always 1 token
            num_tokens += 2  # every reply is primed with <im_start>assistant
            return num_tokens + completion_tokens
        # normal completions
        else:
            prompt = request_json["prompt"]
            if isinstance(prompt, str):  # single prompt
                prompt_tokens = len(encoding.encode(prompt))
                num_tokens = prompt_tokens + completion_tokens
                return num_tokens
            elif isinstance(prompt, list):  # multiple prompts
                prompt_tokens = sum([len(encoding.encode(p)) for p in prompt])
                num_tokens = prompt_tokens + completion_tokens * len(prompt)
                return num_tokens
            else:
                raise TypeError(
                    'Expecting either string or list of strings for "prompt" field in completion request'
                )
    # if embeddings request, tokens = input tokens
    elif api_endpoint == "embeddings":
        input = request_json["input"]
        if isinstance(input, str):  # single input
            num_tokens = len(encoding.encode(input))
            return num_tokens
        elif isinstance(input, list):  # multiple inputs
            num_tokens = sum([len(encoding.encode(i)) for i in input])
            return num_tokens
        else:
            raise TypeError(
                'Expecting either string or list of strings for "inputs" field in embedding request'
            )
    # more logic needed to support other API calls (e.g., edits, inserts, DALL-E)
    else:
        raise NotImplementedError(
            f'API endpoint "{api_endpoint}" not implemented in this script'
        )


def task_id_generator_function():
    """Generate integers 0, 1, 2, and so on."""
    task_id = 0
    while True:
        yield task_id
        task_id += 1


# run script


if __name__ == "__main__":
    # parse command line arguments
    parser = argparse.ArgumentParser()
    parser.add_argument("--requests_filepath")
    parser.add_argument("--save_filepath", default=None)
    parser.add_argument("--request_url", default="https://api.openai.com/v1/embeddings")
    parser.add_argument("--api_key", default=os.getenv("OPENAI_API_KEY"))
    parser.add_argument("--max_requests_per_minute", type=int, default=3_000 * 0.5)
    parser.add_argument("--max_tokens_per_minute", type=int, default=250_000 * 0.5)
    parser.add_argument("--token_encoding_name", default="cl100k_base")
    parser.add_argument("--max_attempts", type=int, default=5)
    parser.add_argument("--logging_level", default=logging.INFO)
    args = parser.parse_args()

    if args.save_filepath is None:
        args.save_filepath = args.requests_filepath.replace(".jsonl", "_results.jsonl")

    # run script
    asyncio.run(
        process_api_requests_from_file(
            requests_filepath=args.requests_filepath,
            save_filepath=args.save_filepath,
            request_url=args.request_url,
            api_key=args.api_key,
            max_requests_per_minute=float(args.max_requests_per_minute),
            max_tokens_per_minute=float(args.max_tokens_per_minute),
            token_encoding_name=args.token_encoding_name,
            max_attempts=int(args.max_attempts),
            logging_level=int(args.logging_level),
        )
    )

# %%

# %%


================================================
FILE: 06장/chapter_6.ipynb
================================================
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "PwfomfP4tRe6"
   },
   "outputs": [],
   "source": [
    "!pip install transformers==4.40.1 bitsandbytes==0.43.1 accelerate==0.29.3 datasets==2.19.0 tiktoken==0.6.0 huggingface_hub==0.22.2 autotrain-advanced==0.7.77 -qqq\n",
    "!pip install --upgrade huggingface-hub -qqq"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.2. SQL 프롬프트"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "iDNZcQfstivr"
   },
   "outputs": [],
   "source": [
    "def make_prompt(ddl, question, query=''):\n",
    "    prompt = f\"\"\"당신은 SQL을 생성하는 SQL 봇입니다. DDL의 테이블을 활용한 Question을 해결할 수 있는 SQL 쿼리를 생성하세요.\n",
    "\n",
    "### DDL:\n",
    "{ddl}\n",
    "\n",
    "### Question:\n",
    "{question}\n",
    "\n",
    "### SQL:\n",
    "{query}\"\"\"\n",
    "    return prompt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.4. 평가를 위한 요청 jsonl 작성 함수"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "2ondFOp7tmAM"
   },
   "outputs": [],
   "source": [
    "import json\n",
    "import pandas as pd\n",
    "from pathlib import Path\n",
    "\n",
    "def make_requests_for_gpt_evaluation(df, filename, dir='requests'):\n",
    "  if not Path(dir).exists():\n",
    "      Path(dir).mkdir(parents=True)\n",
    "  prompts = []\n",
    "  for idx, row in df.iterrows():\n",
    "      prompts.append(\"\"\"Based on below DDL and Question, evaluate gen_sql can resolve Question. If gen_sql and gt_sql do equal job, return \"yes\" else return \"no\". Output JSON Format: {\"resolve_yn\": \"\"}\"\"\" + f\"\"\"\n",
    "\n",
    "DDL: {row['context']}\n",
    "Question: {row['question']}\n",
    "gt_sql: {row['answer']}\n",
    "gen_sql: {row['gen_sql']}\"\"\"\n",
    ")\n",
    "\n",
    "  jobs = [{\"model\": \"gpt-4-turbo-preview\", \"response_format\" : { \"type\": \"json_object\" }, \"messages\": [{\"role\": \"system\", \"content\": prompt}]} for prompt in prompts]\n",
    "  with open(Path(dir, filename), \"w\") as f:\n",
    "      for job in jobs:\n",
    "          json_string = json.dumps(job)\n",
    "          f.write(json_string + \"\\n\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.5. 비동기 요청 명령"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "7onIkAWutnrQ"
   },
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ[\"OPENAI_API_KEY\"] = \"자신의 OpenAI API 키 입력\"\n",
    "\n",
    "python api_request_parallel_processor.py \\\n",
    "  --requests_filepath {요청 파일 경로} \\\n",
    "  --save_filepath {생성할 결과 파일 경로} \\\n",
    "  --request_url https://api.openai.com/v1/chat/completions \\\n",
    "  --max_requests_per_minute 300 \\\n",
    "  --max_tokens_per_minute 100000 \\\n",
    "  --token_encoding_name cl100k_base \\\n",
    "  --max_attempts 5 \\\n",
    "  --logging_level 20"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.6. 결과 jsonl 파일을 csv로 변환하는 함수"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "1QhfH5vVtqNr"
   },
   "outputs": [],
   "source": [
    "def change_jsonl_to_csv(input_file, output_file, prompt_column=\"prompt\", response_column=\"response\"):\n",
    "    prompts = []\n",
    "    responses = []\n",
    "    with open(input_file, 'r') as json_file:\n",
    "        for data in json_file:\n",
    "            prompts.append(json.loads(data)[0]['messages'][0]['content'])\n",
    "            responses.append(json.loads(data)[1]['choices'][0]['message']['content'])\n",
    "\n",
    "    df = pd.DataFrame({prompt_column: prompts, response_column: responses})\n",
    "    df.to_csv(output_file, index=False)\n",
    "    return df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.7. 기초 모델로 생성하기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "zYtqMd4ztuGX"
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "from transformers import pipeline, AutoTokenizer, AutoModelForCausalLM\n",
    "\n",
    "def make_inference_pipeline(model_id):\n",
    "  tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
    "  model = AutoModelForCausalLM.from_pretrained(model_id, device_map=\"auto\", load_in_4bit=True, bnb_4bit_compute_dtype=torch.float16)\n",
    "  pipe = pipeline(\"text-generation\", model=model, tokenizer=tokenizer)\n",
    "  return pipe\n",
    "\n",
    "model_id = 'beomi/Yi-Ko-6B'\n",
    "hf_pipe = make_inference_pipeline(model_id)\n",
    "\n",
    "example = \"\"\"당신은 SQL을 생성하는 SQL 봇입니다. DDL의 테이블을 활용한 Question을 해결할 수 있는 SQL 쿼리를 생성하세요.\n",
    "\n",
    "### DDL:\n",
    "CREATE TABLE players (\n",
    "  player_id INT PRIMARY KEY AUTO_INCREMENT,\n",
    "  username VARCHAR(255) UNIQUE NOT NULL,\n",
    "  email VARCHAR(255) UNIQUE NOT NULL,\n",
    "  password_hash VARCHAR(255) NOT NULL,\n",
    "  date_joined DATETIME NOT NULL,\n",
    "  last_login DATETIME\n",
    ");\n",
    "\n",
    "### Question:\n",
    "사용자 이름에 'admin'이 포함되어 있는 계정의 수를 알려주세요.\n",
    "\n",
    "### SQL:\n",
    "\"\"\"\n",
    "\n",
    "hf_pipe(example, do_sample=False,\n",
    "    return_full_text=False, max_length=512, truncation=True)\n",
    "#  SELECT COUNT(*) FROM players WHERE username LIKE '%admin%';\n",
    "\n",
    "# ### SQL 봇:\n",
    "# SELECT COUNT(*) FROM players WHERE username LIKE '%admin%';\n",
    "\n",
    "# ### SQL 봇의 결과:\n",
    "# SELECT COUNT(*) FROM players WHERE username LIKE '%admin%'; (생략)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.8. 기초 모델 성능 측정"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "!mkdir results"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "GNIR_bartwIA"
   },
   "outputs": [],
   "source": [
    "from datasets import load_dataset\n",
    "# 데이터셋 불러오기\n",
    "df = load_dataset(\"shangrilar/ko_text2sql\", \"origin\")['test']\n",
    "df = df.to_pandas()\n",
    "for idx, row in df.iterrows():\n",
    "  prompt = make_prompt(row['context'], row['question'])\n",
    "  df.loc[idx, 'prompt'] = prompt\n",
    "# sql 생성\n",
    "gen_sqls = hf_pipe(df['prompt'].tolist(), do_sample=False,\n",
    "                   return_full_text=False, max_length=512, truncation=True)\n",
    "gen_sqls = [x[0]['generated_text'] for x in gen_sqls]\n",
    "df['gen_sql'] = gen_sqls\n",
    "\n",
    "# 평가를 위한 requests.jsonl 생성\n",
    "eval_filepath = \"text2sql_evaluation.jsonl\"\n",
    "make_requests_for_gpt_evaluation(df, eval_filepath)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "_5-D5us7yiuE"
   },
   "outputs": [],
   "source": [
    "# GPT-4 평가 수행\n",
    "!python api_request_parallel_processor.py \\\n",
    "--requests_filepath requests/{eval_filepath}  \\\n",
    "--save_filepath results/{eval_filepath} \\\n",
    "--request_url https://api.openai.com/v1/chat/completions \\\n",
    "--max_requests_per_minute 2500 \\\n",
    "--max_tokens_per_minute 100000 \\\n",
    "--token_encoding_name cl100k_base \\\n",
    "--max_attempts 5 \\\n",
    "--logging_level 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "Oj3yhtKMxnaO"
   },
   "outputs": [],
   "source": [
    "base_eval = change_jsonl_to_csv(f\"results/{eval_filepath}\", \"results/yi_ko_6b_eval.csv\", \"prompt\", \"resolve_yn\")\n",
    "base_eval['resolve_yn'] = base_eval['resolve_yn'].apply(lambda x: json.loads(x)['resolve_yn'])\n",
    "num_correct_answers = base_eval.query(\"resolve_yn == 'yes'\").shape[0]\n",
    "num_correct_answers"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.9. 학습 데이터 불러오기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "qzho0PYKt2O9"
   },
   "outputs": [],
   "source": [
    "from datasets import load_dataset\n",
    "\n",
    "df_sql = load_dataset(\"shangrilar/ko_text2sql\", \"origin\")[\"train\"]\n",
    "df_sql = df_sql.to_pandas()\n",
    "df_sql = df_sql.dropna().sample(frac=1, random_state=42)\n",
    "df_sql = df_sql.query(\"db_id != 1\")\n",
    "\n",
    "for idx, row in df_sql.iterrows():\n",
    "  df_sql.loc[idx, 'text'] = make_prompt(row['context'], row['question'], row['answer'])\n",
    "\n",
    "!mkdir data\n",
    "df_sql.to_csv('data/train.csv', index=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.10. 미세 조정 명령어"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "XGvS0jdouIiu"
   },
   "outputs": [],
   "source": [
    "base_model = 'beomi/Yi-Ko-6B'\n",
    "finetuned_model = 'yi-ko-6b-text2sql'\n",
    "\n",
    "!autotrain llm \\\n",
    "--train \\\n",
    "--model {base_model} \\\n",
    "--project-name {finetuned_model} \\\n",
    "--data-path data/ \\\n",
    "--text-column text \\\n",
    "--lr 2e-4 \\\n",
    "--batch-size 8 \\\n",
    "--epochs 1 \\\n",
    "--block-size 1024 \\\n",
    "--warmup-ratio 0.1 \\\n",
    "--lora-r 16 \\\n",
    "--lora-alpha 32 \\\n",
    "--lora-dropout 0.05 \\\n",
    "--weight-decay 0.01 \\\n",
    "--gradient-accumulation 8 \\\n",
    "--mixed-precision fp16 \\\n",
    "--use-peft \\\n",
    "--quantization int4 \\\n",
    "--trainer sft"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.11. LoRA 어댑터 결합 및 허깅페이스 허브 업로드"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "liLEbS40uVy_"
   },
   "outputs": [],
   "source": [
    "import torch\n",
    "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
    "from peft import LoraConfig, PeftModel\n",
    "\n",
    "model_name = base_model\n",
    "device_map = {\"\": 0}\n",
    "\n",
    "# LoRA와 기초 모델 파라미터 합치기\n",
    "base_model = AutoModelForCausalLM.from_pretrained(\n",
    "    model_name,\n",
    "    low_cpu_mem_usage=True,\n",
    "    return_dict=True,\n",
    "    torch_dtype=torch.float16,\n",
    "    device_map=device_map,\n",
    ")\n",
    "model = PeftModel.from_pretrained(base_model, finetuned_model)\n",
    "model = model.merge_and_unload()\n",
    "\n",
    "# 토크나이저 설정\n",
    "tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)\n",
    "tokenizer.pad_token = tokenizer.eos_token\n",
    "tokenizer.padding_side = \"right\"\n",
    "\n",
    "# 허깅페이스 허브에 모델 및 토크나이저 저장\n",
    "model.push_to_hub(finetuned_model, use_temp_dir=False)\n",
    "tokenizer.push_to_hub(finetuned_model, use_temp_dir=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.12. 미세 조정한 모델로 예시 데이터에 대한 SQL 생성"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "9x_Num7auXPu"
   },
   "outputs": [],
   "source": [
    "model_id = \"shangrilar/yi-ko-6b-text2sql\"\n",
    "hf_pipe = make_inference_pipeline(model_id)\n",
    "\n",
    "hf_pipe(example, do_sample=False,\n",
    "       return_full_text=False, max_length=1024, truncation=True)\n",
    "# SELECT COUNT(*) FROM players WHERE username LIKE '%admin%';"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 6.13. 미세 조정한 모델 성능 측정"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "fQblRmRjubVJ"
   },
   "outputs": [],
   "source": [
    "# sql 생성 수행\n",
    "gen_sqls = hf_pipe(df['prompt'].tolist(), do_sample=False,\n",
    "                   return_full_text=False, max_length=1024, truncation=True)\n",
    "gen_sqls = [x[0]['generated_text'] for x in gen_sqls]\n",
    "df['gen_sql'] = gen_sqls\n",
    "\n",
    "# 평가를 위한 requests.jsonl 생성\n",
    "ft_eval_filepath = \"text2sql_evaluation_finetuned.jsonl\"\n",
    "make_requests_for_gpt_evaluation(df, ft_eval_filepath)\n",
    "\n",
    "# GPT-4 평가 수행\n",
    "!python api_request_parallel_processor.py \\\n",
    "  --requests_filepath requests/{ft_eval_filepath} \\\n",
    "  --save_filepath results/{ft_eval_filepath} \\\n",
    "  --request_url https://api.openai.com/v1/chat/completions \\\n",
    "  --max_requests_per_minute 2500 \\\n",
    "  --max_tokens_per_minute 100000 \\\n",
    "  --token_encoding_name cl100k_base \\\n",
    "  --max_attempts 5 \\\n",
    "  --logging_level 20"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "id": "5zPKM-xfvlrf"
   },
   "outputs": [],
   "source": [
    "ft_eval = change_jsonl_to_csv(f\"results/{ft_eval_filepath}\", \"results/yi_ko_6b_eval.csv\", \"prompt\", \"resolve_yn\")\n",
    "ft_eval['resolve_yn'] = ft_eval['resolve_yn'].apply(lambda x: json.loads(x)['resolve_yn'])\n",
    "num_correct_answers = ft_eval.query(\"resolve_yn == 'yes'\").shape[0]\n",
    "num_correct_answers"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "gpuType": "T4",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}


================================================
FILE: 06장/utils.py
================================================
import json
import pandas as pd


def change_jsonl_to_csv(input_file, output_file, prompt_column="prompt", response_column="response"):
    prompts = []
    responses = []
    with open(input_file, 'r') as json_file:
        for data in json_file:
            prompts.append(json.loads(data)[0]['messages'][0]['content'])
            responses.append(json.loads(data)[1]['choices'][0]['message']['content'])

    df = pd.DataFrame({prompt_column: prompts, response_column: responses})
    df.to_csv(output_file, index=False)
    return df


def merge_gt_and_gen_result(df_gt, df_gen):
    results = []
    for idx, row in df_gen.iterrows():
        with_sql_gt = df_gt.loc[df_gt['without_sql'] == row['without_sql']] 
        gt_sql = with_sql_gt['sql'].values[0]
        gen_sql = row['gen_sql']
        results.append((with_sql_gt['ddl'].values[0], with_sql_gt['request'].values[0], gt_sql, gen_sql))
    df_result = pd.DataFrame(results, columns=["ddl", "request", "gt_sql", "gen_sql"])
    return df_result

def make_evaluation_requests(df, filename, model="gpt-4-1106-preview"):
    prompts = []
    for idx, row in df.iterrows():
        prompts.append(f"""Based on provided ddl, request, gen_sql, ground_truth_sql if gen_sql eqauls to ground_truth_sql, output "yes" else "no"
DDL:
{row['ddl']}
Request:
{row['request']}
ground_truth_sql:
{row['gt_sql']}
gen_sql:
{row['gen_sql']}

Answer:""")

    jobs = [{"model": model, "messages": [{"role": "system", "content": prompt}]} for prompt in prompts]
    with open(filename, "w") as f:
        for job in jobs:
            json_string = json.dumps(job)
            f.write(json_string + "\n")

def make_prompt(ddl, request, sql=""):
    prompt = f"""당신은 SQL을 생성하는 SQL 봇입니다. DDL과 요청사항을 바탕으로 적절한 SQL 쿼리를 생성하세요.

DDL:
{ddl}

요청사항:
{request}

SQL:
{sql}"""
    return prompt


if __name__ == '__main__':
    df = pd.read_csv('./nl2sql_validation.csv')
    df.sample(100).to_csv('nl2sql_validation_sample.csv', index=False)

================================================
FILE: 07장/chapter_7.ipynb
================================================
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "pMEN6Pdhq-3v",
    "outputId": "7708194b-4a1a-460f-c48d-812c1416806b"
   },
   "outputs": [],
   "source": [
    "!pip install transformers==4.40.1 accelerate==0.30.0 bitsandbytes==0.43.1 auto-gptq==0.7.1 autoawq==0.2.5 optimum==1.19.1 -qqq"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "etO0bk4KrMl8",
    "outputId": "045590a6-12bc-4fb6-e9cd-1343e7b43e4c"
   },
   "outputs": [],
   "source": [
    "import transformers\n",
    "import accelerate\n",
    "import bitsandbytes\n",
    "import auto_gptq\n",
    "import awq"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 7.1. 비츠앤바이츠 양자화 모델 불러오기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "oruzQDHHrDCq",
    "outputId": "c344fa0d-0e53-4b94-cda2-01849d49de57"
   },
   "outputs": [],
   "source": [
    "from transformers import AutoModelForCausalLM, BitsAndBytesConfig\n",
    "\n",
    "# 8비트 양자화 모델 불러오기\n",
    "bnb_config_8bit = BitsAndBytesConfig(load_in_8bit=True)\n",
    "model_8bit = AutoModelForCausalLM.from_pretrained(\"facebook/opt-350m\", quantization_config=bnb_config_8bit)\n",
    "\n",
    "# 4비트 양자화 모델 불러오기\n",
    "bnb_config_4bit = BitsAndBytesConfig(load_in_4bit=True,\n",
    "                                     bnb_4bit_quant_type=\"nf4\")\n",
    "\n",
    "model_4bit = AutoModelForCausalLM.from_pretrained(\"facebook/opt-350m\",\n",
    "                                                  low_cpu_mem_usage=True,\n",
    "                                                  quantization_config=bnb_config_4bit)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 7.2. GPTQ 양자화 수행 코드\n",
    "\n",
    "코드 출처: https://huggingface.co/blog/gptq-integration"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 265,
     "referenced_widgets": [
      "3da25351cdb24a58a86989fba6ffb0df",
      "2fea90a5b16541fda21d949baf862963",
      "031d9242e5b04af4b3b56e1be33cb919",
      "593b9ee7599a478ba04fb4f943223e0b",
      "bfd589bc42234266ba83a996de34716c",
      "c64a303eff724161a7f051682fe497d6",
      "e3cd5113956046568fe5764cc7dcc86a",
      "3e114ee0e02547b88ab3f9fcb3762022",
      "ad4a4d15b3c84ccab67c16b906ea35ce",
      "b519f919967a47b2a96c4106b9dc3f6e",
      "51c4b2298bf74f20963afcfff9f7b5b1",
      "5a78f760f77e497fa2ca616a63824e4c",
      "fe9b1c10a39b4794a39fd55c15b733c8",
      "f0f60643e2394036b65ac0ba17bf5671",
      "8a7562b62b9d430b84da3422dad9e199",
      "5b5ff1634a7549e298114e2a99b1496a",
      "962ff8cb96234d4e96fe43905b27dea0",
      "b81ecafcfeec4b6b961ca28c57dff4ca",
      "2043e4a9ff164ecbbce670cacb240a1c",
      "3872878b831a44be947c46f2c0ce7219",
      "50a9ecbb1167421b8758e85f6b1ec1bd",
      "bfb899bc244c4c4a8a7f58b7126c36bd",
      "183e69a1686344b094b45e576ee91153",
      "4ecdbf2489064fe1b8622424671ee964",
      "c2b3d00385de48829fc14101f30c4996",
      "75d2765c285b4cb3a9e870fca981a961",
      "1ae33ccbf3b946348a2247f86e71b0cb",
      "4e5051ffe33e43f19c005aaaac34edb5",
      "3f60e6e946b94fb98a89bed038ac1432",
      "587cef4dfe4a467da1f178b27e1cfe1d",
      "fb13d78c663d4850a34d5475b6d83531",
      "8355627c9b334c45be8250b4cd69a96a",
      "43d68d34c1df44efb46cd8208f8f3486",
      "8c8a6b26d0b8401d8f291f500efafb04",
      "fa09232083974a72992c6b5cdfa10645",
      "9c2dcb8ee47d40d2acf6ef8525c44b41",
      "f0acd027f7fc49669eedd42ebadf3176",
      "fb9061ab8ac84ee0b93c33df0f496f53",
      "10a93e42a3304c969bfa8557a136d045",
      "469629510e564e639b8f7f794e859548",
      "ecdac963a2064b41bf2bab4319d46e31",
      "bb46d4a581974a6eade836ef9d5bf77b",
      "9ce13ac97c5c4082b7d37a462bd29532",
      "db1d7e5f73b0421aab596da309c0d45f",
      "76e8e98dbb8c4165b6f879398e1a9b51",
      "6c989372cc04470eb752fe16fe7d9e2a",
      "d13e78613a82439597dfee5b0b5b4192",
      "1a5e5f90d9cd42f7a10303125f7bc968",
      "899dd463c052482baf91acdff6648383",
      "aa9c1c4acd504798bc38d86c6384b9d0",
      "f102e0825d384b79bd9796b0f027c36c",
      "defeeb14dac14c9f82429e8beae9650d",
      "aad1b2b1527a4c37810ce55ab559949d",
      "4fe079a530ea4513914e3adc6497ccfa",
      "08d60277c2944313bee4a5e6c7541bea",
      "cd2d40b654494de99688c13cb3c0fd75",
      "fb3da81f37fa45198bb9f8a6ff379118",
      "50b540edd8e4499f9a6035d4d30589d1",
      "a4f9d17c92c248edaa4d6a542bcbeb14",
      "5fa32b32e53f4bdb8c0a81cef9d09589",
      "2efb1ecb191148258040532835f1b04d",
      "1ff8c51873ec42fd97294dad506639c0",
      "608ae2fdbd9d4c7486e969b2f2b79fc5",
      "9ec4239108d74f748ffdbdc1d050f0f7",
      "9102ae2dceb649819fa46d735ebb238d",
      "d23494c67e004b77b27859f95724dac8",
      "5126754b520640c681e373669d8ba119",
      "5773d51b00364a2a9bd5339927e1bebf",
      "c6f69996162244be983632dcf652d4c7",
      "3014d796698c40e6892713c4c6b34a5f",
      "d06bae798f2545c2a8f3384161bc5179",
      "c3a0e9ec16ca417992ef522c6f61df8a",
      "ed5bbbe7fc8340a281e8293b54933859",
      "1431e6cebf2c431d82e952b5a76e0b04",
      "30b5dd66ab614e5a9964d8ccee2c835e",
      "00753337770a47fc9e38b62e64b5caf8",
      "356e936b75c34adc8e4da90f725e9524",
      "dcf35a0e07c440a9a8e9d284bfe133b0",
      "cbaff72208494027ab0724dac54ebb66",
      "836c03c4dcbc4efda7849ece476eb30e",
      "f430c5b0a71e45cdb63742eed8e1cfd5",
      "9ce2d522c9064370836e2fe8956b12c8",
      "8e5be8ad20fd4fc185cb726dfb9beaf5",
      "73d7a9888cb240338d82f32f6924cb59",
      "c92a1ce10c49477887a9537f1d2c9b17",
      "e390a1d7f4974a1ba49b22683d7a96c7",
      "9f25a471a45e45ed943f570bbe926641",
      "f4b177db4db74c86a371d827032bb14e",
      "d13781a5fcb6490fa16cfd80a3cba9e0",
      "a058e1db54c84a79b226aad6b4c56c19",
      "1ae1b54e99b3496faa422ca650ca4ee5",
      "a36d11e9b8a9445891b3ece1258f7198",
      "4d9888a12e2e4ff4b70b0527187b6b66",
      "02969ba21a494cc7a51929ba5c47f2a2",
      "f02ebe94bef54aedbd0b107398e772f7",
      "e745afa7113e4323947462758652791e",
      "951241115edc467bbe18c4f75b247a1b",
      "f10e391c557e4b2f98be05505c06c89e",
      "a5612fc3c838456bbc71ef3beabdc6f8",
      "e781045dc03f40d3a094c1c121d6273a",
      "904d94735fb04bb8a3c72ed65f94520d",
      "e4de97af4b0f4a5c8adfeaca0ae1e24b",
      "bc2d0ffe705f423da3b247186ff3caeb",
      "37706a098fbf4b9ba3ee47e2823bf64d",
      "5a513a997a4e4754bc8b93381ba149dc",
      "5dc218c28b2d43888935315fc3b9170b",
      "9766c03104bd46e4b7338fcee3d3574b",
      "bddc28876e9e4f2a923724dfc9a491ec",
      "0379e35322e44b9d997d4f568a85d652",
      "71014fd51a6f4a9db3c59af6b314e22a",
      "e7c7499782e3498c8703e47b31cef653",
      "f95d6f3215a74d6c9378aa98c2614c41",
      "c05bb0415af44e2b8752e57d2800cb3d",
      "d5af9f073de94f44a4f2b65223379f33",
      "76df59c8b29e48f9ba477738f2e080ae",
      "79f9d0c807c44b5b8d6cc306d9151a65",
      "9920deb111b241d0bb302dec90c7055d",
      "00a90c734d1347d4843753bff143aafc",
      "6f6232e1a27f4c9496aa4729ee17942d",
      "cdebe534960a4a60bcbbb3bd189a747b",
      "76da353a2d40435eba000850d4e10560",
      "c39b3fd564734de0bee2c57e602e6219",
      "1f0a1bcdcba44c788d847763797b50c1",
      "bad3567dccfb41c2953b5816b0e6c4a5",
      "61b37f285a844ad6ac8fa44fc3e9f17d",
      "76a73892f3784ef396d21d0223cc7bb7",
      "c7ae45e9dda34c8295afa87dd316ae2d",
      "22b25c1dbd23465eb7b1e4ae7d5240b7",
      "3ff9e06319bf459bb88ada07af16cfa4",
      "df3f3a6590a84621b60d06e6b0fdbd9b",
      "5d63d0bee11b4b2482e17f8d40e34a84",
      "5e648636b6e7471fb90070de4a3be366",
      "f36f566939d3449590e3cc1e5ab50e4e",
      "286ea95ce3d6433cb39ef9b1e90d9a9f",
      "00b460bc702d4c71bff56591536c0629",
      "67690dc1885a421bb91ec5ede9955dfd",
      "0d8757547a464a7088b7367dd0c5be36",
      "a7716843540343c4a2a566ad6b536a6f",
      "44dca45f0a7c4d5da23a9ac367eb55af",
      "7c57815005654e019acd0a8320de5aab",
      "2023d7c5a8634d03896b2dc3ed42bba6",
      "2c4079f6a46e4e33ab8660a6ccd3f44a",
      "d5a3ddfdc8d24add943d84f32cecdd59",
      "e8aa732721a24066bbd348db3991aae6",
      "7cd4c236f14a4853a962cca9fbfc1452",
      "119bfc2e785f4af3b24214046cbd048c",
      "5b6550116b1c4825a61d8f518399e069",
      "640fd42b05cb4b2f86ecef43fa31efa4",
      "747deb347ec24154b5781b8b4be2c0ac",
      "b55b5bbd3e8946db8a2257b256baac07",
      "0a94b2f98d4d482288b956d5807ff282",
      "e0d6d9eae67943d98fd401883ee89db1",
      "b81e30fa3aa64a77b0cbc142bbac7f7d",
      "443b31a1989b4124b9696facdba2b7ab",
      "4bd876ba8b1c41d38341f10079b05d86",
      "3e65f94c78644318bfbc317f0af2a9cc",
      "bd357a59bfb44dfda379ee2865d69395",
      "6df9ef4226bc47808bb02f11b00e8620",
      "b1d12edb78d34f789150a6b5567d08ec",
      "ec143f7c00ad466b933221a49f5d12b7",
      "f240e2a1de144e4682c67668c7c90eac",
      "2cdf89f6e7974cfb88fd0cc1cd4d9760",
      "85a347e956e64142842bbeb8c8b3a619",
      "c44393adff614de7a5cbd30ea730991c",
      "cf1abd80121a4235acd0e6700ec8688d",
      "2c24ab83e40c41549ea30d6b9b2e518e",
      "7e9764092d0c4718ab705cd7ac72844a",
      "9fba87967260497a99727f481f8b8439",
      "99587497525d4e4fa1966b604d325749",
      "ebb480d1bb77470c96f15f929c7874d7",
      "a0899550dfc14aa59700c6773c80e270",
      "5c0e6db9d777466ebaa96b4d5678136e",
      "38316c828bca40539911a89adc96b6e6",
      "fed8415b76a241d08c2dac01c98c4258",
      "006101cf385f4471a6094787b396668d",
      "9e28a920fa4643b08797fc9823b32370",
      "a862e73e082b457aa9628670a1463358",
      "8aec1a3f31c14e4788993ae5327c2422",
      "03b8a5b4d0cb402abede7f2dbe245ea3",
      "b9e4e3ce87cc47cf914f63d7c4830cac",
      "6b903e2c3b024b9981b140bda3f99bf4",
      "37c70567622a47c4af79f52fcb70ccc1",
      "e61d8b1dcc7246aa85f405310175b832",
      "93fe0b2b29be4f0abbc89b233b403eb7",
      "e29cb9e6687146f28e4d9aaf7c3da095",
      "00b961f87e9e4324af6928525fd93aab",
      "d0f52beccdd5452cb3f038672195774a",
      "51779420a08c485ab820b4102eec6859",
      "5bc1751dcce740a590ca507cfc2a05a8",
      "70331a972b874e2ea054689f42666706",
      "ce8f68cdd65c4af2a2522ce5f2a30199",
      "d0c005cdba0a4447b0d369e58d7ec3bb",
      "ba7d055c25d1486d91fbb7d42fb3ef09",
      "ed24eb53c25541e49507b34138630a59",
      "5b9b9aadd7cd4405a6498fc712bb9de7",
      "b372e9bdfa514e9fa149b61164e2ae2d",
      "c98d119697da4ad996027e9bb774ea3d",
      "8a3b7cf5105e49ab8050b32409abde02"
     ]
    },
    "id": "dmy7fV8krIJD",
    "outputId": "a4c8b9df-b0b3-40c9-e613-f28f210ae8c4"
   },
   "outputs": [],
   "source": [
    "from transformers import AutoModelForCausalLM, AutoTokenizer, GPTQConfig\n",
    "\n",
    "model_id = \"facebook/opt-125m\"\n",
    "tokenizer = AutoTokenizer.from_pretrained(model_id)\n",
    "quantization_config = GPTQConfig(bits=4, dataset = \"c4\", tokenizer=tokenizer)\n",
    "\n",
    "model = AutoModelForCausalLM.from_pretrained(model_id, device_map=\"auto\", quantization_config=quantization_config)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 7.3. GPTQ 양자화된 모델 불러오기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/"
    },
    "id": "iTDHvm55rJb-",
    "outputId": "1c4ccfab-97a2-4eee-9c97-5bf5b09a2e55"
   },
   "outputs": [],
   "source": [
    "from transformers import AutoModelForCausalLM\n",
    "model = AutoModelForCausalLM.from_pretrained(\"TheBloke/zephyr-7B-beta-GPTQ\",\n",
    "                                             device_map=\"auto\",\n",
    "                                             trust_remote_code=False,\n",
    "                                             revision=\"main\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 예제 7.4. AWQ 양자화 모델 불러오기"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 501,
     "referenced_widgets": [
      "e112d90c76af48858cbccdb8ae8becde",
      "a913de9d4b054c8fba1f129c387f7c9c",
      "0b2a46e0ccb24cbd862235a4d5821375",
      "c0a1963dee4c4397bc4ad7438addcedd",
      "949d4af656da4a0ca59f5f0742e97543",
      "9ead8ef40da94cee8eaf7878898321a5",
      "12e8cbf10fe94221b9faefc410e6f89b",
      "bbe39dee7dbd484c8ff29513a90834db",
      "1c425f8bf73047eb859f66b25506543d",
      "acc23681c1ff403d890e2e01bf57f813",
      "2bc91270db1a47a4b8a04e4ddf4b215a",
      "f790c98ae35840459e5fc4b44a97a346",
      "33a08f4f18c7409382258d90f455e51b",
      "de90b01ec97440fe925cc7b690f97a0a",
      "8d59c7b2f5924b1190f52ab20bd64bd1",
      "fc9dc8b9d8ca4f7a95c521e5799fdc54",
      "9bea64a6579143d681fa3278bc274c49",
      "f238cd445bf24528b4ede050e204ac42",
      "8f168c783d83495b8da344ade044f377",
      "af3a86ec8d5a42e2ae06deb579880ecc",
      "3e9fbc0e480243f6837c3023483239de",
      "561dab425b7d4d289a2d2fcee8003808",
      "9f358fb57c1c4463b7d34ab4bc833a52",
      "96c0b960f31a4c1fa3e74196d601a898",
      "fd08b096e4ad429d9ec76309fd2d9cb4",
      "04d22d5dbab3412a989b2b7a25c30032",
      "6acc6c02ab34401780fca783deb151de",
      "f6de3d2330474fa2a62949e295ffab9a",
      "9e840421d59f40c8a5882841e23cda27",
      "43bb17b82d7548ae8ae5bdb734914e65",
      "afeb8954861b45d9955f3fad5b556fc8",
      "170d8b408b0b45009612ba89c589d4ae",
      "0fbcfc0db8794bbdb2d6f9b4dc491491",
      "0ad0569269e448a1a58ef5345185c819",
      "ae3a0a0c48814d7b88efc19135cfffd2",
      "839582d23eb5443ea23d488bdf089d4d",
      "ccfaf53457214184b5bcd2ac3f39ce0b",
      "f9eb1710cc21465e9584d992b2533b9d",
      "225ffd28a3074879b7b3ceed6d343c5b",
      "76e7496e8d194daba0a53963fbc6f80e",
      "3660d04fb7574b27a87c33c1c6da4f72",
      "85c210d2543e4fc3b18294b6486a2915",
      "b77fca4e83a141749c3be03be75a7348",
      "a210c097ccc643eaa8f490ce5f25a78b",
      "bc176941357f4f9e8ac04735d6610a25",
      "3f6c00f79b4a496fb407fbecb1292a22",
      "730bc70699974fa080dc7a000cf4a9fb",
      "606a8e564ce54814b8891a39276d9e32",
      "f854a75862374e8ea580bcb35642b6cf",
      "e94ad0c1c25341c5bed0c7bb12b7cede",
      "8c2ebc0d15b54f568b7c45eddffaca52",
      "aec613a07b4743c382d78d298fa70d95",
      "c61e6b41fa7e4b349664d14bc7edf733",
      "a93c7666ab0a497e879bfbd7545866cb",
      "e85de21fa08545d1ac54be46599176f2",
      "48e5d20385a14b35a329a7ceeeb621e6",
      "bdd78a0511e844c0ab375b9454bf1414",
      "6b57906545f64fe9bc89f7e52b11c780",
      "62789e2f3ff84c1fab139e8c7b0dcc75",
      "c7bafd2825f94300bf48a75bd22422ac",
      "960bab7c9ef14445a848899fb2309c39",
      "ecaefd3ed6a74a6ebc7696443c525b62",
      "67995fba23754b5caaf4b04b79705cf5",
      "0fd57b29c05c4664a2a6f315a73dfbef",
      "a4ec6e56666b4f16bb99b9a196e8f8bb",
      "26caed91d77340de9ee051cf4c038d72",
      "75419fb9856d474db3fb073b12d3d03c",
      "6cedd130460a41ec8641c99659f5d8b3",
      "3907885bbb09422f927c2fcdfd39ac57",
      "f50f2a17dad34015a313d2587045f6ca",
      "4f32068c4ab94e08b82cb01f74cf0c7e",
      "0b21626e6db94248987da65406aefa95",
      "16e898adcd0b4da3b3d25df79c899f8e",
      "6af3860327504d9eb9c0e548e4ac0362",
      "6a5e72e21d364f2c909a8dd332cdeea6",
      "eb8cfb0881ce4a4786dc7711fe995f82",
      "ab85ab8b010349ffacfeec2ed4a99e07",
      "d47a1acc92004f8f83320321d4626dbc",
      "ae3f4b9b819d4c3bb57550d99bfda4c1",
      "880387a832234202b4d09af90e9bfe39",
      "f5b2752c2bfd4c858660248ed801bff7",
      "d93e7f8712b24ce392b0d669e1d642e7",
      "e93e37d416ac4e38876100fdf5ec327d",
      "d12f9f3c6d7b49c88fd685c95b1dc7da",
      "e88b47c5c19f463f9c9e1037e058e9db",
      "f3ec83cb5978437fbe3c16e8fe7998b8",
      "df3d35f9799a4e9e9c46dd26317f7837",
      "f6e0cbcffc9e40e2918ad6e1043ae5b3",
      "2e1cc51431b24272b106e069c11d19d2",
      "d279505386c94a09a45f948722791c8f",
      "c79d942f480e484f9bc4405fb9e622c7",
      "228d7b6c6320435b909aefcd4c6b6aa3",
      "79f8a01a92ab4e7a934b31b30c564d57",
      "b2e5ce3c72f84f9180e5899dc7b83c7b",
      "55131198b7324bc48ff089f02031667b",
      "09b61548098a4f20a107f16daf10683f",
      "b5f2e73f77ff4ba1af916b87f29aa7e8",
      "ecb66d8fa36345acb1b2d54314be551d",
      "e66b09e35c9543119232c83191e69ba0",
      "ce46e90dd7e8487daf109d3f83c14306",
      "f189ffd414f44a60a0e0bb1a435ab89f",
      "b865dc974a0a45429aa683d99858ad08",
      "16ba6e8ea9c747f98d9bfa954a03a731",
      "70a0646d9f6c4c96b6cd5b45082dae70",
      "3f449df08a284548bf28b594174eadbe",
      "6d804da0dca3470bb60c563e048bd1b9",
      "0a58b3f040b0461eaa6ba9098d7b0eb5",
      "eadcb24fc0eb4b12adfd015a4f503d22",
      "34955eb9198e464eacffef4ad05e6246",
      "2445110e0b5f401fbfe9c81da8203816",
      "7a7547ce47dc4c3282e71d6a781f0c59",
      "47ae7b5a7d564459badcb026a5a0283a",
      "e7bce84f4aec4a44a1f0a90b31458a32",
      "0cf849bb3d13483cba5a153710adc89a",
      "e5932c6ef6fd4f149ef149954fc42bf0",
      "883c6aeb79bc41c58b70e5ba708e3690",
      "ac9de85329c34e359e229f946b15c399",
      "0bf65075b5124561aa7dd5a83176a5dd",
      "9d3a4826559a4105931bc8772ac51c30",
      "5f5e773eba6d47ecb9a097ddf7e75ae9",
      "f3bddd96d286438f88e35e6e73e15a55",
      "a508b12aa15c43bf8e14ffe1ba0c49f1",
      "b5796ea75f7244dabe9cfb3110417d22",
      "f30df45b0f0d45eb874e0ec03d3f3c57",
      "da166da9c7f7486fad1d96a4c8153578",
      "06f82bb068794f0589d57c6d042c2df6",
      "b7ecc9a611114736beafb27b48490306",
      "4f71eaa053204a5abe06358f97af3cd9",
      "96dffa08cdfb41819c6d09f9c8472171",
      "0342ed06971a4acb8ef5c81908a56b98",
      "68b9b5afe07f4209b0d723fa2de82762",
      "46b7a6dfe6b043fdb11cfe5543e63aa2",
      "6993108029c3468aa18191bc183ef450",
      "b78122aa1d894a2fb37c5bbf1cc6941e",
      "cbb8b9539bcb47919c843643d03ba860",
      "bd2b7944e9104c71914587ef3bef47ae",
      "b47339d4ed0345f68ec83a5af74d70c0",
      "a6da844e6cb149c88cef92ce9b5c5c1c",
      "0f919598ceec4f71a7758d213e8598b0",
      "7e17999a54e040d693dd68c48fe7a965",
      "ab0cd3ee496f44ad99664e4f1b02d73b",
      "7712f9797b8349b0bb13fe4bc121caec",
      "b95abf5865064a719941a30f6bca3921",
      "fe8b292fd2e0441fbf3c30402965fa0f",
      "6efa1259b2b24bd884866c12602f2027",
      "b71997abef3746edbb7154383559d3a4",
      "f010dc2e01ac4711a5b6dec871bcdfbd",
      "04ea403eeeae4406a9713d2bc9a7f685",
      "d2868a732b4741a8a294e9e3ae7a750e",
      "7a5c7c99d7a747d681d683e068def90d",
      "c5538a55a62a483fb7644331048ae355",
      "a85a019fea414cc28dd6394958d5c745",
      "5f644c52125b45219213ef842cd949a9",
      "7c16dadf0bc143dc9063315f65788f45"
     ]
    },
    "id": "EyomgkqLrLYi",
    "outputId": "8ac445c0-d4bd-417f-94c4-85061cea8395"
   },
   "outputs": [],
   "source": [
    "from awq import AutoAWQForCausalLM\n",
    "from transformers import AutoTokenizer\n",
    "\n",
    "model_name_or_path = \"TheBloke/zephyr-7B-beta-AWQ\"\n",
    "tokenizer = AutoTokenizer.from_pretrained(model_name_or_path, trust_remote_code=False)\n",
    "model = AutoAWQForCausalLM.from_quantized(model_name_or_path, fuse_layers=True, trust_remote_code=False, safetensors=True)"
   ]
  }
 ],
 "metadata": {
  "accelerator": "GPU",
  "colab": {
   "gpuType": "T4",
   "provenance": []
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  },
  "widgets": {
   "application/vnd.jupyter.widget-state+json": {
    "006101cf385f4471a6094787b396668d": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "00753337770a47fc9e38b62e64b5caf8": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "00a90c734d1347d4843753bff143aafc": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "00b460bc702d4c71bff56591536c0629": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_7c57815005654e019acd0a8320de5aab",
      "max": 6,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_2023d7c5a8634d03896b2dc3ed42bba6",
      "value": 6
     }
    },
    "00b961f87e9e4324af6928525fd93aab": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "02969ba21a494cc7a51929ba5c47f2a2": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "031d9242e5b04af4b3b56e1be33cb919": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "success",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_3e114ee0e02547b88ab3f9fcb3762022",
      "max": 250540281,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_ad4a4d15b3c84ccab67c16b906ea35ce",
      "value": 250540281
     }
    },
    "0342ed06971a4acb8ef5c81908a56b98": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "0379e35322e44b9d997d4f568a85d652": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "03b8a5b4d0cb402abede7f2dbe245ea3": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_93fe0b2b29be4f0abbc89b233b403eb7",
      "max": 6,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_e29cb9e6687146f28e4d9aaf7c3da095",
      "value": 6
     }
    },
    "04d22d5dbab3412a989b2b7a25c30032": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_170d8b408b0b45009612ba89c589d4ae",
      "placeholder": "​",
      "style": "IPY_MODEL_0fbcfc0db8794bbdb2d6f9b4dc491491",
      "value": " 1.80M/1.80M [00:00&lt;00:00, 24.5MB/s]"
     }
    },
    "04ea403eeeae4406a9713d2bc9a7f685": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "06f82bb068794f0589d57c6d042c2df6": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "08d60277c2944313bee4a5e6c7541bea": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "09b61548098a4f20a107f16daf10683f": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "0a58b3f040b0461eaa6ba9098d7b0eb5": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "0a94b2f98d4d482288b956d5807ff282": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "0ad0569269e448a1a58ef5345185c819": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_ae3a0a0c48814d7b88efc19135cfffd2",
       "IPY_MODEL_839582d23eb5443ea23d488bdf089d4d",
       "IPY_MODEL_ccfaf53457214184b5bcd2ac3f39ce0b"
      ],
      "layout": "IPY_MODEL_f9eb1710cc21465e9584d992b2533b9d"
     }
    },
    "0b21626e6db94248987da65406aefa95": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "0b2a46e0ccb24cbd862235a4d5821375": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "success",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_bbe39dee7dbd484c8ff29513a90834db",
      "max": 1431,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_1c425f8bf73047eb859f66b25506543d",
      "value": 1431
     }
    },
    "0bf65075b5124561aa7dd5a83176a5dd": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "0cf849bb3d13483cba5a153710adc89a": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_5f5e773eba6d47ecb9a097ddf7e75ae9",
      "placeholder": "​",
      "style": "IPY_MODEL_f3bddd96d286438f88e35e6e73e15a55",
      "value": " 195/195 [00:00&lt;00:00, 2.18kB/s]"
     }
    },
    "0d8757547a464a7088b7367dd0c5be36": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": "hidden",
      "width": null
     }
    },
    "0f919598ceec4f71a7758d213e8598b0": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "0fbcfc0db8794bbdb2d6f9b4dc491491": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "0fd57b29c05c4664a2a6f315a73dfbef": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "10a93e42a3304c969bfa8557a136d045": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "119bfc2e785f4af3b24214046cbd048c": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_0a94b2f98d4d482288b956d5807ff282",
      "max": 6,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_e0d6d9eae67943d98fd401883ee89db1",
      "value": 6
     }
    },
    "12e8cbf10fe94221b9faefc410e6f89b": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "1431e6cebf2c431d82e952b5a76e0b04": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "16ba6e8ea9c747f98d9bfa954a03a731": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_34955eb9198e464eacffef4ad05e6246",
      "placeholder": "​",
      "style": "IPY_MODEL_2445110e0b5f401fbfe9c81da8203816",
      "value": " 116/116 [00:00&lt;00:00, 1.43kB/s]"
     }
    },
    "16e898adcd0b4da3b3d25df79c899f8e": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "170d8b408b0b45009612ba89c589d4ae": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "183e69a1686344b094b45e576ee91153": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_4ecdbf2489064fe1b8622424671ee964",
       "IPY_MODEL_c2b3d00385de48829fc14101f30c4996",
       "IPY_MODEL_75d2765c285b4cb3a9e870fca981a961"
      ],
      "layout": "IPY_MODEL_1ae33ccbf3b946348a2247f86e71b0cb"
     }
    },
    "1a5e5f90d9cd42f7a10303125f7bc968": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_4fe079a530ea4513914e3adc6497ccfa",
      "placeholder": "​",
      "style": "IPY_MODEL_08d60277c2944313bee4a5e6c7541bea",
      "value": " 356317/0 [00:13&lt;00:00, 32246.72 examples/s]"
     }
    },
    "1ae1b54e99b3496faa422ca650ca4ee5": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_e745afa7113e4323947462758652791e",
      "max": 6,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_951241115edc467bbe18c4f75b247a1b",
      "value": 6
     }
    },
    "1ae33ccbf3b946348a2247f86e71b0cb": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "1c425f8bf73047eb859f66b25506543d": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "1f0a1bcdcba44c788d847763797b50c1": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_c7ae45e9dda34c8295afa87dd316ae2d",
      "placeholder": "​",
      "style": "IPY_MODEL_22b25c1dbd23465eb7b1e4ae7d5240b7",
      "value": "Quantizing layers inside the block: 100%"
     }
    },
    "1ff8c51873ec42fd97294dad506639c0": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "2023d7c5a8634d03896b2dc3ed42bba6": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "2043e4a9ff164ecbbce670cacb240a1c": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "225ffd28a3074879b7b3ceed6d343c5b": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "228d7b6c6320435b909aefcd4c6b6aa3": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_ecb66d8fa36345acb1b2d54314be551d",
      "placeholder": "​",
      "style": "IPY_MODEL_e66b09e35c9543119232c83191e69ba0",
      "value": " 728/728 [00:00&lt;00:00, 6.04kB/s]"
     }
    },
    "22b25c1dbd23465eb7b1e4ae7d5240b7": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "2445110e0b5f401fbfe9c81da8203816": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "26caed91d77340de9ee051cf4c038d72": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "286ea95ce3d6433cb39ef9b1e90d9a9f": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_a7716843540343c4a2a566ad6b536a6f",
      "placeholder": "​",
      "style": "IPY_MODEL_44dca45f0a7c4d5da23a9ac367eb55af",
      "value": "Quantizing layers inside the block: 100%"
     }
    },
    "2bc91270db1a47a4b8a04e4ddf4b215a": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "2c24ab83e40c41549ea30d6b9b2e518e": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_7e9764092d0c4718ab705cd7ac72844a",
       "IPY_MODEL_9fba87967260497a99727f481f8b8439",
       "IPY_MODEL_99587497525d4e4fa1966b604d325749"
      ],
      "layout": "IPY_MODEL_ebb480d1bb77470c96f15f929c7874d7"
     }
    },
    "2c4079f6a46e4e33ab8660a6ccd3f44a": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "2cdf89f6e7974cfb88fd0cc1cd4d9760": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "2e1cc51431b24272b106e069c11d19d2": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_d279505386c94a09a45f948722791c8f",
       "IPY_MODEL_c79d942f480e484f9bc4405fb9e622c7",
       "IPY_MODEL_228d7b6c6320435b909aefcd4c6b6aa3"
      ],
      "layout": "IPY_MODEL_79f8a01a92ab4e7a934b31b30c564d57"
     }
    },
    "2efb1ecb191148258040532835f1b04d": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "2fea90a5b16541fda21d949baf862963": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_c64a303eff724161a7f051682fe497d6",
      "placeholder": "​",
      "style": "IPY_MODEL_e3cd5113956046568fe5764cc7dcc86a",
      "value": "pytorch_model.bin: 100%"
     }
    },
    "3014d796698c40e6892713c4c6b34a5f": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_00753337770a47fc9e38b62e64b5caf8",
      "placeholder": "​",
      "style": "IPY_MODEL_356e936b75c34adc8e4da90f725e9524",
      "value": " 6/6 [00:12&lt;00:00,  2.23s/it]"
     }
    },
    "30b5dd66ab614e5a9964d8ccee2c835e": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "33a08f4f18c7409382258d90f455e51b": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_9bea64a6579143d681fa3278bc274c49",
      "placeholder": "​",
      "style": "IPY_MODEL_f238cd445bf24528b4ede050e204ac42",
      "value": "tokenizer.model: 100%"
     }
    },
    "34955eb9198e464eacffef4ad05e6246": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "356e936b75c34adc8e4da90f725e9524": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "3660d04fb7574b27a87c33c1c6da4f72": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "37706a098fbf4b9ba3ee47e2823bf64d": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": "hidden",
      "width": null
     }
    },
    "37c70567622a47c4af79f52fcb70ccc1": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "38316c828bca40539911a89adc96b6e6": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "3872878b831a44be947c46f2c0ce7219": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "ProgressStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "ProgressStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "bar_color": null,
      "description_width": ""
     }
    },
    "3907885bbb09422f927c2fcdfd39ac57": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "FloatProgressModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "FloatProgressModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "ProgressView",
      "bar_style": "success",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_6af3860327504d9eb9c0e548e4ac0362",
      "max": 90,
      "min": 0,
      "orientation": "horizontal",
      "style": "IPY_MODEL_6a5e72e21d364f2c909a8dd332cdeea6",
      "value": 90
     }
    },
    "3da25351cdb24a58a86989fba6ffb0df": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_2fea90a5b16541fda21d949baf862963",
       "IPY_MODEL_031d9242e5b04af4b3b56e1be33cb919",
       "IPY_MODEL_593b9ee7599a478ba04fb4f943223e0b"
      ],
      "layout": "IPY_MODEL_bfd589bc42234266ba83a996de34716c"
     }
    },
    "3e114ee0e02547b88ab3f9fcb3762022": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "3e65f94c78644318bfbc317f0af2a9cc": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_ec143f7c00ad466b933221a49f5d12b7",
      "placeholder": "​",
      "style": "IPY_MODEL_f240e2a1de144e4682c67668c7c90eac",
      "value": "Quantizing layers inside the block: 100%"
     }
    },
    "3e9fbc0e480243f6837c3023483239de": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "3f449df08a284548bf28b594174eadbe": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "3f60e6e946b94fb98a89bed038ac1432": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "3f6c00f79b4a496fb407fbecb1292a22": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_e94ad0c1c25341c5bed0c7bb12b7cede",
      "placeholder": "​",
      "style": "IPY_MODEL_8c2ebc0d15b54f568b7c45eddffaca52",
      "value": "config.json: 100%"
     }
    },
    "3ff9e06319bf459bb88ada07af16cfa4": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "43bb17b82d7548ae8ae5bdb734914e65": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "43d68d34c1df44efb46cd8208f8f3486": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "443b31a1989b4124b9696facdba2b7ab": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "44dca45f0a7c4d5da23a9ac367eb55af": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "469629510e564e639b8f7f794e859548": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "46b7a6dfe6b043fdb11cfe5543e63aa2": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "47ae7b5a7d564459badcb026a5a0283a": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_883c6aeb79bc41c58b70e5ba708e3690",
      "placeholder": "​",
      "style": "IPY_MODEL_ac9de85329c34e359e229f946b15c399",
      "value": "train_results.json: 100%"
     }
    },
    "48e5d20385a14b35a329a7ceeeb621e6": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_bdd78a0511e844c0ab375b9454bf1414",
       "IPY_MODEL_6b57906545f64fe9bc89f7e52b11c780",
       "IPY_MODEL_62789e2f3ff84c1fab139e8c7b0dcc75"
      ],
      "layout": "IPY_MODEL_c7bafd2825f94300bf48a75bd22422ac"
     }
    },
    "4bd876ba8b1c41d38341f10079b05d86": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HBoxModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HBoxModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HBoxView",
      "box_style": "",
      "children": [
       "IPY_MODEL_3e65f94c78644318bfbc317f0af2a9cc",
       "IPY_MODEL_bd357a59bfb44dfda379ee2865d69395",
       "IPY_MODEL_6df9ef4226bc47808bb02f11b00e8620"
      ],
      "layout": "IPY_MODEL_b1d12edb78d34f789150a6b5567d08ec"
     }
    },
    "4d9888a12e2e4ff4b70b0527187b6b66": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": "hidden",
      "width": null
     }
    },
    "4e5051ffe33e43f19c005aaaac34edb5": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "4ecdbf2489064fe1b8622424671ee964": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "HTMLModel",
     "state": {
      "_dom_classes": [],
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "HTMLModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/controls",
      "_view_module_version": "1.5.0",
      "_view_name": "HTMLView",
      "description": "",
      "description_tooltip": null,
      "layout": "IPY_MODEL_4e5051ffe33e43f19c005aaaac34edb5",
      "placeholder": "​",
      "style": "IPY_MODEL_3f60e6e946b94fb98a89bed038ac1432",
      "value": "Downloading readme: 100%"
     }
    },
    "4f32068c4ab94e08b82cb01f74cf0c7e": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": null,
      "grid_auto_flow": null,
      "grid_auto_rows": null,
      "grid_column": null,
      "grid_gap": null,
      "grid_row": null,
      "grid_template_areas": null,
      "grid_template_columns": null,
      "grid_template_rows": null,
      "height": null,
      "justify_content": null,
      "justify_items": null,
      "left": null,
      "margin": null,
      "max_height": null,
      "max_width": null,
      "min_height": null,
      "min_width": null,
      "object_fit": null,
      "object_position": null,
      "order": null,
      "overflow": null,
      "overflow_x": null,
      "overflow_y": null,
      "padding": null,
      "right": null,
      "top": null,
      "visibility": null,
      "width": null
     }
    },
    "4f71eaa053204a5abe06358f97af3cd9": {
     "model_module": "@jupyter-widgets/controls",
     "model_module_version": "1.5.0",
     "model_name": "DescriptionStyleModel",
     "state": {
      "_model_module": "@jupyter-widgets/controls",
      "_model_module_version": "1.5.0",
      "_model_name": "DescriptionStyleModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "StyleView",
      "description_width": ""
     }
    },
    "4fe079a530ea4513914e3adc6497ccfa": {
     "model_module": "@jupyter-widgets/base",
     "model_module_version": "1.2.0",
     "model_name": "LayoutModel",
     "state": {
      "_model_module": "@jupyter-widgets/base",
      "_model_module_version": "1.2.0",
      "_model_name": "LayoutModel",
      "_view_count": null,
      "_view_module": "@jupyter-widgets/base",
      "_view_module_version": "1.2.0",
      "_view_name": "LayoutView",
      "align_content": null,
      "align_items": null,
      "align_self": null,
      "border": null,
      "bottom": null,
      "display": null,
      "flex": null,
      "flex_flow": null,
      "grid_area": null,
      "grid_auto_columns": n
Download .txt
gitextract_axs9sb0j/

├── 02장/
│   └── chapter_2_transformer_with_code.ipynb
├── 03장/
│   └── chapter_3.ipynb
├── 05장/
│   └── chapter_5.ipynb
├── 06장/
│   ├── api_request_parallel_processor.py
│   ├── chapter_6.ipynb
│   └── utils.py
├── 07장/
│   └── chapter_7.ipynb
├── 08장/
│   └── chapter_8.ipynb
├── 09장/
│   └── chapter_9.ipynb
├── 10장/
│   └── chapter_10.ipynb
├── 11장/
│   └── chapter_11.ipynb
├── 12장/
│   └── chapter_12.ipynb
├── 14장/
│   └── chapter_14.ipynb
├── 15장/
│   └── chapter_15.ipynb
├── 16장/
│   └── chapter_16.ipynb
└── README.md
Download .txt
SYMBOL INDEX (12 symbols across 2 files)

FILE: 06장/api_request_parallel_processor.py
  function process_api_requests_from_file (line 18) | async def process_api_requests_from_file(
  class StatusTracker (line 186) | class StatusTracker:
  class APIRequest (line 200) | class APIRequest:
    method call_api (line 210) | async def call_api(
  function api_endpoint_from_url (line 277) | def api_endpoint_from_url(request_url):
  function append_to_jsonl (line 286) | def append_to_jsonl(data, filename: str) -> None:
  function num_tokens_consumed_from_request (line 293) | def num_tokens_consumed_from_request(
  function task_id_generator_function (line 352) | def task_id_generator_function():

FILE: 06장/utils.py
  function change_jsonl_to_csv (line 5) | def change_jsonl_to_csv(input_file, output_file, prompt_column="prompt",...
  function merge_gt_and_gen_result (line 18) | def merge_gt_and_gen_result(df_gt, df_gen):
  function make_evaluation_requests (line 28) | def make_evaluation_requests(df, filename, model="gpt-4-1106-preview"):
  function make_prompt (line 49) | def make_prompt(ddl, request, sql=""):
Condensed preview — 16 files, each showing path, character count, and a content snippet. Download the .json file or copy for the full structured content (1,046K chars).
[
  {
    "path": "02장/chapter_2_transformer_with_code.ipynb",
    "chars": 15117,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {\n    \"id\": \"mr7FmYqAi6y2\"\n   },\n   \"source\": [\n    \"## 예제 "
  },
  {
    "path": "03장/chapter_3.ipynb",
    "chars": 27863,
    "preview": "{\n  \"cells\": [\n    {\n      \"cell_type\": \"code\",\n      \"execution_count\": null,\n      \"metadata\": {\n        \"id\": \"8Gd5PV"
  },
  {
    "path": "05장/chapter_5.ipynb",
    "chars": 17549,
    "preview": "{\n  \"cells\": [\n    {\n      \"cell_type\": \"code\",\n      \"execution_count\": null,\n      \"metadata\": {\n        \"id\": \"PJ2VOb"
  },
  {
    "path": "06장/api_request_parallel_processor.py",
    "chars": 16376,
    "preview": "# %%\n# imports\nimport aiohttp  # for making API calls concurrently\nimport argparse  # for running script from command li"
  },
  {
    "path": "06장/chapter_6.ipynb",
    "chars": 13686,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"metadata\": {\n    \"id\": \"PwfomfP4tRe6\"\n   },\n  "
  },
  {
    "path": "06장/utils.py",
    "chars": 1973,
    "preview": "import json\nimport pandas as pd\n\n\ndef change_jsonl_to_csv(input_file, output_file, prompt_column=\"prompt\", response_colu"
  },
  {
    "path": "07장/chapter_7.ipynb",
    "chars": 353538,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"metadata\": {\n    \"colab\": {\n     \"base_uri\": \""
  },
  {
    "path": "08장/chapter_8.ipynb",
    "chars": 166735,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {\n    \"id\": \"_BAOP-OazVQX\",\n    \"colab"
  },
  {
    "path": "09장/chapter_9.ipynb",
    "chars": 104848,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {\n    \"id\": \"lZixmBodbT77\",\n    \"colab"
  },
  {
    "path": "10장/chapter_10.ipynb",
    "chars": 18093,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"metadata\": {\n    \"id\": \"RqusGuvMrhfP\"\n   },\n  "
  },
  {
    "path": "11장/chapter_11.ipynb",
    "chars": 23122,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"metadata\": {\n    \"id\": \"xfGDQ7Yh6oY2\"\n   },\n  "
  },
  {
    "path": "12장/chapter_12.ipynb",
    "chars": 23718,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"metadata\": {\n    \"id\": \"Io5yC7HEZ1R7\"\n   },\n  "
  },
  {
    "path": "14장/chapter_14.ipynb",
    "chars": 92926,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 1,\n   \"metadata\": {\n    \"id\": \"vHbX6lJzZlj8\"\n   },\n   \"o"
  },
  {
    "path": "15장/chapter_15.ipynb",
    "chars": 17680,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": null,\n   \"metadata\": {\n    \"id\": \"2tSxuD4vTjdb\"\n   },\n  "
  },
  {
    "path": "16장/chapter_16.ipynb",
    "chars": 4821,
    "preview": "{\n \"cells\": [\n  {\n   \"cell_type\": \"markdown\",\n   \"id\": \"050fddc7-f38e-415c-8a0c-002ff2d1f222\",\n   \"metadata\": {},\n   \"so"
  },
  {
    "path": "README.md",
    "chars": 8301,
    "preview": "<img src=\"https://img1.daumcdn.net/thumb/R1280x0/?scode=mtistory2&fname=https%3A%2F%2Fblog.kakaocdn.net%2Fdn%2FKsHxQ%2Fb"
  }
]

About this extraction

This page contains the full source code of the onlybooks/llm GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 16 files (885.1 KB), approximately 290.8k tokens, and a symbol index with 12 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.

Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.

Copied to clipboard!