File size: 7,242 Bytes
994cc5a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 |
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "d67610d1-a6d9-420f-90d7-248d46b31697",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"loading file tokenizer.model from cache at /root/.cache/huggingface/hub/models--baichuan-inc--Baichuan-13B-Base/snapshots/0ef0739c7bdd34df954003ef76d80f3dabca2ff9/tokenizer.model\n",
"loading file added_tokens.json from cache at None\n",
"loading file special_tokens_map.json from cache at /root/.cache/huggingface/hub/models--baichuan-inc--Baichuan-13B-Base/snapshots/0ef0739c7bdd34df954003ef76d80f3dabca2ff9/special_tokens_map.json\n",
"loading file tokenizer_config.json from cache at /root/.cache/huggingface/hub/models--baichuan-inc--Baichuan-13B-Base/snapshots/0ef0739c7bdd34df954003ef76d80f3dabca2ff9/tokenizer_config.json\n",
"loading configuration file config.json from cache at /root/.cache/huggingface/hub/models--baichuan-inc--Baichuan-13B-Base/snapshots/0ef0739c7bdd34df954003ef76d80f3dabca2ff9/config.json\n",
"loading configuration file config.json from cache at /root/.cache/huggingface/hub/models--baichuan-inc--Baichuan-13B-Base/snapshots/0ef0739c7bdd34df954003ef76d80f3dabca2ff9/config.json\n",
"Model config BaichuanConfig {\n",
" \"_from_model_config\": true,\n",
" \"_name_or_path\": \"baichuan-inc/Baichuan-13B-Base\",\n",
" \"architectures\": [\n",
" \"BaichuanForCausalLM\"\n",
" ],\n",
" \"auto_map\": {\n",
" \"AutoConfig\": \"baichuan-inc/Baichuan-13B-Base--configuration_baichuan.BaichuanConfig\",\n",
" \"AutoModelForCausalLM\": \"baichuan-inc/Baichuan-13B-Base--modeling_baichuan.BaichuanForCausalLM\"\n",
" },\n",
" \"bos_token_id\": 1,\n",
" \"eos_token_id\": 2,\n",
" \"gradient_checkpointing\": [\n",
" false\n",
" ],\n",
" \"hidden_act\": \"silu\",\n",
" \"hidden_size\": 5120,\n",
" \"initializer_range\": 0.02,\n",
" \"intermediate_size\": 13696,\n",
" \"model_max_length\": 4096,\n",
" \"model_type\": \"baichuan\",\n",
" \"num_attention_heads\": 40,\n",
" \"num_hidden_layers\": 40,\n",
" \"pad_token_id\": 0,\n",
" \"rms_norm_eps\": 1e-06,\n",
" \"tie_word_embeddings\": false,\n",
" \"torch_dtype\": \"bfloat16\",\n",
" \"transformers_version\": \"4.32.1\",\n",
" \"use_cache\": true,\n",
" \"vocab_size\": 64000\n",
"}\n",
"\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"[2023-08-31 19:08:00,343] [INFO] [real_accelerator.py:158:get_accelerator] Setting ds_accelerator to cuda (auto detect)\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"loading weights file pytorch_model.bin from cache at /root/.cache/huggingface/hub/models--baichuan-inc--Baichuan-13B-Base/snapshots/0ef0739c7bdd34df954003ef76d80f3dabca2ff9/pytorch_model.bin.index.json\n",
"Generate config GenerationConfig {\n",
" \"_from_model_config\": true,\n",
" \"bos_token_id\": 1,\n",
" \"eos_token_id\": 2,\n",
" \"pad_token_id\": 0,\n",
" \"transformers_version\": \"4.32.1\"\n",
"}\n",
"\n"
]
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "87e88732661e46cebbc8cc1ab0f93a77",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Loading checkpoint shards: 0%| | 0/3 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"All model checkpoint weights were used when initializing BaichuanForCausalLM.\n",
"\n",
"All the weights of BaichuanForCausalLM were initialized from the model checkpoint at baichuan-inc/Baichuan-13B-Base.\n",
"If your task is similar to the task the model of the checkpoint was trained on, you can already use BaichuanForCausalLM for predictions without further training.\n",
"loading configuration file generation_config.json from cache at /root/.cache/huggingface/hub/models--baichuan-inc--Baichuan-13B-Base/snapshots/0ef0739c7bdd34df954003ef76d80f3dabca2ff9/generation_config.json\n",
"Generate config GenerationConfig {\n",
" \"_from_model_config\": true,\n",
" \"bos_token_id\": 1,\n",
" \"eos_token_id\": 2,\n",
" \"pad_token_id\": 0,\n",
" \"transformers_version\": \"4.32.1\"\n",
"}\n",
"\n",
"Generate config GenerationConfig {\n",
" \"_from_model_config\": true,\n",
" \"bos_token_id\": 1,\n",
" \"eos_token_id\": 2,\n",
" \"pad_token_id\": 0,\n",
" \"transformers_version\": \"4.32.1\"\n",
"}\n",
"\n",
"/root/miniconda3/lib/python3.8/site-packages/transformers/generation/configuration_utils.py:367: UserWarning: `do_sample` is set to `False`. However, `top_p` is set to `0.92` -- this flag is only used in sample-based generation modes. You should set `do_sample=True` or unset `top_p`.\n",
" warnings.warn(\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"begin to gen\n"
]
}
],
"source": [
"import transformers\n",
"from transformers import AutoModelForCausalLM, AutoTokenizer\n",
"\n",
"transformers.logging.set_verbosity_info()\n",
"tokenizer = AutoTokenizer.from_pretrained(\"baichuan-inc/Baichuan-13B-Base\", trust_remote_code=True)\n",
"model = AutoModelForCausalLM.from_pretrained(\"baichuan-inc/Baichuan-13B-Base\", device_map=\"auto\", trust_remote_code=True)\n",
"inputs = tokenizer('make lyric:想带给你一句话', return_tensors='pt')\n",
"inputs = inputs.to('cuda:0')\n",
"print(\"begin to gen\")\n",
"pred = model.generate(**inputs, max_new_tokens=64,repetition_penalty=1.1, top_p=0.92)\n",
"print(tokenizer.decode(pred.cpu()[0], skip_special_tokens=True))\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "91c204d0-b141-4dea-a468-8f74b1361782",
"metadata": {},
"outputs": [],
"source": [
"from peft import PeftModel\n",
"lora_model = PeftModel.from_pretrained(model, \"./autodl-tmp/LLaMA-Efficient-Tuning/pppfuck\")\n",
"lora_pred = lora_model.generate(**inputs, max_new_tokens=128,repetition_penalty=1.1)\n",
"print(tokenizer.decode(lora_pred.cpu()[0], skip_special_tokens=True))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "84885258-cc93-4e08-a394-d2c5283a3fb3",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"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.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|