diff --git "a/Midjourney Prompt Generator using falcon 7b finetune.ipynb" "b/Midjourney Prompt Generator using falcon 7b finetune.ipynb" new file mode 100644--- /dev/null +++ "b/Midjourney Prompt Generator using falcon 7b finetune.ipynb" @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"gpuType":"T4","authorship_tag":"ABX9TyNwkYMTT5vPL8ZKvpIVt885"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"},"accelerator":"GPU","widgets":{"application/vnd.jupyter.widget-state+json":{"67dc7e54e6f54dac96104f97924709ed":{"model_module":"@jupyter-widgets/controls","model_name":"VBoxModel","model_module_version":"1.5.0","state":{"_dom_classes":[],"_model_module":"@jupyter-widgets/controls","_model_module_version":"1.5.0","_model_name":"VBoxModel","_view_count":null,"_view_module":"@jupyter-widgets/controls","_view_module_version":"1.5.0","_view_name":"VBoxView","box_style":"","children":["IPY_MODEL_f1ce970ea63348a9a2089f59ee5b9610","IPY_MODEL_59219d3e0c814b98bdfd30f27a89ea2f","IPY_MODEL_5259d861df294a34af23284b0fcdcbac","IPY_MODEL_ba44bb7d60cb482cb1ed497e7ae38e27"],"layout":"IPY_MODEL_db9063f770bd4a79834525aa00b7cd0b"}},"87b06de45a884a89b8736082789b4352":{"model_module":"@jupyter-widgets/controls","model_name":"HTMLModel","model_module_version":"1.5.0","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_e7042124776f4bd28e83606e5e954a7b","placeholder":"","style":"IPY_MODEL_38e23793e1cd45e9b04fd4967ddf1291","value":"
Step | \n","Training Loss | \n","
---|---|
1 | \n","4.632900 | \n","
2 | \n","4.785000 | \n","
3 | \n","4.725800 | \n","
4 | \n","4.498500 | \n","
5 | \n","4.526100 | \n","
6 | \n","4.546100 | \n","
7 | \n","4.197700 | \n","
8 | \n","4.044100 | \n","
9 | \n","4.361300 | \n","
10 | \n","4.104100 | \n","
11 | \n","4.256700 | \n","
12 | \n","3.846900 | \n","
13 | \n","3.562900 | \n","
14 | \n","3.647100 | \n","
15 | \n","3.677400 | \n","
16 | \n","3.339300 | \n","
17 | \n","3.200300 | \n","
18 | \n","3.564800 | \n","
19 | \n","3.057700 | \n","
20 | \n","3.342800 | \n","
21 | \n","3.475100 | \n","
22 | \n","2.992000 | \n","
23 | \n","2.834900 | \n","
24 | \n","2.652300 | \n","
25 | \n","3.243600 | \n","
26 | \n","2.976000 | \n","
27 | \n","3.395400 | \n","
28 | \n","2.868300 | \n","
29 | \n","2.639700 | \n","
30 | \n","2.689000 | \n","
31 | \n","2.828400 | \n","
32 | \n","3.130400 | \n","
33 | \n","2.471300 | \n","
34 | \n","2.637300 | \n","
35 | \n","2.523500 | \n","
36 | \n","2.338600 | \n","
37 | \n","2.774200 | \n","
38 | \n","2.458300 | \n","
39 | \n","2.606900 | \n","
40 | \n","2.819700 | \n","
41 | \n","2.602900 | \n","
42 | \n","2.166600 | \n","
43 | \n","2.204600 | \n","
44 | \n","2.405500 | \n","
45 | \n","1.929400 | \n","
46 | \n","2.289100 | \n","
47 | \n","2.157100 | \n","
48 | \n","2.095500 | \n","
49 | \n","2.639400 | \n","
50 | \n","2.201900 | \n","
51 | \n","1.789000 | \n","
52 | \n","2.046100 | \n","
53 | \n","2.414200 | \n","
54 | \n","2.117800 | \n","
55 | \n","2.614400 | \n","
56 | \n","1.842500 | \n","
57 | \n","2.100100 | \n","
58 | \n","3.374300 | \n","
59 | \n","2.244300 | \n","
60 | \n","2.533400 | \n","
61 | \n","1.754700 | \n","
62 | \n","2.725600 | \n","
63 | \n","2.347400 | \n","
64 | \n","2.164600 | \n","
65 | \n","2.615300 | \n","
66 | \n","2.275800 | \n","
67 | \n","1.806700 | \n","
68 | \n","2.040100 | \n","
69 | \n","1.925000 | \n","
70 | \n","1.313200 | \n","
71 | \n","2.344600 | \n","
72 | \n","2.901200 | \n","
"]},"metadata":{}},{"output_type":"execute_result","data":{"text/plain":["TrainOutput(global_step=72, training_loss=2.8924238599008985, metrics={'train_runtime': 430.1614, 'train_samples_per_second': 0.67, 'train_steps_per_second': 0.167, 'total_flos': 425393421932544.0, 'train_loss': 2.8924238599008985, 'epoch': 1.0})"]},"metadata":{},"execution_count":17}]},{"cell_type":"markdown","source":["# Save trained model"],"metadata":{"id":"wqG2axYHqfpO"}},{"cell_type":"code","source":["model.save_pretrained(\"trained-model\")"],"metadata":{"id":"2SqPtd-2qfNU","executionInfo":{"status":"ok","timestamp":1694778473330,"user_tz":-330,"elapsed":688,"user":{"displayName":"Bitan Paul","userId":"16789405851811800399"}}},"execution_count":18,"outputs":[]},{"cell_type":"code","source":["PEFT_MODEL = \"thebitanpaul/midjourneyPromptGenerator\"\n","\n","model.push_to_hub(\n"," PEFT_MODEL, use_auth_token=True, create_pr=True\n",")\n"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":272,"referenced_widgets":["86ea7aee86824993bc7b053ad6eeb189","d31aa2b80b254e1eb74e6a59590ec147","6f47e73b78624087a01a4b1206482350","c60c46319295455b84ec136d28c696de","d82a9a7a3ac840ed9f12d447004f2ecb","44550408b2b544678144d0a2493638ba","8261d67f388a471ea2c3ec10fa26a67c","bde25efa4bea47a08378e31c57ca2936","01be9dd7987c4ca8ba70792e1b0b1973","361353a2107046c6be45e2bad69a9579","dd00261660bc4165a140dd95a85dc6c6","fa288995ff024967ba16058bcb46d8c4","5cfcb15352234a64b78571f6be05be1d","1d4b430401074da785c61c3445275c24","31dc15264b774d24a2b1ca5bd3bcb8c7","db28f66326ba424b975ea0977c247373","15067311060e43579df225f211886a48","dc346d64d8f6411881734c30da296ac6","900278ec4fc343c1ac700a8cc6425df5","88de5a4934e149acae0a65001b86a850","4cf6404b74584b54aa4737e6d194b130","586fd41d8b5547e4bc1a252c5564c4f0","b92f4e50f4894dedb652ebfc0788c131","4629fa1c00a34c8893b10b0e6e645476","2b5d54fd2cfb4fd7b8187ba808a9ecf1","3d3092eeb27f4d4f8dc34ac1bfe2c25d","4f1da04d9b914defb8bfce7cdae52c60","405f5c3b9cb14177bd5c6c114ee27250","1d8e4d73eaf649458bffb2289bf5950f","2b2992b04e2e4f11b90b487936353305","2c2dedb163c54450a90a0f3b1d2cf3e5","587423d51630425cb87444579ba11066","055fb04db81d4421bf76961514bd4a57"]},"id":"CO5XoASWqzLI","executionInfo":{"status":"ok","timestamp":1694778627967,"user_tz":-330,"elapsed":7832,"user":{"displayName":"Bitan Paul","userId":"16789405851811800399"}},"outputId":"edccc597-ffc1-4f91-a03a-cd2c2445821c"},"execution_count":19,"outputs":[{"output_type":"stream","name":"stderr","text":["/usr/local/lib/python3.10/dist-packages/huggingface_hub/_commit_api.py:273: UserWarning: About to update multiple times the same file in the same commit: 'adapter_config.json'. This can cause undesired inconsistencies in your repo.\n"," warnings.warn(\n","/usr/local/lib/python3.10/dist-packages/huggingface_hub/_commit_api.py:273: UserWarning: About to update multiple times the same file in the same commit: 'adapter_model.bin'. This can cause undesired inconsistencies in your repo.\n"," warnings.warn(\n"]},{"output_type":"display_data","data":{"text/plain":["Upload 2 LFS files: 0%| | 0/2 [00:00, ?it/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"86ea7aee86824993bc7b053ad6eeb189"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["adapter_model.bin: 0%| | 0.00/18.9M [00:00, ?B/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"fa288995ff024967ba16058bcb46d8c4"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["adapter_model.bin: 0%| | 0.00/18.9M [00:00, ?B/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"b92f4e50f4894dedb652ebfc0788c131"}},"metadata":{}},{"output_type":"execute_result","data":{"text/plain":["CommitInfo(commit_url='https://huggingface.co/thebitanpaul/midjourneyPromptGenerator/commit/ee8fbfc2610f116e78dfe8bff89a7eaf6ee8f263', commit_message='Upload model', commit_description='', oid='ee8fbfc2610f116e78dfe8bff89a7eaf6ee8f263', pr_url='https://huggingface.co/thebitanpaul/midjourneyPromptGenerator/discussions/1', pr_revision='refs/pr/1', pr_num=1)"]},"metadata":{},"execution_count":19}]},{"cell_type":"code","source":["config = PeftConfig.from_pretrained(PEFT_MODEL)\n","model = AutoModelForCausalLM.from_pretrained(\n"," config.base_model_name_or_path,\n"," return_dict=True,\n"," quantization_config=bnb_config,\n"," device_map=\"auto\",\n"," trust_remote_code=True\n",")\n","\n","tokenizer=AutoTokenizer.from_pretrained(config.base_model_name_or_path)\n","tokenizer.pad_token = tokenizer.eos_token\n","\n","model = PeftModel.from_pretrained(model, PEFT_MODEL)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":168,"referenced_widgets":["8ebd6e4a2c104610bc37387ca4a50bf2","a378aab66cef487f9867a84973e11ecb","8e3cf6d56ffa45bd945a693aeeadaeef","067649a4dae14d839ff141e076e63fe7","0260e86550074a3386e0fb11b7594441","f808926931bf4944901e2cca7d29d6b6","f0d2dea18db54a9ea76ce495474b4865","69ae1dc91a534b7f9898d269413dbdae","434ffa04d76a428983175d0b0447d125","1aaa0188fb5d400fb238c7efd82537e2","ee3661b5a18a483c8633e8cd4086d822","2ea76f50d7ce494982443d9efb3ad9ba","b4cdf54d35e44c80a1ca8385ad29abf4","2474580dd82b41faafde583f2226b0e0","24769c2575fa464c9ae2e77fbd4ac286","8fbe3a683d55475cb1ec31348092dd7e","db0819f4600e46be854138eb5f1df5c9","674c591251d64d628c162d04b8ac3fd8","40a8d6d1b6fd4c3884351d2686b938e2","06c54efcc53a49d5934e5c0e2e4cc3c3","cae33ab9dffa4ca484cdbed0ead901e4","eb0a1f361b404e84acf8c1e5f9e94efa","d64da4b1487b44a6a0aa22397cfb4445","e8f0c34a9e8144368bad16d28116e958","ec5abd6b590c4a1ea5057a1f3fd512ca","fd3506338b8541a9969cd32124260789","20996a7be7f742a7bace69092ad550d8","c91c5689bec74520a112459deeb4bf95","0fa99990f29d4f228b8ed822d7b33e51","91a800327b6041fda7c124cb3a79290d","85a017ab2fcd45cf91cb0b5262cf857b","499ba09ac4264f40a23df522dfd002e0","7586d2a53e57411a9527a1b856839397"]},"id":"zew9Fkr9rXGJ","executionInfo":{"status":"ok","timestamp":1694778949322,"user_tz":-330,"elapsed":194333,"user":{"displayName":"Bitan Paul","userId":"16789405851811800399"}},"outputId":"258d7290-6ac1-4587-b4b9-488cc7b1a8ad"},"execution_count":20,"outputs":[{"output_type":"display_data","data":{"text/plain":["Downloading (…)/adapter_config.json: 0%| | 0.00/436 [00:00, ?B/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"8ebd6e4a2c104610bc37387ca4a50bf2"}},"metadata":{}},{"output_type":"display_data","data":{"text/plain":["Loading checkpoint shards: 0%| | 0/15 [00:00, ?it/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"2ea76f50d7ce494982443d9efb3ad9ba"}},"metadata":{}},{"output_type":"stream","name":"stderr","text":["Some weights of FalconForCausalLM were not initialized from the model checkpoint at vilsonrodrigues/falcon-7b-instruct-sharded and are newly initialized: ['lm_head.weight']\n","You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.\n"]},{"output_type":"display_data","data":{"text/plain":["Downloading adapter_model.bin: 0%| | 0.00/18.9M [00:00, ?B/s]"],"application/vnd.jupyter.widget-view+json":{"version_major":2,"version_minor":0,"model_id":"d64da4b1487b44a6a0aa22397cfb4445"}},"metadata":{}}]},{"cell_type":"markdown","source":["# Run the finetuned model"],"metadata":{"id":"4Mtk4rvAr-6j"}},{"cell_type":"code","source":["generation_config = model.generation_config\n","generation_config.max_new_tokens = 200\n","generation_config.temperature = 0.7\n","generation_config.top_p = 0.7\n","generation_config.num_return_sequences = 1\n","generation_config.pad_token_id = tokenizer.eos_token_id\n","generation_config.eos_token_id = tokenizer.eos_token_id"],"metadata":{"id":"CQgUvtXjr4KW","executionInfo":{"status":"ok","timestamp":1694778997121,"user_tz":-330,"elapsed":664,"user":{"displayName":"Bitan Paul","userId":"16789405851811800399"}}},"execution_count":21,"outputs":[]},{"cell_type":"code","source":["%%time\n","device = \"cuda:0\"\n","\n","prompt = \"\"\"\n"," Albert Einstein playing a guitar A portrait of Albert Einstein playing a guitar, with a backdrop of a city skyline, a bright blue sky, and a warm golden light, --ar 16:9 --no-repeat --no-stretch --no-scale --no-flip --no-flip-horizontal --no-flip-vertical --no-repeat --no-stretch --ar 16:9 --ar 4:3 --no-repeat --no-scale --no-flip --no-flip-horizontal --no-flip-vertical --no-repeat --no-stretch --ar 16:9 --ar 4:3 --ar 16:9 --ar 4:3 --ar 16:9 --ar 16:9 --ar 16\n","CPU times: user 1min 19s, sys: 140 ms, total: 1min 19s\n","Wall time: 1min 33s\n"]}]},{"cell_type":"code","source":[],"metadata":{"id":"5QWwDaxOvQ4N"},"execution_count":null,"outputs":[]}]}
\ No newline at end of file