{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "c:\\Users\\X\\Anaconda3\\envs\\llama_factory\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n", " from .autonotebook import tqdm as notebook_tqdm\n" ] } ], "source": [ "import torch\n", "from transformers import AutoModelForCausalLM, AutoTokenizer\n", "from peft import PeftModel, PeftConfig\n", "\n", "device = 'cuda' if torch.cuda.is_available() else 'cpu'" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "model_dir = 'D:/models/Qwen2.5-0.5B'\n", "lora_dir = 'train_2024-09-26-14-50-59'\n", "\n", "# tokenizers should be the same for base and lora models. No adjustments during training.\n", "tokenizer = AutoTokenizer.from_pretrained(model_dir)\n", "\n", "base = AutoModelForCausalLM.from_pretrained(model_dir).to(device)\n", "\n", "model = AutoModelForCausalLM.from_pretrained(model_dir).to(device)\n", "lora = PeftModel.from_pretrained(model, lora_dir).to(device)" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Qwen2ForCausalLM(\n", " (model): Qwen2Model(\n", " (embed_tokens): Embedding(151936, 896)\n", " (layers): ModuleList(\n", " (0-23): 24 x Qwen2DecoderLayer(\n", " (self_attn): Qwen2SdpaAttention(\n", " (q_proj): Linear(in_features=896, out_features=896, bias=True)\n", " (k_proj): Linear(in_features=896, out_features=128, bias=True)\n", " (v_proj): Linear(in_features=896, out_features=128, bias=True)\n", " (o_proj): Linear(in_features=896, out_features=896, bias=False)\n", " (rotary_emb): Qwen2RotaryEmbedding()\n", " )\n", " (mlp): Qwen2MLP(\n", " (gate_proj): Linear(in_features=896, out_features=4864, bias=False)\n", " (up_proj): Linear(in_features=896, out_features=4864, bias=False)\n", " (down_proj): Linear(in_features=4864, out_features=896, bias=False)\n", " (act_fn): SiLU()\n", " )\n", " (input_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n", " (post_attention_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n", " )\n", " )\n", " (norm): Qwen2RMSNorm((896,), eps=1e-06)\n", " )\n", " (lm_head): Linear(in_features=896, out_features=151936, bias=False)\n", ")\n" ] } ], "source": [ "print(base)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Qwen2ForCausalLM(\n", " (model): Qwen2Model(\n", " (embed_tokens): Embedding(151936, 896)\n", " (layers): ModuleList(\n", " (0-23): 24 x Qwen2DecoderLayer(\n", " (self_attn): Qwen2SdpaAttention(\n", " (q_proj): lora.Linear(\n", " (base_layer): Linear(in_features=896, out_features=896, bias=True)\n", " (lora_dropout): ModuleDict(\n", " (default): Identity()\n", " )\n", " (lora_A): ModuleDict(\n", " (default): Linear(in_features=896, out_features=1, bias=False)\n", " )\n", " (lora_B): ModuleDict(\n", " (default): Linear(in_features=1, out_features=896, bias=False)\n", " )\n", " (lora_embedding_A): ParameterDict()\n", " (lora_embedding_B): ParameterDict()\n", " (lora_magnitude_vector): ModuleDict()\n", " )\n", " (k_proj): lora.Linear(\n", " (base_layer): Linear(in_features=896, out_features=128, bias=True)\n", " (lora_dropout): ModuleDict(\n", " (default): Identity()\n", " )\n", " (lora_A): ModuleDict(\n", " (default): Linear(in_features=896, out_features=1, bias=False)\n", " )\n", " (lora_B): ModuleDict(\n", " (default): Linear(in_features=1, out_features=128, bias=False)\n", " )\n", " (lora_embedding_A): ParameterDict()\n", " (lora_embedding_B): ParameterDict()\n", " (lora_magnitude_vector): ModuleDict()\n", " )\n", " (v_proj): lora.Linear(\n", " (base_layer): Linear(in_features=896, out_features=128, bias=True)\n", " (lora_dropout): ModuleDict(\n", " (default): Identity()\n", " )\n", " (lora_A): ModuleDict(\n", " (default): Linear(in_features=896, out_features=1, bias=False)\n", " )\n", " (lora_B): ModuleDict(\n", " (default): Linear(in_features=1, out_features=128, bias=False)\n", " )\n", " (lora_embedding_A): ParameterDict()\n", " (lora_embedding_B): ParameterDict()\n", " (lora_magnitude_vector): ModuleDict()\n", " )\n", " (o_proj): lora.Linear(\n", " (base_layer): Linear(in_features=896, out_features=896, bias=False)\n", " (lora_dropout): ModuleDict(\n", " (default): Identity()\n", " )\n", " (lora_A): ModuleDict(\n", " (default): Linear(in_features=896, out_features=1, bias=False)\n", " )\n", " (lora_B): ModuleDict(\n", " (default): Linear(in_features=1, out_features=896, bias=False)\n", " )\n", " (lora_embedding_A): ParameterDict()\n", " (lora_embedding_B): ParameterDict()\n", " (lora_magnitude_vector): ModuleDict()\n", " )\n", " (rotary_emb): Qwen2RotaryEmbedding()\n", " )\n", " (mlp): Qwen2MLP(\n", " (gate_proj): lora.Linear(\n", " (base_layer): Linear(in_features=896, out_features=4864, bias=False)\n", " (lora_dropout): ModuleDict(\n", " (default): Identity()\n", " )\n", " (lora_A): ModuleDict(\n", " (default): Linear(in_features=896, out_features=1, bias=False)\n", " )\n", " (lora_B): ModuleDict(\n", " (default): Linear(in_features=1, out_features=4864, bias=False)\n", " )\n", " (lora_embedding_A): ParameterDict()\n", " (lora_embedding_B): ParameterDict()\n", " (lora_magnitude_vector): ModuleDict()\n", " )\n", " (up_proj): lora.Linear(\n", " (base_layer): Linear(in_features=896, out_features=4864, bias=False)\n", " (lora_dropout): ModuleDict(\n", " (default): Identity()\n", " )\n", " (lora_A): ModuleDict(\n", " (default): Linear(in_features=896, out_features=1, bias=False)\n", " )\n", " (lora_B): ModuleDict(\n", " (default): Linear(in_features=1, out_features=4864, bias=False)\n", " )\n", " (lora_embedding_A): ParameterDict()\n", " (lora_embedding_B): ParameterDict()\n", " (lora_magnitude_vector): ModuleDict()\n", " )\n", " (down_proj): lora.Linear(\n", " (base_layer): Linear(in_features=4864, out_features=896, bias=False)\n", " (lora_dropout): ModuleDict(\n", " (default): Identity()\n", " )\n", " (lora_A): ModuleDict(\n", " (default): Linear(in_features=4864, out_features=1, bias=False)\n", " )\n", " (lora_B): ModuleDict(\n", " (default): Linear(in_features=1, out_features=896, bias=False)\n", " )\n", " (lora_embedding_A): ParameterDict()\n", " (lora_embedding_B): ParameterDict()\n", " (lora_magnitude_vector): ModuleDict()\n", " )\n", " (act_fn): SiLU()\n", " )\n", " (input_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n", " (post_attention_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n", " )\n", " )\n", " (norm): Qwen2RMSNorm((896,), eps=1e-06)\n", " )\n", " (lm_head): Linear(in_features=896, out_features=151936, bias=False)\n", ")\n" ] } ], "source": [ "print(model)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Which is bigger? 9.9 or 9.11\n", "base model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response='Which is bigger? 9.9 or 9.1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'\n", "lora model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response_lora='Which is bigger? 9.9 or 9.11\\n\\nTo determine which is bigger, we can compare the two numbers directly. The first number is 9.9, and the second number is 9.11. Since 9.9 is greater than 9.11, the answer is 9.9. \\n\\n9.9 > 9.11<|endoftext|>'\n", "---------------\n", "How many r's in the word strawberry?\n", "base model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response=\"How many r's in the word strawberry? - Answers\\\\nMath and Arithmetic\\\\nHow many r's in the word strawberry?\\\\nWiki User\\\\nโˆ™ 2011-09-28 19:52:27\\\\nStudy now\\\\nSee answer (1)\\\\nBest Answer\\\\nCopy\\\\nThere are 3 r's in the word strawberry.\\\\nWiki User\\\\nโˆ™ 2011-09-28 19:52:27\\\\nThis answer is:\\\\n๐Ÿ‘\\\\n๐Ÿ™\\\\n0\\\\n๐Ÿคจ\\\\n0\\\\n๐Ÿ˜ฎ\\\\n0\\\\nAdd a Comment\\\\nStudy guides\\\\nAlgebra\\\\n20 cards\\\\nA polynomial of degree zero is a constant term\\\\nThe grouping method of factoring can still be used when only some of the terms share a common factor A True B False\\\\nThe sum or difference of p and q is the of the x-term in the trinomial\\\\nA number a power of a variable or a product of the two is a monomial while a polynomial is the of monomials\\\\nโžก๏ธ\\\\nSee all cards\\\\n3.75\\\\nโ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…โ˜†โ˜…\\\\n524 Reviews\\\\nStudy now\\\\nAdd your answer:\\\\nEarn +20 pts\\\\nQ: How many r's in the word strawberry?\\\\nSubmit\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many\"\n", "lora model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response_lora=\"How many r's in the word strawberry? The word strawberry has 5 r's. What is 5 r's in the word strawberry? The answer is 5.<|endoftext|>\"\n", "---------------\n", "Given the vectors \\( \\mathbf{v}_1 = (3, -2, 5) \\) and \\( \\mathbf{v}_2 = (1, 4, -1) \\), compute the dot product \\( \\mathbf{v}_1 \\cdot \\mathbf{v}_2 \\).\n", "base model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response='Given the vectors \\\\( \\\\mathbf{v}_1 = (3, -2, 5) \\\\) and \\\\( \\\\mathbf{v}_2 = (1, 4, -1) \\\\), compute the dot product \\\\( \\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 \\\\). To compute the dot product of two vectors \\\\(\\\\mathbf{v}_1 = (3, -2, 5)\\\\) and \\\\(\\\\mathbf{v}_2 = (1, 4, -1)\\\\), we use the formula for the dot product of two vectors in three-dimensional space:\\n\\n\\\\[\\n\\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 = v_1 \\\\cdot v_2 = v_1_1 \\\\cdot v_2_1 + v_1_2 \\\\cdot v_2_2 + v_1_3 \\\\cdot v_2_3\\n\\\\]\\n\\nHere, the components of the vectors are:\\n\\\\[\\nv_1_1 = 3, \\\\quad v_1_2 = -2, \\\\quad v_1_3 = 5\\n\\\\]\\n\\\\[\\nv_2_1 = 1, \\\\quad v_2_2 = 4, \\\\quad v_2_3 = -1\\n\\\\]\\n\\nSubstituting these values into the formula, we get:\\n\\\\[\\n\\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 = (3)(1) + (-2)(4) + (5)(-1)\\n\\\\]\\n\\nNow, we perform the multiplications:\\n\\\\[\\n(3)(1) = 3\\n\\\\]\\n\\\\[\\n(-2)(4) = -8\\n\\\\]\\n\\\\[\\n(5)(-1) = -5\\n\\\\]\\n\\nAdding these results together gives:\\n\\\\[\\n3 + (-8) + (-5) = 3 - 8 - 5 = -10\\n\\\\]\\n\\nTherefore, the dot product of \\\\(\\\\mathbf{v}_1\\\\) and \\\\(\\\\mathbf{v}_2\\\\) is \\\\(\\\\boxed{-10}\\\\).<|endoftext|>'\n", "lora model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response_lora=\"Given the vectors \\\\( \\\\mathbf{v}_1 = (3, -2, 5) \\\\) and \\\\( \\\\mathbf{v}_2 = (1, 4, -1) \\\\), compute the dot product \\\\( \\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 \\\\). To find the dot product of two vectors \\\\(\\\\mathbf{v}_1 = (3, -2, 5)\\\\) and \\\\(\\\\mathbf{v}_2 = (1, 4, -1)\\\\), we use the formula for the dot product of two vectors in three-dimensional space:\\n\\n\\\\[\\n\\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 = v_1 \\\\cdot v_2 = 3 \\\\cdot 1 + (-2) \\\\cdot 4 + 5 \\\\cdot (-1)\\n\\\\]\\n\\nLet's calculate this step by step using Python.\\n```python\\n# Define the vectors\\nv1 = (3, -2, 5)\\nv2 = (1, 4, -1)\\n\\n# Calculate the dot product\\ndot_product = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]\\nprint(dot_product)\\n```\\n```output\\n-10\\n```\\nThe dot product of the vectors \\\\(\\\\mathbf{v}_1 = (3, -2, 5)\\\\) and \\\\(\\\\mathbf{v}_2 = (1, 4, -1)\\\\) is \\\\(\\\\boxed{-10}\\\\).<|endoftext|>\"\n", "---------------\n", "Find the derivative of the function \\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\) with respect to \\( x \\).\n", "base model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response=\"Find the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\). To find the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\), we will apply the power rule to each term of the function. The power rule states that if \\\\( f(x) = x^n \\\\), then \\\\( f'(x) = nx^{n-1} \\\\).\\n\\nLet's break it down term by term:\\n\\n1. For the term \\\\( 3x^4 \\\\):\\n \\\\[\\n \\\\frac{d}{dx}(3x^4) = 3 \\\\cdot 4x^{4-1} = 12x^3\\n \\\\]\\n\\n2. For the term \\\\( -5x^3 \\\\):\\n \\\\[\\n \\\\frac{d}{dx}(-5x^3) = -5 \\\\cdot 3x^{3-1} = -15x^2\\n \\\\]\\n\\n3. For the term \\\\( 2x \\\\):\\n \\\\[\\n \\\\frac{d}{dx}(2x) = 2 \\\\cdot 1x^{1-1} = 2\\n \\\\]\\n\\n4. For the constant term \\\\( -7 \\\\):\\n \\\\[\\n \\\\frac{d}{dx}(-7) = 0\\n \\\\]\\n\\nNow, we combine the derivatives of all the terms:\\n\\\\[\\nf'(x) = 12x^3 - 15x^2 + 2\\n\\\\]\\n\\nTherefore, the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\) is \\\\(\\\\boxed{12x^3 - 15x^2 + 2}\\\\).<|endoftext|>\"\n", "lora model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response_lora=\"Find the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\). To find the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\), we will apply the power rule to each term. The power rule states that if \\\\( f(x) = x^n \\\\), then \\\\( f'(x) = nx^{n-1} \\\\).\\n\\nLet's break down the function and apply the power rule to each term:\\n\\n1. For the term \\\\( 3x^4 \\\\):\\n \\\\[\\n \\\\frac{d}{dx}(3x^4) = 3 \\\\cdot 4x^{4-1} = 12x^3\\n \\\\]\\n\\n2. For the term \\\\( -5x^3 \\\\):\\n \\\\[\\n \\\\frac{d}{dx}(-5x^3) = -5 \\\\cdot 3x^{3-1} = -15x^2\\n \\\\]\\n\\n3. For the term \\\\( 2x \\\\):\\n \\\\[\\n \\\\frac{d}{dx}(2x) = 2 \\\\cdot 1x^{1-1} = 2\\n \\\\]\\n\\n4. For the constant term \\\\( -7 \\\\):\\n \\\\[\\n \\\\frac{d}{dx}(-7) = 0\\n \\\\]\\n\\nNow, we combine the derivatives of each term to get the derivative of the entire function:\\n\\\\[\\nf'(x) = 12x^3 - 15x^2 + 2\\n\\\\]\\n\\nThus, the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\) is \\\\(\\\\boxed{12x^3 - 15x^2 + 2}\\\\).<|endoftext|>\"\n", "---------------\n", "Find the area of a triangle with vertices at points \\( (1, 2) \\), \\( (4, 6) \\), and \\( (7, 2) \\).\n", "base model\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "response='Find the area of a triangle with vertices at points \\\\( (1, 2) \\\\), \\\\( (4, 6) \\\\), and \\\\( (7, 2) \\\\). To find the area of a triangle with vertices at points \\\\((1, 2)\\\\), \\\\((4, 6)\\\\), and \\\\((7, 2)\\\\), we can use the formula for the area of a triangle given its vertices \\\\((x_1, y_1)\\\\), \\\\((x_2, y_2)\\\\), and \\\\((x_3, y_3)\\\\):\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2) \\\\right|\\n\\\\]\\n\\nSubstituting the coordinates of the vertices \\\\((1, 2)\\\\), \\\\((4, 6)\\\\), and \\\\((7, 2)\\\\) into the formula, we get:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| 1(6 - 2) + 4(2 - 2) + 7(2 - 6) \\\\right|\\n\\\\]\\n\\nSimplifying inside the absolute value:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| 1 \\\\cdot 4 + 4 \\\\cdot 0 + 7 \\\\cdot (-4) \\\\right| = \\\\frac{1}{2} \\\\left| 4 + 0 - 28 \\\\right| = \\\\frac{1}{2} \\\\left| -24 \\\\right| = \\\\frac{1}{2} \\\\cdot 24 = 12\\n\\\\]\\n\\nThus, the area of the triangle is \\\\(\\\\boxed{12}\\\\).<|endoftext|>'\n", "lora model\n", "response_lora=\"Find the area of a triangle with vertices at points \\\\( (1, 2) \\\\), \\\\( (4, 6) \\\\), and \\\\( (7, 2) \\\\). To find the area of a triangle with vertices at points \\\\((x_1, y_1)\\\\), \\\\((x_2, y_2)\\\\), and \\\\((x_3, y_3)\\\\), we can use the following formula:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2) \\\\right|\\n\\\\]\\n\\nGiven the vertices \\\\((1, 2)\\\\), \\\\((4, 6)\\\\), and \\\\((7, 2)\\\\), we can substitute these coordinates into the formula:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| 1(6 - 2) + 4(2 - 2) + 7(2 - 6) \\\\right|\\n\\\\]\\n\\nSimplify the expression inside the absolute value:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| 1 \\\\cdot 4 + 4 \\\\cdot 0 + 7 \\\\cdot (-4) \\\\right| = \\\\frac{1}{2} \\\\left| 4 - 28 \\\\right| = \\\\frac{1}{2} \\\\left| -24 \\\\right| = \\\\frac{1}{2} \\\\cdot 24 = 12\\n\\\\]\\n\\nThus, the area of the triangle is \\\\(12\\\\). Let's confirm this with Python code.\\n```python\\n# Define the vertices\\nx1, y1 = 1, 2\\nx2, y2 = 4, 6\\nx3, y3 = 7, 2\\n\\n# Calculate the area using the formula\\narea = 0.5 * abs(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2))\\nprint(area)\\n```\\n```output\\n12.0\\n```\\nThe area of the triangle with vertices at points \\\\((1, 2)\\\\), \\\\((4, 6)\\\\), and \\\\((7, 2)\\\\) is \\\\(\\\\boxed{12}\\\\).<|endoftext|>\"\n", "---------------\n" ] } ], "source": [ "import warnings\n", "\n", "# Suppress all warnings\n", "warnings.filterwarnings(\"ignore\")\n", "\n", "# The last three problems are generated by GPT-4o\n", "texts = ['Which is bigger? 9.9 or 9.11',\n", " 'How many r\\'s in the word strawberry?',\n", " 'Given the vectors \\( \\mathbf{v}_1 = (3, -2, 5) \\) and \\( \\mathbf{v}_2 = (1, 4, -1) \\), compute the dot product \\( \\mathbf{v}_1 \\cdot \\mathbf{v}_2 \\).',\n", " 'Find the derivative of the function \\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\) with respect to \\( x \\).',\n", " 'Find the area of a triangle with vertices at points \\( (1, 2) \\), \\( (4, 6) \\), and \\( (7, 2) \\).'\n", " ]\n", "for t in texts:\n", " print(t)\n", " inputs = tokenizer([t], return_tensors='pt').to(device)\n", "\n", " print('base model')\n", " outputs = base.generate(**inputs)\n", " response = tokenizer.decode(outputs[0], max_new_tokens=128)\n", " print(f'{response=}')\n", "\n", " print('lora model')\n", "\n", " outputs_lora = lora.generate(**inputs)\n", " response_lora = tokenizer.decode(outputs_lora[0], max_new_tokens=128)\n", " print(f'{response_lora=}')\n", " print('---------------')" ] } ], "metadata": { "kernelspec": { "display_name": "llama_factory", "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.10.14" } }, "nbformat": 4, "nbformat_minor": 2 }