{"id":466450,"date":"2025-07-08T15:00:06","date_gmt":"2025-07-08T15:00:06","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=466450"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=466450","title":{"rendered":"<span>\u041e\u0442 \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u044f \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u0430 LLM \u0434\u043e \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u0430 \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0432\u0430\u043d \u0418\u0441\u0430\u0435\u0432, \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u041c\u041b \u0441 2014 \u0433\u043e\u0434\u0430, \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0438\u043b \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u041c\u041b \u0432 \u043a\u0440\u0443\u043f\u043d\u043e\u043c \u0442\u0435\u043b\u0435\u043a\u043e\u043c\u0435, \u043e\u0442\u0434\u0435\u043b\u043e\u043c \u041c\u041b \u0432 \u043a\u0440\u0443\u043f\u043d\u043e\u0439 RTB \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0433\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0432\u0435\u0434\u0443\u0449\u0438\u043c \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043e\u043c \u0432 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d-\u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b Bittensor.  \u041b\u044e\u0431\u043b\u044e \u043f\u043e\u0440\u0435\u0448\u0430\u0442\u044c Kaggle \u0441\u043e\u0440\u0435\u0432\u044b, \u0438 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0441\u043c\u043e\u0433 \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u043c\u0430\u0441\u0442\u0435\u0440\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u0430\u0440\u0443 \u043b\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u0430\u0436\u043d\u044f\u043b\u0441\u044f \u0441 NLP \u0438 LLM \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441 \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 (ImageBind, VITA \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438).  \u0412 Bittensor \u0443 \u043c\u0435\u043d\u044f \u0431\u044b\u043b\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u0441\u043c\u043e\u0433 \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u043e\u043c LLM \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0412 \u044d\u0442\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043d\u0435 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 (\u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u0441 \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u043e\u043c \u0431\u044b\u043b \u043d\u0430 Kaggle \u0441 Mistral, \u043a\u043e\u0433\u0434\u0430 \u044f <a href=\"https:\/\/www.kaggle.com\/code\/cdeotte\/mistral-7b-baseline-lb-0-7x\/notebook?scriptVersionId=172773538\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0447\u0435\u043b \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442<\/a>).<\/p>\n<blockquote>\n<p>\u042f \u043d\u0430\u0447\u043d\u0443 \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0432\u0435\u0449\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c, \u0430 \u0431\u043b\u0438\u0436\u0435 \u043a \u043a\u043e\u043d\u0446\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0442\u044e\u043d\u0438\u043d\u0433 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 Vision-to-Text LLMs, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0434\u0435, \u0438 \u043f\u0440\u043e \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433 ImageBind \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 LoRA.<\/p>\n<\/blockquote>\n<h3>1. \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<h4>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 LLM \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u043d\u0443\u0436\u043d\u043e?<\/h4>\n<p>\u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (LLM) \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u0437\u0430\u0434\u0430\u0447\u0438, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0443\u043c\u043d\u0435\u0435 \u043d\u0430 \u0441\u0432\u043e\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b. <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c, \u0430 \u043a\u043e\u0433\u0434\u0430 \u0445\u0432\u0430\u0442\u0438\u0442 prompt engineering \u0438\u043b\u0438 RAG? \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u0433\u043e \u2014 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0439. \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u043c\u043f\u0442\u044b.<\/p>\n<h3>2. PEFT \u0438 \u0435\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438<\/h3>\n<h4>PEFT (Parameter-Efficient Fine-Tuning) \u2014 \u0447\u0442\u043e \u044d\u0442\u043e \u0438 \u0437\u0430\u0447\u0435\u043c?<\/h4>\n<p>PEFT \u2014 \u044d\u0442\u043e \u0446\u0435\u043b\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u044d\u043a\u043e\u043d\u043e\u043c\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0443\u0441\u043a\u043e\u0440\u044f\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. LoRA \u2014 \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445! <\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/91b\/55d\/dc3\/91b55ddc33e5c0e5a4d48c4c0572091e.JPG\" width=\"887\" height=\"375\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/91b\/55d\/dc3\/91b55ddc33e5c0e5a4d48c4c0572091e.JPG 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/91b\/55d\/dc3\/91b55ddc33e5c0e5a4d48c4c0572091e.JPG 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<div class=\"floating-image\">\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b PEFT:<\/strong><\/p>\n<\/div>\n<ul>\n<li>\n<p><strong>LoRA (Low-Rank Adaptation):<\/strong><br \/>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 low-rank \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043a \u0437\u0430\u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0432\u0435\u0441\u0430\u043c. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import LoraConfig, get_peft_model     lora_config = LoraConfig(         r=8,         lora_alpha=32,         target_modules=[\"q_proj\", \"v_proj\"],         lora_dropout=0.05,         bias=\"none\"     )     lora_model = get_peft_model(base_model, lora_config)<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0438\u0442\u044c LLM \u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u0442\u0440\u0430\u0442\u0430\u043c\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.<\/p>\n<ul>\n<li>\n<p><strong>QLoRA (Quantized LoRA):<\/strong><br \/>\u0421\u043e\u0447\u0435\u0442\u0430\u0435\u0442 LoRA \u0438 4-bit \u043a\u0432\u0430\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u0435 (\u0447\u0435\u0440\u0435\u0437 bitsandbytes). \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u0436\u0435 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0435 \u0441 24\u0413\u0411 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 33B+.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from transformers import BitsAndBytesConfig     bnb_config = BitsAndBytesConfig(         load_in_4bit=True,         bnb_4bit_compute_dtype=torch.float16,         bnb_4bit_quant_type=\"nf4\"     )     # \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c LoRA \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f.<\/p>\n<ul>\n<li>\n<p><strong>AdaLoRA:<\/strong><br \/>\u0410\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f LoRA, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u0430\u043d\u043a (\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c low-rank \u043c\u0430\u0442\u0440\u0438\u0446) \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<br \/><strong>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e? <\/strong>\u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044d\u0442\u0430\u043f\u0430\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u0430\u044f &#171;\u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c&#187; \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438, AdaLoRA \u0441\u0430\u043c\u0430 \u043f\u043e\u0434\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import AdaLoraConfig     adalora_config = AdaLoraConfig(         init_r=12,      # \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u043d\u043a         target_r=8,     # \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0440\u0430\u043d\u043a         beta1=0.85,         beta2=0.85,         target_modules=[\"q_proj\", \"v_proj\"]     )<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u0443 \u0442\u0435\u0431\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0442\u0434\u0430\u0447\u0438 \u043e\u0442 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f).<\/p>\n<ul>\n<li>\n<p><strong>BitFit:<\/strong><br \/>\u0414\u043e\u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e bias-\u0442\u0435\u0440\u043c\u044b (\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f) \u0432 \u0441\u043b\u043e\u044f\u0445 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0441\u0430 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u044b\u043c\u0438.<br \/><strong>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e?<\/strong> \u042d\u0442\u043e \u0441\u0430\u043c\u044b\u0439 &#171;\u043b\u0451\u0433\u043a\u0438\u0439&#187; \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import BitFitConfig     bitfit_config = BitFitConfig(         bias_pattern=[\"bias\", \"LayerNorm.bias\"],         modules_to_save=None     )<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f), \u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0441\u043e\u0432\u0441\u0435\u043c \u043c\u0430\u043b\u043e, \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0441\u043c\u044b\u0441\u043b \u0432 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0432\u043e\u043e\u0431\u0449\u0435.<\/p>\n<ul>\n<li>\n<p><strong>Prefix Tuning:<\/strong><br \/>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u043a \u0432\u0445\u043e\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 &#171;\u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442&#187; \u0435\u0439, \u043a\u0430\u043a \u0441\u0435\u0431\u044f \u0432\u0435\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import PrefixTuningConfig     prefix_config = PrefixTuningConfig(         num_virtual_tokens=20, task_type=\"CAUSAL_LM\"     )<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u043b\u0438 \u0441\u0442\u0438\u043b\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<ul>\n<li>\n<p>P-Tuning:<br \/>\u041f\u043e\u0445\u043e\u0436 \u043d\u0430 Prefix Tuning, \u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0438\u043d\u0430\u0447\u0435. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 soft prompts, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import PromptTuningConfig     ptuning_config = PromptTuningConfig(         num_virtual_tokens=10,         task_type=\"CAUSAL_LM\"     )<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 (few-shot).<\/p>\n<p><strong>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/strong><\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"center\"><strong>\u041c\u0435\u0442\u043e\u0434<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"center\"><strong>\u041f\u0430\u043c\u044f\u0442\u044c<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"center\"><strong>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"center\"><strong>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438  <\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">LoRA<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u043d\u0438\u0437\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">\u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e LLM<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">QLoRA<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u043e\u0447\u0435\u043d\u044c \u043d\u0438\u0437\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u0430\u043b\u043e RAM<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u0432\u0430\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">AdaLoRA<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u043d\u0438\u0437\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">\u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0440\u0430\u043d\u043a \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">P-Tuning<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u0441\u0440\u0435\u0434\u043d\u044f\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">prompt-based \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0445\u043e\u0440\u043e\u0448 \u0434\u043b\u044f few-shot<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">BitFit<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">\u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0442\u043e\u043b\u044c\u043a\u043e bias<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>3. LoRA \u2014 Low-Rank Adaptation<\/h3>\n<p><strong>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 LoRA \u0438 \u043a\u0430\u043a \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/strong><\/p>\n<p>LoRA \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0438\u0437\u043a\u043e\u0440\u0430\u043d\u0433\u043e\u0432\u044b\u0435 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438 \u043a \u0432\u0435\u0441\u0430\u043c \u043c\u043e\u0434\u0435\u043b\u0438. \u0412\u043c\u0435\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4b7\/c05\/cbd\/4b7c05cbd7182013a324b4ca03452865.JPG\" width=\"908\" height=\"343\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/4b7\/c05\/cbd\/4b7c05cbd7182013a324b4ca03452865.JPG 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4b7\/c05\/cbd\/4b7c05cbd7182013a324b4ca03452865.JPG 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<h3>4. \u041a\u0430\u043a\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c?<\/h3>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/strong><\/p>\n<p>\u0412 LoraConfig \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 target_modules : q_proj, k_proj, v_proj, o_proj, gate_proj \u0438 \u0434\u0440.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (Mistral, Qwen, Llama) \u2014 \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u044e\u0442 q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj.<\/p>\n<p><em>\u041a\u0430\u043a \u0432\u044b\u0431\u0440\u0430\u0442\u044c?<\/em> \u0415\u0441\u043b\u0438 \u043d\u0435 \u0437\u043d\u0430\u0435\u0448\u044c \u2014 \u043d\u0430\u0447\u043d\u0438 \u0441 q_proj \u0438 v_proj, \u043f\u043e\u0442\u043e\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439. \u0414\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Qwen) \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u2014 \u0441\u043c\u043e\u0442\u0440\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f Mistral:<\/p>\n<blockquote>\n<p><code>python   lora_config = LoraConfig(       target_modules=[\"q_proj\", \"k_proj\", \"v_proj\", \"o_proj\", \"gate_proj\", \"up_proj\", \"down_proj\"]   )<\/code><\/p>\n<\/blockquote>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/strong><\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f12\/b3d\/95b\/f12b3d95bb6d749d2e6a7dffdda48107.JPG\" width=\"892\" height=\"277\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/f12\/b3d\/95b\/f12b3d95bb6d749d2e6a7dffdda48107.JPG 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/f12\/b3d\/95b\/f12b3d95bb6d749d2e6a7dffdda48107.JPG 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>q_proj (Query projection)<\/strong>: \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0412\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0432\u0430\u0436\u043d\u043e\u0439 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. <\/p>\n<p><strong>k_proj (Key projection)<\/strong>: \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u043a\u043b\u044e\u0447\u0438 \u0434\u043b\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0447\u0430\u0441\u0442\u044f\u043c\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>v_proj (Value projection)<\/strong>: \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u0430. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0443\u044e \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p><strong>o_proj (Output projection)<\/strong>: \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u0412\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p><strong>gate_proj (Gate projection)<\/strong>: \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 FFN (feed-forward network) \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u043c, \u043a\u0430\u043a\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p><strong>up_proj (Up projection)<\/strong>: \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432 FFN. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u043e\u043b\u0435\u0435 \u0431\u043e\u0433\u0430\u0442\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b.<\/p>\n<p><strong>down_proj (Down projection)<\/strong>: \u0423\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 FFN. \u0421\u0436\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432\u0430\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u0438 \u0441\u0436\u0430\u0442\u0438\u0438.<\/p>\n<p><strong>\u0427\u0430\u0441\u0442\u043e\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/strong><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/803\/dcc\/9de\/803dcc9de8261d1b566b57814a6dd441.JPG\" width=\"899\" height=\"418\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/803\/dcc\/9de\/803dcc9de8261d1b566b57814a6dd441.JPG 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/803\/dcc\/9de\/803dcc9de8261d1b566b57814a6dd441.JPG 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438<\/strong><\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442<strong> lm_head<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0445 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 <strong>embed_tokens<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438 \u043a \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c \u0442\u043e\u043a\u0435\u043d\u0430\u043c <\/p>\n<\/li>\n<\/ul>\n<h3>5. \u0424\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/h3>\n<p><strong>HuggingFace Trainer, SFTTrainer, TRL \u2014 \u0447\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c?<\/strong><\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/788\/21b\/9f6\/78821b9f66ec9bcae172ff7393781ee1.JPG\" width=\"890\" height=\"340\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/788\/21b\/9f6\/78821b9f66ec9bcae172ff7393781ee1.JPG 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/788\/21b\/9f6\/78821b9f66ec9bcae172ff7393781ee1.JPG 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<p><strong>HuggingFace Trainer<\/strong> \u2014 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u0447, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 LoRA \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 PEFT.<\/p>\n<p><strong>SFTTrainer<\/strong> (\u0438\u0437 TRL) \u2014 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043b\u044f supervised fine-tuning (SFT, \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c), \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441 LoRA \u0438 \u0434\u043b\u044f instruction tuning. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0445 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445. SFT \u2014 \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0447\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043f\u0430\u0440\u0430\u0445 &#171;\u0432\u043e\u043f\u0440\u043e\u0441-\u043e\u0442\u0432\u0435\u0442&#187; \u0438\u043b\u0438 &#171;\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f-\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442&#187;, \u0433\u0434\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b. TRL (transformers reinforcement learning) \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 SFT, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0446\u0435\u043d\u043a\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 RLHF, reward modeling, PPO \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438. \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430 \u0441 LoRA, QLoRA \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 PEFT.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 SFTTrainer:<\/p>\n<blockquote>\n<p><code>python   from trl import SFTTrainer   trainer = SFTTrainer(       model=model,       args=training_args,       train_dataset=dataset   )   trainer.train()<\/code><\/p>\n<\/blockquote>\n<p><em>\u041a\u043e\u0433\u0434\u0430 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c?<\/em> \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u2014 \u0445\u0432\u0430\u0442\u0438\u0442 Trainer. \u0414\u043b\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0445 \u0438 instruction \u0437\u0430\u0434\u0430\u0447 \u2014 SFTTrainer.<\/p>\n<h3>6. \u041a\u0432\u0430\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p><strong>fp16 vs 8bit quantization<\/strong><\/p>\n<p>\u041a\u0432\u0430\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0437\u0430 \u0441\u0447\u0451\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u0435\u043b. <\/p>\n<p><strong>fp16<\/strong> \u2014 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u044d\u043a\u043e\u043d\u043e\u043c\u043d\u0435\u0435, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c. \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e\u043c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 GPU.<\/p>\n<p><strong>8bit\/4bit<\/strong> \u2014 \u0435\u0449\u0451 \u044d\u043a\u043e\u043d\u043e\u043c\u043d\u0435\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0435, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 QLoRA.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441 8bit:<\/p>\n<blockquote>\n<p><code>python   from transformers import BitsAndBytesConfig   bnb_config = BitsAndBytesConfig(load_in_8bit=True)   model = AutoModelForCausalLM.from_pretrained(       \"model_name\",       quantization_config=bnb_config   )<\/code><\/p>\n<\/blockquote>\n<h3>7. Instruction finetuning<\/h3>\n<p><strong>\u0427\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e?<\/strong><\/p>\n<p>Instruction finetuning \u2014 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0433\u0434\u0435 \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f (&#171;\u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0438 \u0442\u0435\u043a\u0441\u0442&#8230;&#187;, &#171;\u041e\u0442\u0432\u0435\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441&#8230;&#187;).<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438? \u0414\u0430, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 supervised fine-tuning (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f DeBERTa).<\/p>\n<p>\u0414\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 LoRA \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0441 DeBERTa:<\/p>\n<blockquote>\n<p><code>python   from transformers import Trainer   trainer = Trainer(       model=model,       args=training_args,       train_dataset=dataset   )   trainer.train()<\/code><\/p>\n<\/blockquote>\n<h3>8. \u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0434\u0435\u0442\u0430\u043b\u0438<\/h3>\n<p><strong>\u041a\u043e\u0433\u0434\u0430 \u0441\u0442\u043e\u0438\u0442 \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u043b\u043d\u043e\u0435 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435, \u0430 \u043a\u043e\u0433\u0434\u0430 \u0445\u0432\u0430\u0442\u0438\u0442 PEFT?<\/strong><\/p>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043e\u0447\u0435\u043d\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0430\u044f \u0438\u043b\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0435 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u2014 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043f\u0440\u043e\u0431\u043e\u0432\u0430\u0442\u044c full finetuning, \u043d\u043e \u044d\u0442\u043e \u0434\u043e\u0440\u043e\u0433\u043e.<\/p>\n<p>Task types \u0432 LoraConfig:<\/p>\n<ul>\n<li>\n<p>CAUSAL_LM: \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430, \u0447\u0430\u0442-\u0431\u043e\u0442\u044b, completion \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>FEATURE_EXTRACTION: \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432, \u043f\u043e\u0438\u0441\u043a \u043f\u043e\u0445\u043e\u0436\u0438\u0445 \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u043a\u043b\u0430\u0441\u0442\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>SEQ_CLS: \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u043e\u0432, \u0430\u043d\u0430\u043b\u0438\u0437 \u0442\u043e\u043d\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438, \u0434\u0435\u0442\u0435\u043a\u0446\u0438\u044f AI<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python   lora_config = LoraConfig(task_type=\"SEQ_2_SEQ_LM\")<\/code><\/p>\n<\/blockquote>\n<p><strong>\u041a\u0430\u043a\u043e\u0439 learning rate \u0432\u044b\u0431\u0440\u0430\u0442\u044c?<\/strong><\/p>\n<p>\u041e\u0431\u044b\u0447\u043d\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442 \u0441 1e-4 \u0434\u043b\u044f LoRA, 5e-5 \u0434\u043b\u044f QLoRA. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 learning rate finder \u0438\u043b\u0438 grid search. <\/p>\n<p><strong>\u041a\u0430\u043a\u043e\u0439 batch size \u043e\u043f\u0442\u0438\u043c\u0430\u043b\u0435\u043d?<\/strong><\/p>\n<p>\u041c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u043f\u0430\u043c\u044f\u0442\u044c. \u0414\u043b\u044f LoRA \u043e\u0431\u044b\u0447\u043d\u043e 4-16, \u0434\u043b\u044f QLoRA 1-4.<\/p>\n<p><strong>\u0421\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u043f\u043e\u0445 \u043d\u0443\u0436\u043d\u043e?<\/strong><\/p>\n<p>1-3 \u044d\u043f\u043e\u0445\u0438 \u0434\u043b\u044f LoRA, 3-5 \u0434\u043b\u044f QLoRA. \u0421\u043b\u0435\u0434\u0438 \u0437\u0430 validation loss.<\/p>\n<p><strong>\u041a\u0430\u043a \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435:<\/strong><\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 gradient accumulation \u0434\u043b\u044f \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0433\u043e batch size<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0439 mixed precision (fp16\/bf16)<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 DeepSpeed ZeRO \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439:<\/p>\n<ul>\n<li>\n<p>ZeRO (Zero Redundancy Optimizer) \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 GPU \u043f\u0430\u043c\u044f\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>Stage 1 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0438\u0440\u0443\u0435\u0442 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0442\u043e\u0440, Stage 2 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u0433\u0440\u0430\u0434\u0438\u0435\u043d\u0442\u044b, Stage 3 &#8212; \u0432\u0435\u0441\u0430 \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043d\u0444\u0438\u0433\u0430:<\/p>\n<blockquote>\n<p><code>python     # deepspeed_config.json     {       \"zero_optimization\": {         \"stage\": 2,         \"offload_optimizer\": {           \"device\": \"cpu\"         }       }     }<\/code><\/p>\n<\/blockquote>\n<ul>\n<li>\n<p>\u041a\u044d\u0448\u0438\u0440\u0443\u0439 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0434\u043b\u044f \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445:<\/p>\n<ul>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435 \u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043c\u0435\u0436\u0434\u0443 \u044d\u043f\u043e\u0445\u0430\u043c\u0438, \u043c\u043e\u0436\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0438\u0445 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 <\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043f\u043e\u043b\u0435\u0437\u043d\u043e \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u043e\u0432 \u0441 \u0434\u043b\u0438\u043d\u043d\u044b\u043c\u0438 \u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     # \u0421\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432     embeddings = model.get_input_embeddings()(input_ids)     <\/code><a href=\"http:\/\/torch.save\" rel=\"noopener noreferrer nofollow\"><code>torch.save<\/code><\/a><code>(embeddings, 'cached_<\/code><a href=\"http:\/\/embeddings.pt\" rel=\"noopener noreferrer nofollow\"><code>embeddings.pt<\/code><\/a><code>')          # \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043a\u044d\u0448\u0430     embeddings = torch.load('cached_<\/code><a href=\"http:\/\/embeddings.pt\" rel=\"noopener noreferrer nofollow\"><code>embeddings.pt<\/code><\/a><code>')<\/code><\/p>\n<\/blockquote>\n<p><strong>\u041c\u0435\u0442\u0440\u0438\u043a\u0438 \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>BLEU: \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u0442 n-\u0433\u0440\u0430\u043c\u043c\u044b \u0441\u0433\u0435\u043d\u0435\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u0438 \u044d\u0442\u0430\u043b\u043e\u043d\u043d\u043e\u0433\u043e \u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>ROUGE: \u043e\u0446\u0435\u043d\u0438\u0432\u0430\u0435\u0442 \u043f\u043e\u043b\u043d\u043e\u0442\u0443 \u0438 \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c \u0434\u043b\u044f \u0441\u0443\u043c\u043c\u0430\u0440\u0438\u0437\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<li>\n<p>METEOR: \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u0441\u0438\u043d\u043e\u043d\u0438\u043c\u044b \u0438 \u043c\u043e\u0440\u0444\u043e\u043b\u043e\u0433\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u044b<\/p>\n<\/li>\n<li>\n<p>BERTScore: \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f   (\u0412\u0441\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u043d\u0430 <a href=\"https:\/\/huggingface.co\/metrics\" rel=\"noopener noreferrer nofollow\">https:\/\/huggingface.co\/metrics<\/a>)<\/p>\n<\/li>\n<li>\n<p>\u041c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u0430\u044f \u043e\u0446\u0435\u043d\u043a\u0430:<br \/>&#8212; \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, ImageBind Similarity: \u043e\u0446\u0435\u043d\u043a\u0430 \u0447\u0435\u0440\u0435\u0437 \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u0443\u044e \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432<br \/>&#8212; \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0438 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u0435\u043d \u0434\u043b\u044f \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439 \u043a \u0432\u0438\u0434\u0435\u043e, \u0442\u0430\u043a \u043a\u0430\u043a ImageBind \u0445\u043e\u0440\u043e\u0448\u043e \u0443\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u0438 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432 \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0435<br \/>&#8212; \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f image-to-text \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u0430 \u0441\u0435\u043c\u0430\u043d\u0442\u0438\u0447\u0435\u0441\u043a\u0430\u044f \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u044c \u043c\u0435\u0436\u0434\u0443 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c\u0438<\/p>\n<\/li>\n<\/ul>\n<blockquote>\n<p><code>python       from imagebind import ImageBind              # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043c\u043e\u0434\u0435\u043b\u044c       model = ImageBind()              # \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0434\u043b\u044f \u0442\u0435\u043a\u0441\u0442\u0430 \u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\/\u0432\u0438\u0434\u0435\u043e       text_emb = model.encode_text(generated_text)       media_emb = model.encode_video(source_video) # \u0438\u043b\u0438 encode_image()              # \u0421\u0447\u0438\u0442\u0430\u0435\u043c \u043a\u043e\u0441\u0438\u043d\u0443\u0441\u043d\u0443\u044e \u0431\u043b\u0438\u0437\u043e\u0441\u0442\u044c       similarity = F.cosine_similarity(text_emb, media_emb)<\/code><\/p>\n<\/blockquote>\n<h3>9. \u0422\u044e\u043d\u0438\u043d\u0433 Vision-to-Text LLMs: Moondream2, VITA, InternVL, MiniCPM<\/h3>\n<p><strong>Vision-to-Text LLMs<\/strong> \u2014 \u044d\u0442\u043e \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 (\u0438\u043b\u0438 \u0432\u0438\u0434\u0435\u043e) \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u044e\u0442 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u043e\u0435 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435, \u043e\u0442\u0432\u0435\u0442 \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u0443\u044e \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u0443\u044e \u0437\u0430\u0434\u0430\u0447\u0443. \u0412 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0433\u043e\u0434\u044b \u043f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043c\u043d\u043e\u0433\u043e \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u0445 \u0438 \u043a\u043e\u043c\u043c\u0435\u0440\u0447\u0435\u0441\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c \u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<p><strong>\u041e\u0431\u0449\u0438\u0435 \u0441\u043e\u0432\u0435\u0442\u044b \u043f\u043e \u0442\u044e\u043d\u0438\u043d\u0433\u0443 Vision-to-Text LLMs<\/strong><\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0430\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u043e\u0431\u044b\u0447\u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u043f\u0430\u0440\u0430 (image, text) \u0438\u043b\u0438 (video, text).<\/p>\n<\/li>\n<li>\n<p>\u0412\u0430\u0436\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u044c \u0434\u0430\u0442\u0430\u0441\u0435\u0442: \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0438 \u0434\u043e\u043b\u0436\u043d\u044b \u0431\u044b\u0442\u044c \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0430 \u0442\u0435\u043a\u0441\u0442\u044b \u2014 \u0447\u0438\u0441\u0442\u044b\u043c\u0438 \u0438 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u044b\u043c\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f cross-entropy loss \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, \u043d\u043e \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0438\u0435 loss (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, BCE).<\/p>\n<\/li>\n<li>\n<p>\u0410\u0443\u0433\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439 (crop, resize, color jitter) \u043c\u043e\u0433\u0443\u0442 \u043f\u043e\u043c\u043e\u0447\u044c, \u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0442\u044c \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u044b\u043c \u2014 \u043c\u043e\u0434\u0435\u043b\u044c \u0434\u043e\u043b\u0436\u043d\u0430 \u0432\u0438\u0434\u0435\u0442\u044c &#171;\u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435&#187; \u0434\u0430\u043d\u043d\u044b\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0443\u0441\u043a\u043e\u0440\u0435\u043d\u0438\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c LoRA\/QLoRA, \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 PEFT.<\/p>\n<\/li>\n<\/ul>\n<p><strong>Moondream2<\/strong><\/p>\n<p>\u041e\u0442\u043a\u0440\u044b\u0442\u0430\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c (image-to-text, VQA).<\/p>\n<p>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430: CLIP-\u044d\u043d\u043a\u043e\u0434\u0435\u0440 + LLM (\u043e\u0441\u043d\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 Microsoft Phi, \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 Llama \u0438 Mistral).<\/p>\n<p>\u0414\u043b\u044f \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u0435\u043d \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u043f\u0430\u0440\u0430\u043c\u0438 (image, text\/question\/answer).<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (\u043d\u0430 HuggingFace):<\/p>\n<blockquote>\n<p><code>python   from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, Trainer   model = AutoModelForCausalLM.from_pretrained(\"vikhyatk\/moondream2\")   tokenizer = AutoTokenizer.from_pretrained(\"vikhyatk\/moondream2\")   # \u041f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u044c \u0441\u0432\u043e\u0439 \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 image_path \u0438 text   # ...   training_args = TrainingArguments(       output_dir=\".\/results\",       per_device_train_batch_size=4,       num_train_epochs=3,       fp16=True   )   trainer = Trainer(       model=model,       args=training_args,       train_dataset=your_dataset   )   trainer.train()<\/code><\/p>\n<\/blockquote>\n<p><em>\u0421\u043e\u0432\u0435\u0442\u044b: <\/em>\u043c\u043e\u0434\u0435\u043b\u044c \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0431\u044b\u0441\u0442\u0440\u043e, \u043d\u043e \u0432 \u043d\u0435\u0439 \u043d\u0435\u0442 system prompt (\u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 DeepSeekVL2, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u043c\u0435\u0434\u043b\u0435\u043d\u043d\u0435\u0435, \u043d\u043e \u0442\u043e\u0436\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0438 \u0438\u043c\u0435\u0435\u0442 system prompt). \u041c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0430\u043d\u0441\u0430\u043c\u0431\u043b\u044c \u0438\u0437 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0441 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u043c\u043f\u0442\u0430\u043c\u0438 \u0438 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0434\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0438 \u0440\u0430\u0437\u043d\u043e\u043e\u0431\u0440\u0430\u0437\u0438\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438. \u0422\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0447\u0430\u043d\u043a\u043e\u0432 \u0442\u0435\u043a\u0441\u0442\u0430 \u0434\u043b\u044f RAG \u0441 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435\u043c \u0432 \u0432\u0435\u043a\u0442\u043e\u0440\u043d\u0443\u044e \u0411\u0414 \u0442\u0435\u0445, \u0447\u0442\u043e \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u044e\u0442 \u043f\u043e\u0440\u043e\u0433 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438.<\/p>\n<p><strong>VITA (Vision-and-Text Aligned Multimodal LLM)<\/strong><\/p>\n<p>\u041c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u0430\u044f LLM, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043d\u0430 \u0432\u0445\u043e\u0434 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438 \u0442\u0435\u043a\u0441\u0442 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432\u043e\u043f\u0440\u043e\u0441) \u0438 \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u0442 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442 \u0438\u043b\u0438 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0435.<\/p>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447 VQA (\u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u043e\u043f\u0440\u043e\u0441-\u043e\u0442\u0432\u0435\u0442), image captioning, reasoning \u043f\u043e \u043a\u0430\u0440\u0442\u0438\u043d\u043a\u0435 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447.<\/p>\n<p>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430: \u0432\u0438\u0437\u0443\u0430\u043b\u044c\u043d\u044b\u0439 \u044d\u043d\u043a\u043e\u0434\u0435\u0440 (\u043e\u0431\u044b\u0447\u043d\u043e ViT \u0438\u043b\u0438 CLIP) + \u044f\u0437\u044b\u043a\u043e\u0432\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c (LLM) + \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u044c\u043d\u044b\u0435 \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b.<\/p>\n<p>\u0414\u043b\u044f \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u0435\u043d \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u043f\u0430\u0440\u0430\u043c\u0438 (image, text\/question, answer\/target).<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 LoRA-\u0442\u044e\u043d\u0438\u043d\u0433\u0430:<\/p>\n<blockquote>\n<p><code>python   from peft import LoraConfig, get_peft_model   lora_config = LoraConfig(       r=8, lora_alpha=32, target_modules=[\"vision_adapter\", \"text_adapter\"], lora_dropout=0.05   )   model = get_peft_model(base_model, lora_config)   # \u0414\u0430\u043b\u0435\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 Trainer<\/code><\/p>\n<\/blockquote>\n<p><em>\u0421\u043e\u0432\u0435\u0442\u044b:<\/em> \u0434\u043b\u044f VQA \u0438 captioning \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 loss (cross-entropy \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438, BCE \u0434\u043b\u044f multi-label). \u0412\u0430\u0436\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u043c\u043f\u0442\u044b (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, &#171;Q: &#8230; A: &#8230;&#187;).<\/p>\n<p><strong>InternVL<\/strong><\/p>\n<p>\u041c\u043e\u0449\u043d\u0430\u044f \u043a\u0438\u0442\u0430\u0439\u0441\u043a\u0430\u044f \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c (\u0430\u043d\u0430\u043b\u043e\u0433 LLaVA, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 VQA, captioning, reasoning).<\/p>\n<p>\u0414\u043b\u044f \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0434\u0430\u0442\u0430\u0441\u0435\u0442 \u0441 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f\u043c\u0438 \u0438 \u0442\u0435\u043a\u0441\u0442\u0430\u043c\u0438 (\u0438\u043b\u0438 \u0432\u043e\u043f\u0440\u043e\u0441\u0430\u043c\u0438\/\u043e\u0442\u0432\u0435\u0442\u0430\u043c\u0438).<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 (\u043d\u0430 PyTorch):<\/p>\n<blockquote>\n<p><code>python   # \u041e\u0431\u044b\u0447\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 training loop   for batch in dataloader:       images, texts = batch[\"image\"], batch[\"text\"]       outputs = model(images, texts)       loss = loss_fn(outputs, texts)       loss.backward()       optimizer.step()<\/code><\/p>\n<\/blockquote>\n<p><em>\u0421\u043e\u0432\u0435\u0442\u044b:<\/em> \u0432\u043d\u0438\u043c\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043b\u0435\u0434\u0438 \u0437\u0430 \u0444\u043e\u0440\u043c\u0430\u0442\u0430\u043c\u0438 \u0432\u0445\u043e\u0434\u0430 (\u0440\u0430\u0437\u043c\u0435\u0440\u044b, \u043d\u043e\u0440\u043c\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f), InternVL \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u0435\u043d \u043a preprocessing.<\/p>\n<p><strong>MiniCPM<\/strong><\/p>\n<p>\u041b\u0451\u0433\u043a\u0430\u044f \u0438 \u0431\u044b\u0441\u0442\u0440\u0430\u044f open-source Vision-to-Text \u043c\u043e\u0434\u0435\u043b\u044c, \u0445\u043e\u0440\u043e\u0448\u043e \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f edge-\u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0430 \u0438 \u0431\u044b\u0441\u0442\u0440\u044b\u0445 \u043f\u0440\u043e\u0442\u043e\u0442\u0438\u043f\u043e\u0432.<\/p>\n<p>\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 LoRA\/QLoRA \u0434\u043b\u044f \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 LoRA-\u0442\u044e\u043d\u0438\u043d\u0433\u0430:<\/p>\n<blockquote>\n<p><code>python   from peft import LoraConfig, get_peft_model   lora_config = LoraConfig(       r=4, lora_alpha=16, target_modules=[\"visual_adapter\", \"text_adapter\"], lora_dropout=0.1   )   model = get_peft_model(base_model, lora_config)   # Trainer \u0438\u043b\u0438 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 \u0446\u0438\u043a\u043b<\/code><\/p>\n<\/blockquote>\n<p><em>\u0421\u043e\u0432\u0435\u0442\u044b: <\/em>MiniCPM \u0445\u043e\u0440\u043e\u0448\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u0434\u0430\u0442\u0430\u0441\u0435\u0442\u0430\u0445, \u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0431\u043e\u0440\u0430 lr \u0438 batch size.<\/p>\n<p><strong>Best practices \u0438 \u043b\u0430\u0439\u0444\u0445\u0430\u043a\u0438<\/strong><\/p>\n<ul>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 mix precision (fp16\/bf16), \u0435\u0441\u043b\u0438 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0436\u0435\u043b\u0435\u0437\u043e.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u0435\u0439 (captioning) \u2014 cross-entropy loss, \u0434\u043b\u044f VQA \u2014 \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u043c loss.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0439 \u0432\u0430\u043b\u0438\u0434\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u0441\u0432\u043e\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445, \u0430 \u043d\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430 \u043f\u0443\u0431\u043b\u0438\u0447\u043d\u044b\u0445 \u0431\u0435\u043d\u0447\u043c\u0430\u0440\u043a\u0430\u0445.<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f inference \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c quantization (8bit\/4bit), \u0435\u0441\u043b\u0438 \u0432\u0430\u0436\u043d\u0430 \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u044c. \u0422\u0430\u043a\u0436\u0435 \u0445\u043e\u0440\u043e\u0448\u043e \u0443\u0441\u043a\u043e\u0440\u044f\u0435\u0442 \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441 vllm, sglang \u0434\u043e\u043b\u0436\u0435\u043d \u0443\u0441\u043a\u043e\u0440\u044f\u0442\u044c \u0435\u0449\u0435 \u043b\u0443\u0447\u0448\u0435, \u043d\u043e \u0435\u0433\u043e \u044f \u043d\u0435 \u043f\u0440\u043e\u0431\u043e\u0432\u0430\u043b \u0441 \u044d\u0442\u0438\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438.<\/p>\n<\/li>\n<\/ul>\n<h3>10. \u0424\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433 ImageBind \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 LoRA<\/h3>\n<p><strong>ImageBind<\/strong> \u2014 \u044d\u0442\u043e \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0442 Meta AI, \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u0430\u044f \u0441\u043e\u043f\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0439, \u0442\u0435\u043a\u0441\u0442\u0430, \u0430\u0443\u0434\u0438\u043e, \u0433\u043b\u0443\u0431\u0438\u043d\u044b, \u0442\u0435\u043f\u043b\u043e\u0432\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 IMU \u0432 \u0435\u0434\u0438\u043d\u043e\u043c \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u0435. \u0414\u043b\u044f \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0437\u0430\u0434\u0430\u0447 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043e\u0446\u0435\u043d\u043a\u0438 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0432\u0438\u0434\u0435\u043e\u043e\u043f\u0438\u0441\u0430\u043d\u0438\u0439) \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0439 \u043f\u0440\u0435\u0434\u043e\u0431\u0443\u0447\u0435\u043d\u043d\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0447\u0430\u0441\u0442\u043e \u043d\u0435\u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u2014 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433. <\/p>\n<ul>\n<li>\n<p><strong>HuggingFace<\/strong>: <a href=\"https:\/\/huggingface.co\/facebook\/imagebind-1.4b\" rel=\"noopener noreferrer nofollow\">https:\/\/huggingface.co\/facebook\/imagebind-1.4b<\/a><\/p>\n<\/li>\n<li>\n<p><strong>GitHub<\/strong>: <a href=\"https:\/\/github.com\/facebookresearch\/ImageBind\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/facebookresearch\/ImageBind<\/a><\/p>\n<\/li>\n<li>\n<p><strong>Paper<\/strong>: <a href=\"https:\/\/arxiv.org\/abs\/2305.05665\" rel=\"noopener noreferrer nofollow\">https:\/\/arxiv.org\/abs\/2305.05665<\/a><\/p>\n<\/li>\n<li>\n<p><strong>ImageBind-LoRA<\/strong>: <a href=\"https:\/\/github.com\/fabawi\/ImageBind-LoRA\" rel=\"noopener noreferrer nofollow\">https:\/\/github.com\/fabawi\/ImageBind-LoRA<\/a><\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u043e\u0447\u0435\u043c\u0443 \u0437\u0434\u0435\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f LoRA, \u0430 \u043d\u0435 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0439 PEFT?<\/p>\n<ul>\n<li>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 LLM \u0438 vision-to-text \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0433\u0434\u0435 LoRA \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442\u0441\u044f \u0447\u0435\u0440\u0435\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443 PEFT (HuggingFace), \u0434\u043b\u044f ImageBind \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f <strong>\u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f LoRA<\/strong>.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u0447\u0438\u043d\u044b:<\/p>\n<ul>\n<li>\n<p>\u0412 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u043c PEFT LoRA \u0435\u0441\u0442\u044c task_type (CAUSAL_LM, SEQ_2_SEQ_LM \u0438 \u0442.\u0434.), \u0430 \u0434\u043b\u044f ImageBind \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u0438\u0432\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432, \u0430 \u043d\u0435 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u043b\u0438 \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430 \u0433\u0438\u0431\u043a\u0430\u044f \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f LoRA-\u0441\u043b\u043e\u0451\u0432 \u0432 attention-\u043c\u043e\u0434\u0443\u043b\u0438 \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 (vision, text, audio \u0438 \u0434\u0440.).<\/p>\n<\/li>\n<li>\n<p>\u0422\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u044b\u0439 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044c \u043d\u0430\u0434 \u0442\u0435\u043c, \u043a\u0430\u043a\u0438\u0435 \u0441\u043b\u043e\u0438 \u0438 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u041a\u0430\u043a \u0443\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f LoRA \u0434\u043b\u044f ImageBind<\/strong><\/p>\n<p>LoRA \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u043a \u043f\u0440\u043e\u0435\u043a\u0446\u0438\u044f\u043c Query, Key, Value (QKV) \u0432 multi-head attention.<\/p>\n<p>\u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0435 attention-\u0441\u043b\u043e\u0438 \u0437\u0430\u043c\u0435\u043d\u044f\u044e\u0442\u0441\u044f \u043d\u0430 \u043e\u0431\u0451\u0440\u0442\u043a\u0443 \u0441 LoRA-\u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0435\u0439:<\/p>\n<blockquote>\n<p><code>python class <em>LoRALayer(nn.Module):     def <\/em>_init__(self, w: nn.Module, w_a: nn.Module, w_b: nn.Module):         super().__init__()         self.w = w  # \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 attention \u0441\u043b\u043e\u0439         self.w_a = w_a  # LoRA \u043c\u0430\u0442\u0440\u0438\u0446\u0430 A (dim \u2192 rank)         self.w_b = w_b  # LoRA \u043c\u0430\u0442\u0440\u0438\u0446\u0430 B (rank \u2192 dim)          def forward(self, x: torch.Tensor, attn_mask: torch.Tensor, **kwargs):         # \u041a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u0443\u0435\u043c \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438 LoRA-\u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0439 \u0432\u044b\u0445\u043e\u0434\u044b         return self.w(x, attn_mask=attn_mask) + self.w_b(self.w_a(x))<\/code><\/p>\n<\/blockquote>\n<p>\u0412\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0431\u0430\u0437\u043e\u0432\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0437\u0430\u043c\u043e\u0440\u0430\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f (<code>requires_grad=False<\/code>), \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e LoRA-\u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b.<\/p>\n<p>LoRA \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u044b\u043c \u0441\u043b\u043e\u044f\u043c \u0438 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, vision \u0438 text).<\/p>\n<p><strong>\u041e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u043e\u0433\u043e LoRA\/PEFT<\/strong><\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"329\" width=\"329\">\n<p align=\"center\"><strong>\u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 LoRA (PEFT)<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u0430\u044f LoRA \u0434\u043b\u044f ImageBind<\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"329\" width=\"329\">\n<p align=\"left\">\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 task_type<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041d\u0435\u0442 task_type, \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u0438\u0432\u043d\u044b\u0439 loss<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"329\" width=\"329\">\n<p align=\"left\">\u0418\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044f \u0447\u0435\u0440\u0435\u0437 HuggingFace<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041f\u0440\u044f\u043c\u043e\u0435 \u0432\u043d\u0435\u0434\u0440\u0435\u043d\u0438\u0435 \u0432 PyTorch-\u043a\u043e\u0434 \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"329\" width=\"329\">\n<p align=\"left\">\u041f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438\/\u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0422\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u0438\u0432\u043d\u043e\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u043e\u0432<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"329\" width=\"329\">\n<p align=\"left\">\u0410\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u0432\u044b\u0431\u043e\u0440 \u0441\u043b\u043e\u0451\u0432<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0420\u0443\u0447\u043d\u043e\u0439 \u0432\u044b\u0431\u043e\u0440 \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0435\u0439 \u0438 attention-\u0441\u043b\u043e\u0451\u0432<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"329\" width=\"329\">\n<p align=\"left\">\u0421\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u043e\u0441\u0442\u044c \u0441 Trainer\/SFTTrainer<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u041a\u0430\u0441\u0442\u043e\u043c\u043d\u044b\u0439 train loop \u0438\u043b\u0438 \u0441\u043a\u0440\u0438\u043f\u0442\u044b<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0433\u043e LoRA-\u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u0430<\/strong><\/p>\n<p>\u0411\u0430\u0437\u043e\u0432\u044b\u0439 \u0437\u0430\u043f\u0443\u0441\u043a:<\/p>\n<blockquote>\n<p><code>bash python <\/code><a href=\"http:\/\/train.py\" rel=\"noopener noreferrer nofollow\"><code>train.py<\/code><\/a><code> --batch_size 12 --max_epochs 500 \\         --lora --lora_modality_names vision text \\         --self_contrast --datasets dreambooth \\         --device cuda:0<\/code><\/p>\n<\/blockquote>\n<p>\u0412\u044b\u0431\u043e\u0440\u043e\u0447\u043d\u043e\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0435 LoRA \u043a \u0441\u043b\u043e\u044f\u043c:<\/p>\n<blockquote>\n<p><code>bash python <\/code><a href=\"http:\/\/train.py\" rel=\"noopener noreferrer nofollow\"><code>train.py<\/code><\/a><code> --batch_size 12 --max_epochs 500 \\         --lora --lora_modality_names vision text \\         --lora_layer_idxs_vision 1 2 3 4 5 6 \\         --self_contrast --datasets dreambooth<\/code><\/p>\n<\/blockquote>\n<p>\u0414\u0432\u0443\u0445\u044d\u0442\u0430\u043f\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434: Linear Probing + LoRA<\/p>\n<blockquote>\n<p><code>bash # \u042d\u0442\u0430\u043f 1: Linear Probing (\u0442\u043e\u043b\u044c\u043a\u043e heads) python <\/code><a href=\"http:\/\/train.py\" rel=\"noopener noreferrer nofollow\"><code>train.py<\/code><\/a><code> --batch_size 12 --max_epochs 500 \\         --linear_probing --lora_modality_names vision text \\         --self_contrast --datasets dreambooth  # \u042d\u0442\u0430\u043f 2: LoRA Fine-tuning (\u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0430 heads \u0438\u0437 \u044d\u0442\u0430\u043f\u0430 1) python <\/code><a href=\"http:\/\/train.py\" rel=\"noopener noreferrer nofollow\"><code>train.py<\/code><\/a><code> --batch_size 12 --max_epochs 500 \\         --lora --lora_modality_names vision text \\         --self_contrast --datasets dreambooth<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043b\u044e\u0447\u0435\u0432\u044b\u0435 \u0433\u0438\u043f\u0435\u0440\u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b:<br \/>&#8212; LoRA rank: 4\u201316 (\u043e\u0431\u044b\u0447\u043d\u043e 4)<br \/>&#8212; Learning rate: 5e-6<br \/>&#8212; Batch size: 12\u201332<br \/>&#8212; Temperature (\u0434\u043b\u044f InfoNCE): 0.07<br \/>&#8212; Weight decay: 1e-4<br \/>&#8212; Gradient clipping: 1.0<\/p>\n<p>\u0418\u043d\u0444\u0435\u0440\u0435\u043d\u0441 \u0441 \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 LoRA<\/p>\n<blockquote>\n<p><code>python import torch from models import imagebind_model from models import lora as LoRA from models.imagebind_model import ModalityType, load_module  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u0431\u0430\u0437\u043e\u0432\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c ImageBind model = imagebind_model.imagebind_huge(pretrained=True)  # \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c LoRA \u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b model.modality_trunks.update(     LoRA.apply_lora_modality_trunks(         model.modality_trunks,          rank=4,         modality_names=[ModalityType.TEXT, <\/code><a href=\"http:\/\/ModalityType.VISION\" rel=\"noopener noreferrer nofollow\"><code>ModalityType.VISION<\/code><\/a><code>]     ) )  # \u0417\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u043c \u043e\u0431\u0443\u0447\u0435\u043d\u043d\u044b\u0435 LoRA \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b LoRA.load_lora_modality_trunks(     model.modality_trunks,     checkpoint_dir=\".checkpoints\/lora\/550_epochs_lora\",      postfix=\"_dreambooth_last\" ) model.eval()<\/code><\/p>\n<\/blockquote>\n<p><strong>\u041f\u0440\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u0441\u043e\u0432\u0435\u0442\u044b<\/strong><\/p>\n<ul>\n<li>\n<p>\u041d\u0430\u0447\u0438\u043d\u0430\u0439 \u0441 Linear Probing, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0438\u0441\u043f\u043e\u0440\u0442\u0438\u0442\u044c \u0431\u0430\u0437\u043e\u0432\u044b\u0435 \u044d\u043c\u0431\u0435\u0434\u0434\u0438\u043d\u0433\u0438.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0439 LoRA \u0442\u043e\u043b\u044c\u043a\u043e \u043a \u043d\u0443\u0436\u043d\u044b\u043c \u043c\u043e\u0434\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044f\u043c \u0438 \u0441\u043b\u043e\u044f\u043c.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439 InfoNCE loss \u0434\u043b\u044f \u043a\u043e\u043d\u0442\u0440\u0430\u0441\u0442\u0438\u0432\u043d\u043e\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0439 \u0442\u043e\u043b\u044c\u043a\u043e LoRA-\u0430\u0434\u0430\u043f\u0442\u0435\u0440\u044b (\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438).<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u043b\u043e\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c comet-ml \u0438\u043b\u0438 wandb.<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0412\u0430\u0436\u043d\u043e\u0435 \u043e\u0442\u043b\u0438\u0447\u0438\u0435<\/strong><\/p>\n<p>\u0412 \u043e\u0442\u043b\u0438\u0447\u0438\u0435 \u043e\u0442 \u043a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0445 LLM\/vision-to-text \u043c\u043e\u0434\u0435\u043b\u0435\u0439, \u0437\u0434\u0435\u0441\u044c LoRA \u0432\u043d\u0435\u0434\u0440\u044f\u0435\u0442\u0441\u044f \u0432\u0440\u0443\u0447\u043d\u0443\u044e \u0432 PyTorch-\u043a\u043e\u0434, \u0430 \u043d\u0435 \u0447\u0435\u0440\u0435\u0437 PEFT\/Trainer. \u042d\u0442\u043e \u0434\u0430\u0451\u0442 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c, \u043d\u043e \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043d\u044b\u0445 \u0443\u0441\u0438\u043b\u0438\u0439.<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/925886\/\"> https:\/\/habr.com\/ru\/articles\/925886\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041c\u0435\u043d\u044f \u0437\u043e\u0432\u0443\u0442 \u0418\u0432\u0430\u043d \u0418\u0441\u0430\u0435\u0432, \u044f \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0441\u044c \u041c\u041b \u0441 2014 \u0433\u043e\u0434\u0430, \u0440\u0443\u043a\u043e\u0432\u043e\u0434\u0438\u043b \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u041c\u041b \u0432 \u043a\u0440\u0443\u043f\u043d\u043e\u043c \u0442\u0435\u043b\u0435\u043a\u043e\u043c\u0435, \u043e\u0442\u0434\u0435\u043b\u043e\u043c \u041c\u041b \u0432 \u043a\u0440\u0443\u043f\u043d\u043e\u0439 RTB \u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u0433\u043e\u0434\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u044e \u0432\u0435\u0434\u0443\u0449\u0438\u043c \u0438\u043d\u0436\u0435\u043d\u0435\u0440\u043e\u043c \u0432 \u0431\u043b\u043e\u043a\u0447\u0435\u0439\u043d-\u043a\u043e\u043c\u043f\u0430\u043d\u0438\u0438 \u0432\u043d\u0443\u0442\u0440\u0438 \u044d\u043a\u043e\u0441\u0438\u0441\u0442\u0435\u043c\u044b Bittensor.  \u041b\u044e\u0431\u043b\u044e \u043f\u043e\u0440\u0435\u0448\u0430\u0442\u044c Kaggle \u0441\u043e\u0440\u0435\u0432\u044b, \u0438 \u043f\u043e\u0442\u0440\u0430\u0442\u0438\u0432 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0432\u0440\u0435\u043c\u044f \u0441\u043c\u043e\u0433 \u043f\u0440\u043e\u043a\u0430\u0447\u0430\u0442\u044c\u0441\u044f \u0434\u043e \u043c\u0430\u0441\u0442\u0435\u0440\u0430. \u041f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0435 \u043f\u0430\u0440\u0443 \u043b\u0435\u0442 \u043c\u043d\u043e\u0433\u043e \u0443\u043f\u0440\u0430\u0436\u043d\u044f\u043b\u0441\u044f \u0441 NLP \u0438 LLM \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0438 \u0434\u0440\u0443\u0433\u0438\u0445 \u0437\u0430\u0434\u0430\u0447, \u0432 \u0442\u043e\u043c \u0447\u0438\u0441\u043b\u0435 \u0441 \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u043c\u043e\u0434\u0435\u043b\u044f\u043c\u0438 (ImageBind, VITA \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438).  \u0412 Bittensor \u0443 \u043c\u0435\u043d\u044f \u0431\u044b\u043b\u043e \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447, \u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u044f \u0441\u043c\u043e\u0433 \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u043e\u043c LLM \u0434\u043b\u044f \u043f\u0440\u043e\u0434\u043e\u0432\u044b\u0445 \u0437\u0430\u0434\u0430\u0447. \u0412 \u044d\u0442\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u044f \u0445\u043e\u0442\u0435\u043b \u0431\u044b \u0440\u0430\u0441\u0441\u043a\u0430\u0437\u0430\u0442\u044c \u043f\u0440\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0434\u0435\u0442\u0430\u043b\u0438 \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043d\u0435 \u043a\u0430\u0436\u0443\u0442\u0441\u044f \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b\u043c\u0438 (\u043c\u043e\u0439 \u043f\u0435\u0440\u0432\u044b\u0439 \u043e\u043f\u044b\u0442 \u0441 \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433\u043e\u043c \u0431\u044b\u043b \u043d\u0430 Kaggle \u0441 Mistral, \u043a\u043e\u0433\u0434\u0430 \u044f <a href=\"https:\/\/www.kaggle.com\/code\/cdeotte\/mistral-7b-baseline-lb-0-7x\/notebook?scriptVersionId=172773538\" rel=\"noopener noreferrer nofollow\">\u043f\u0440\u043e\u0447\u0435\u043b \u044d\u0442\u043e\u0442 \u043f\u043e\u0441\u0442<\/a>).<\/p>\n<blockquote>\n<p>\u042f \u043d\u0430\u0447\u043d\u0443 \u0441 \u0431\u0430\u0437\u043e\u0432\u044b\u0445 \u0432\u0435\u0449\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u044b \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u043c, \u0430 \u0431\u043b\u0438\u0436\u0435 \u043a \u043a\u043e\u043d\u0446\u0443 \u0441\u0442\u0430\u0442\u044c\u0438 \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443 \u043f\u0440\u043e \u0442\u044e\u043d\u0438\u043d\u0433 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u0438\u0445 Vision-to-Text LLMs, \u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u043c\u0438 \u0434\u043e\u0432\u0435\u043b\u043e\u0441\u044c \u043f\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0430 \u043f\u0440\u043e\u0434\u0435, \u0438 \u043f\u0440\u043e \u0444\u0430\u0439\u043d\u0442\u044e\u043d\u0438\u043d\u0433 ImageBind \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043a\u0430\u0441\u0442\u043e\u043c\u043d\u043e\u0439 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 LoRA.<\/p>\n<\/blockquote>\n<h3>1. \u0412\u0432\u0435\u0434\u0435\u043d\u0438\u0435<\/h3>\n<h4>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 LLM \u0438 \u0437\u0430\u0447\u0435\u043c \u043e\u043d\u043e \u043d\u0443\u0436\u043d\u043e?<\/h4>\n<p>\u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 \u044f\u0437\u044b\u043a\u043e\u0432\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (LLM) \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0445 \u043f\u043e\u0434 \u0441\u0432\u043e\u0438 \u0437\u0430\u0434\u0430\u0447\u0438, \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u0438\u0445 \u0443\u043c\u043d\u0435\u0435 \u043d\u0430 \u0441\u0432\u043e\u0438\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u0441\u044d\u043a\u043e\u043d\u043e\u043c\u0438\u0442\u044c \u0440\u0435\u0441\u0443\u0440\u0441\u044b. <\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0441\u0442\u043e\u0438\u0442 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c, \u0430 \u043a\u043e\u0433\u0434\u0430 \u0445\u0432\u0430\u0442\u0438\u0442 prompt engineering \u0438\u043b\u0438 RAG? \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u0430\u044f \u0438\u043b\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043c\u043d\u043e\u0433\u043e \u2014 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0439. \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u2014 \u043f\u043e\u043f\u0440\u043e\u0431\u0443\u0439 \u0441\u043d\u0430\u0447\u0430\u043b\u0430 \u043f\u0440\u043e\u043c\u043f\u0442\u044b.<\/p>\n<h3>2. PEFT \u0438 \u0435\u0433\u043e \u0440\u0430\u0437\u043d\u043e\u0432\u0438\u0434\u043d\u043e\u0441\u0442\u0438<\/h3>\n<h4>PEFT (Parameter-Efficient Fine-Tuning) \u2014 \u0447\u0442\u043e \u044d\u0442\u043e \u0438 \u0437\u0430\u0447\u0435\u043c?<\/h4>\n<p>PEFT \u2014 \u044d\u0442\u043e \u0446\u0435\u043b\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u043c\u0435\u0442\u043e\u0434\u043e\u0432, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0447\u0430\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u043c\u043e\u0434\u0435\u043b\u0438, \u044d\u043a\u043e\u043d\u043e\u043c\u044f \u043f\u0430\u043c\u044f\u0442\u044c \u0438 \u0443\u0441\u043a\u043e\u0440\u044f\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435. LoRA \u2014 \u043b\u0438\u0448\u044c \u043e\u0434\u0438\u043d \u0438\u0437 \u043d\u0438\u0445! <\/p>\n<figure class=\"full-width\"><\/figure>\n<div class=\"floating-image\">\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b PEFT:<\/strong><\/p>\n<\/div>\n<ul>\n<li>\n<p><strong>LoRA (Low-Rank Adaptation):<\/strong><br \/>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 low-rank \u043c\u0430\u0442\u0440\u0438\u0446\u044b \u043a \u0437\u0430\u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u044b\u043c \u0432\u0435\u0441\u0430\u043c. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0431\u0435\u0437 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0431\u043d\u043e\u0432\u043b\u044f\u0442\u044c \u0432\u0441\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import LoraConfig, get_peft_model     lora_config = LoraConfig(         r=8,         lora_alpha=32,         target_modules=[\"q_proj\", \"v_proj\"],         lora_dropout=0.05,         bias=\"none\"     )     lora_model = get_peft_model(base_model, lora_config)<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0438\u0442\u044c LLM \u043d\u0430 \u0441\u0432\u043e\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0435 \u0441 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u043c\u0438 \u0437\u0430\u0442\u0440\u0430\u0442\u0430\u043c\u0438 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439.<\/p>\n<ul>\n<li>\n<p><strong>QLoRA (Quantized LoRA):<\/strong><br \/>\u0421\u043e\u0447\u0435\u0442\u0430\u0435\u0442 LoRA \u0438 4-bit \u043a\u0432\u0430\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u0435 (\u0447\u0435\u0440\u0435\u0437 bitsandbytes). \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u0436\u0435 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0435 \u0441 24\u0413\u0411 \u043f\u0430\u043c\u044f\u0442\u0438 \u0434\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 33B+.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from transformers import BitsAndBytesConfig     bnb_config = BitsAndBytesConfig(         load_in_4bit=True,         bnb_4bit_compute_dtype=torch.float16,         bnb_4bit_quant_type=\"nf4\"     )     # \u0414\u0430\u043b\u0435\u0435 \u043f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u043c LoRA \u043a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u043e\u0447\u0435\u043d\u044c \u043c\u0430\u043b\u043e \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0431\u043e\u043b\u044c\u0448\u0430\u044f.<\/p>\n<ul>\n<li>\n<p><strong>AdaLoRA:<\/strong><br \/>\u0410\u0434\u0430\u043f\u0442\u0438\u0432\u043d\u0430\u044f \u0432\u0435\u0440\u0441\u0438\u044f LoRA, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u0438\u043d\u0430\u043c\u0438\u0447\u0435\u0441\u043a\u0438 \u0438\u0437\u043c\u0435\u043d\u044f\u0435\u0442 \u0440\u0430\u043d\u043a (\u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c low-rank \u043c\u0430\u0442\u0440\u0438\u0446) \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f.<br \/><strong>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e? <\/strong>\u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0438 \u043d\u0430 \u0440\u0430\u0437\u043d\u044b\u0445 \u044d\u0442\u0430\u043f\u0430\u0445 \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0437\u043d\u0430\u044f &#171;\u0433\u0438\u0431\u043a\u043e\u0441\u0442\u044c&#187; \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438, AdaLoRA \u0441\u0430\u043c\u0430 \u043f\u043e\u0434\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442 \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u0442\u0440\u0430\u0442\u0438\u0442\u044c \u043b\u0438\u0448\u043d\u0438\u0435 \u0440\u0435\u0441\u0443\u0440\u0441\u044b.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import AdaLoraConfig     adalora_config = AdaLoraConfig(         init_r=12,      # \u043d\u0430\u0447\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u043d\u043a         target_r=8,     # \u0446\u0435\u043b\u0435\u0432\u043e\u0439 \u0440\u0430\u043d\u043a         beta1=0.85,         beta2=0.85,         target_modules=[\"q_proj\", \"v_proj\"]     )<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u0443 \u0442\u0435\u0431\u044f \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u044b \u0440\u0435\u0441\u0443\u0440\u0441\u044b, \u043d\u043e \u0445\u043e\u0447\u0435\u0442\u0441\u044f \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u043e\u0442\u0434\u0430\u0447\u0438 \u043e\u0442 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043d\u0435 \u0442\u0440\u0438\u0432\u0438\u0430\u043b\u044c\u043d\u0430\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043b\u043e\u0436\u043d\u0430\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u0438\u043b\u0438 \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f).<\/p>\n<ul>\n<li>\n<p><strong>BitFit:<\/strong><br \/>\u0414\u043e\u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e bias-\u0442\u0435\u0440\u043c\u044b (\u0441\u043c\u0435\u0449\u0435\u043d\u0438\u044f) \u0432 \u0441\u043b\u043e\u044f\u0445 \u043c\u043e\u0434\u0435\u043b\u0438, \u0432\u0441\u0435 \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0432\u0435\u0441\u0430 \u043e\u0441\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u0430\u043c\u043e\u0440\u043e\u0436\u0435\u043d\u043d\u044b\u043c\u0438.<br \/><strong>\u0417\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u043d\u0443\u0436\u043d\u043e?<\/strong> \u042d\u0442\u043e \u0441\u0430\u043c\u044b\u0439 &#171;\u043b\u0451\u0433\u043a\u0438\u0439&#187; \u0441\u043f\u043e\u0441\u043e\u0431 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f, \u043f\u043e\u0447\u0442\u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043f\u0430\u043c\u044f\u0442\u0438 \u0438 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0439, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0434\u0430\u0442\u044c \u043f\u0440\u0438\u0440\u043e\u0441\u0442 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043d\u0430 \u043f\u0440\u043e\u0441\u0442\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import BitFitConfig     bitfit_config = BitFitConfig(         bias_pattern=[\"bias\", \"LayerNorm.bias\"],         modules_to_save=None     )<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0431\u0438\u043d\u0430\u0440\u043d\u0430\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u044f), \u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u043e\u0432 \u0441\u043e\u0432\u0441\u0435\u043c \u043c\u0430\u043b\u043e, \u0438\u043b\u0438 \u0435\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0435\u0441\u0442\u044c \u043b\u0438 \u0441\u043c\u044b\u0441\u043b \u0432 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0438 \u0432\u043e\u043e\u0431\u0449\u0435.<\/p>\n<ul>\n<li>\n<p><strong>Prefix Tuning:<\/strong><br \/>\u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0431\u0443\u0447\u0430\u0435\u043c\u044b\u0435 \u0432\u0438\u0440\u0442\u0443\u0430\u043b\u044c\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u043a \u0432\u0445\u043e\u0434\u0443 \u043c\u043e\u0434\u0435\u043b\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 &#171;\u043f\u043e\u0434\u0441\u043a\u0430\u0437\u044b\u0432\u0430\u044e\u0442&#187; \u0435\u0439, \u043a\u0430\u043a \u0441\u0435\u0431\u044f \u0432\u0435\u0441\u0442\u0438.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import PrefixTuningConfig     prefix_config = PrefixTuningConfig(         num_virtual_tokens=20, task_type=\"CAUSAL_LM\"     )<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447, \u0433\u0434\u0435 \u0432\u0430\u0436\u043d\u043e \u0437\u0430\u0434\u0430\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0438\u043b\u0438 \u0441\u0442\u0438\u043b\u044c \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438.<\/p>\n<ul>\n<li>\n<p>P-Tuning:<br \/>\u041f\u043e\u0445\u043e\u0436 \u043d\u0430 Prefix Tuning, \u043d\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u0438\u043d\u0430\u0447\u0435. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 soft prompts, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043c\u043e\u0434\u0435\u043b\u044c\u044e.<\/p>\n<\/li>\n<\/ul>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440:<\/p>\n<blockquote>\n<p><code>python     from peft import PromptTuningConfig     ptuning_config = PromptTuningConfig(         num_virtual_tokens=10,         task_type=\"CAUSAL_LM\"     )<\/code><\/p>\n<\/blockquote>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c? \u0414\u043b\u044f \u0437\u0430\u0434\u0430\u0447, \u0433\u0434\u0435 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0438\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043a\u043e\u043b\u0438\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u0432 (few-shot).<\/p>\n<p><strong>\u0421\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0435 \u043c\u0435\u0442\u043e\u0434\u043e\u0432:<\/strong><\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"center\"><strong>\u041c\u0435\u0442\u043e\u0434<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"center\"><strong>\u041f\u0430\u043c\u044f\u0442\u044c<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"center\"><strong>\u0421\u043a\u043e\u0440\u043e\u0441\u0442\u044c<\/strong><\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"center\"><strong>\u0414\u043b\u044f \u0447\u0435\u0433\u043e \u043b\u0443\u0447\u0448\u0435 \u0432\u0441\u0435\u0433\u043e<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"center\"><strong>\u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0438  <\/strong><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">LoRA<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u043d\u0438\u0437\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">\u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e LLM<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u043f\u0440\u043e\u0441\u0442\u043e \u0432\u043d\u0435\u0434\u0440\u044f\u0442\u044c<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">QLoRA<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u043e\u0447\u0435\u043d\u044c \u043d\u0438\u0437\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438, \u043c\u0430\u043b\u043e RAM<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0442\u0440\u0435\u0431\u0443\u0435\u0442 \u043a\u0432\u0430\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u044f<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">AdaLoRA<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u043d\u0438\u0437\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">\u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438, \u0434\u0438\u043d\u0430\u043c\u0438\u043a\u0430<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0440\u0430\u043d\u043a \u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">P-Tuning<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u0441\u0440\u0435\u0434\u043d\u044f\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">prompt-based \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0445\u043e\u0440\u043e\u0448 \u0434\u043b\u044f few-shot<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td data-colwidth=\"104\" width=\"104\">\n<p align=\"left\">BitFit<\/p>\n<\/td>\n<td data-colwidth=\"117\" width=\"117\">\n<p align=\"left\">\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"103\" width=\"103\">\n<p align=\"left\">\u0432\u044b\u0441\u043e\u043a\u0430\u044f<\/p>\n<\/td>\n<td data-colwidth=\"194\" width=\"194\">\n<p align=\"left\">\u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0442\u043e\u043b\u044c\u043a\u043e bias<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3>3. LoRA \u2014 Low-Rank Adaptation<\/h3>\n<p><strong>\u0427\u0442\u043e \u0442\u0430\u043a\u043e\u0435 LoRA \u0438 \u043a\u0430\u043a \u043e\u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442?<\/strong><\/p>\n<p>LoRA \u2014 \u044d\u0442\u043e \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0438\u0437\u043a\u043e\u0440\u0430\u043d\u0433\u043e\u0432\u044b\u0435 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438 \u043a \u0432\u0435\u0441\u0430\u043c \u043c\u043e\u0434\u0435\u043b\u0438. \u0412\u043c\u0435\u0441\u0442\u043e \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0435\u0431\u043e\u043b\u044c\u0448\u0438\u0435 \u043c\u0430\u0442\u0440\u0438\u0446\u044b, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0431\u0443\u0447\u0430\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u043e\u0439 \u0437\u0430\u0434\u0430\u0447\u0438.<\/p>\n<figure class=\"full-width\"><\/figure>\n<h3>4. \u041a\u0430\u043a\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0438 \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u0442\u044c?<\/h3>\n<p><strong>\u041e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b<\/strong><\/p>\n<p>\u0412 LoraConfig \u0435\u0441\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440 target_modules : q_proj, k_proj, v_proj, o_proj, gate_proj \u0438 \u0434\u0440.<\/p>\n<p>\u0414\u043b\u044f \u0440\u0430\u0437\u043d\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (Mistral, Qwen, Llama) \u2014 \u043e\u0431\u044b\u0447\u043d\u043e \u0434\u043e\u043e\u0431\u0443\u0447\u0430\u044e\u0442 q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj.<\/p>\n<p><em>\u041a\u0430\u043a \u0432\u044b\u0431\u0440\u0430\u0442\u044c?<\/em> \u0415\u0441\u043b\u0438 \u043d\u0435 \u0437\u043d\u0430\u0435\u0448\u044c \u2014 \u043d\u0430\u0447\u043d\u0438 \u0441 q_proj \u0438 v_proj, \u043f\u043e\u0442\u043e\u043c \u044d\u043a\u0441\u043f\u0435\u0440\u0438\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0439. \u0414\u043b\u044f \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u043c\u043e\u0434\u0435\u043b\u0435\u0439 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, Qwen) \u0441\u043f\u0438\u0441\u043e\u043a \u043c\u043e\u0436\u0435\u0442 \u043e\u0442\u043b\u0438\u0447\u0430\u0442\u044c\u0441\u044f \u2014 \u0441\u043c\u043e\u0442\u0440\u0438 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430\u0446\u0438\u044e \u0438\u043b\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u0438\u043a\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f Mistral:<\/p>\n<blockquote>\n<p><code>python   lora_config = LoraConfig(       target_modules=[\"q_proj\", \"k_proj\", \"v_proj\", \"o_proj\", \"gate_proj\", \"up_proj\", \"down_proj\"]   )<\/code><\/p>\n<\/blockquote>\n<p><strong>\u041e\u043f\u0438\u0441\u0430\u043d\u0438\u0435 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/strong><\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435 \u043f\u0440\u043e \u043a\u0430\u0436\u0434\u044b\u0439 \u043c\u043e\u0434\u0443\u043b\u044c:<\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>q_proj (Query projection)<\/strong>: \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0442\u043e\u043a\u0435\u043d\u044b \u0432 \u0437\u0430\u043f\u0440\u043e\u0441\u044b. \u0412\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0442\u043e, \u043a\u0430\u043a\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u0447\u0438\u0442\u0430\u0435\u0442 \u0432\u0430\u0436\u043d\u043e\u0439 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u0444\u043e\u043a\u0443\u0441\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u043e\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0434\u043b\u044f \u0432\u0430\u0448\u0435\u0439 \u0437\u0430\u0434\u0430\u0447\u0438. <\/p>\n<p><strong>k_proj (Key projection)<\/strong>: \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u043a\u043b\u044e\u0447\u0438 \u0434\u043b\u044f \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u043d\u0434\u0435\u043a\u0441\u0438\u0440\u0443\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c \u0441\u0432\u044f\u0437\u0438 \u043c\u0435\u0436\u0434\u0443 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u0447\u0430\u0441\u0442\u044f\u043c\u0438 \u0432\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p><strong>v_proj (Value projection)<\/strong>: \u041f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u0442 \u0432\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f. \u041e\u0442\u0432\u0435\u0447\u0430\u0435\u0442 \u0437\u0430 \u0444\u0430\u043a\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u0435, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043b\u044f \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0432\u044b\u0445\u043e\u0434\u0430. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u0443\u044e \u0434\u043b\u044f \u0437\u0430\u0434\u0430\u0447\u0438 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p><strong>o_proj (Output projection)<\/strong>: \u041e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u044b \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u044f. \u0412\u043b\u0438\u044f\u0435\u0442 \u043d\u0430 \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u043e\u0435 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0443\u043b\u0443\u0447\u0448\u0430\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u0442\u043e\u0433\u043e\u0432\u044b\u0439 \u043e\u0442\u0432\u0435\u0442.<\/p>\n<p><strong>gate_proj (Gate projection)<\/strong>: \u041a\u043e\u043d\u0442\u0440\u043e\u043b\u0438\u0440\u0443\u0435\u0442 \u043f\u043e\u0442\u043e\u043a \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u0432 \u043c\u043e\u0434\u0435\u043b\u0438. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 FFN (feed-forward network) \u0434\u043b\u044f \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u043c, \u043a\u0430\u043a\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f \u043f\u0440\u043e\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0434\u0430\u043b\u044c\u0448\u0435. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u0440\u0435\u043b\u0435\u0432\u0430\u043d\u0442\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<p><strong>up_proj (Up projection)<\/strong>: \u0423\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u0432 FFN. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u0441 \u0431\u043e\u043b\u0435\u0435 \u0431\u043e\u0433\u0430\u0442\u044b\u043c\u0438 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u0442 \u0441\u043f\u043e\u0441\u043e\u0431\u043d\u043e\u0441\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u0438 \u0443\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0442\u044c \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u044b.<\/p>\n<p><strong>down_proj (Down projection)<\/strong>: \u0423\u043c\u0435\u043d\u044c\u0448\u0430\u0435\u0442 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 FFN. \u0421\u0436\u0438\u043c\u0430\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0434\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438. \u0414\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u0438 \u043b\u0443\u0447\u0448\u0435 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c \u0432\u0430\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043f\u0440\u0438 \u0441\u0436\u0430\u0442\u0438\u0438.<\/p>\n<p><strong>\u0427\u0430\u0441\u0442\u043e\u0442\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u0445 \u043c\u043e\u0434\u0443\u043b\u0435\u0439<\/strong><\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043c\u043e\u0434\u0443\u043b\u0438<\/strong><\/p>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442<strong> lm_head<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u0414\u043b\u044f \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044f \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u0438 \u0442\u0435\u043a\u0441\u0442\u0430<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0433\u0434\u0430 \u043d\u0443\u0436\u043d\u043e \u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u044b\u0445\u043e\u0434\u043d\u043e\u0439 \u0441\u043b\u043e\u0439<\/p>\n<\/li>\n<li>\n<p>\u0412 \u0441\u043b\u043e\u0436\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u0445 \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0439 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u044e\u0442 <strong>embed_tokens<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u041f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u043d\u043e\u0432\u044b\u043c \u0441\u043b\u043e\u0432\u0430\u0440\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\u0414\u043b\u044f \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u043d\u0430 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043e\u0431\u043b\u0430\u0441\u0442\u0438<\/p>\n<\/li>\n<li>\n<p>\u041f\u0440\u0438 \u0430\u0434\u0430\u043f\u0442\u0430\u0446\u0438\u0438 \u043a \u0441\u043f\u0435\u0446\u0438\u0444\u0438\u0447\u043d\u044b\u043c \u0442\u043e\u043a\u0435\u043d\u0430\u043c <\/p>\n<\/li>\n<\/ul>\n<h3>5. \u0424\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0438 \u0438 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b<\/h3>\n<p><strong>HuggingFace Trainer, SFTTrainer, TRL \u2014 \u0447\u0442\u043e \u0432\u044b\u0431\u0440\u0430\u0442\u044c?<\/strong><\/p>\n<figure class=\"full-width\"><\/figure>\n<p><strong>HuggingFace Trainer<\/strong> \u2014 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u0434\u043b\u044f \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u0438 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439. \u041f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u0430 \u0437\u0430\u0434\u0430\u0447, \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 LoRA \u0447\u0435\u0440\u0435\u0437 \u0438\u043d\u0442\u0435\u0433\u0440\u0430\u0446\u0438\u044e \u0441 PEFT.<\/p>\n<p><strong>SFTTrainer<\/strong> (\u0438\u0437 TRL) \u2014 \u0441\u043f\u0435\u0446\u0438\u0430\u043b\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043b\u044f supervised fine-tuning (SFT, \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0441 \u0443\u0447\u0438\u0442\u0435\u043b\u0435\u043c), \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0441 LoRA \u0438 \u0434\u043b\u044f instruction tuning. \u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043b\u0435\u0433\u043a\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0445 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u044b\u0445 \u0437\u0430\u0434\u0430\u0447\u0430\u0445. SFT \u2014 \u044d\u0442\u043e \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0443\u0447\u0438\u043c \u043c\u043e\u0434\u0435\u043b\u044c \u043d\u0430 \u043f\u0430\u0440\u0430\u0445 &#171;\u0432\u043e\u043f\u0440\u043e\u0441-\u043e\u0442\u0432\u0435\u0442&#187; \u0438\u043b\u0438 &#171;\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f-\u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442&#187;, \u0433\u0434\u0435 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u0435 \u043e\u0442\u0432\u0435\u0442\u044b \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0438\u0437\u0432\u0435\u0441\u0442\u043d\u044b. TRL (transformers reinforcement learning) \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0443\u0434\u043e\u0431\u043d\u044b\u0435 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442\u044b \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 SFT, \u0432\u043a\u043b\u044e\u0447\u0430\u044f \u0444\u043e\u0440\u043c\u0430\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u0446\u0435\u043d\u043a\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 RLHF, reward modeling, PPO \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0434\u0440\u0443\u0433\u0438\u0435 \u043f\u0440\u043e\u0434\u0432\u0438\u043d\u0443\u0442\u044b\u0435 \u0442\u0435\u0445\u043d\u0438\u043a\u0438. \u0411\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0441\u043e\u0432\u043c\u0435\u0441\u0442\u0438\u043c\u0430 \u0441 LoRA, QLoRA \u0438 \u0434\u0440\u0443\u0433\u0438\u043c\u0438 \u043c\u0435\u0442\u043e\u0434\u0430\u043c\u0438 PEFT.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 SFTTrainer:<\/p>\n<blockquote>\n<p><code>python   from trl import SFTTrainer   trainer = SFTTrainer(       model=model,       args=training_args,       train_dataset=dataset   )   trainer.train()<\/code><\/p>\n<\/blockquote>\n<p><em>\u041a\u043e\u0433\u0434\u0430 \u0447\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c?<\/em> \u0415\u0441\u043b\u0438 \u0437\u0430\u0434\u0430\u0447\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u2014 \u0445\u0432\u0430\u0442\u0438\u0442 Trainer. \u0414\u043b\u044f \u0434\u0438\u0430\u043b\u043e\u0433\u043e\u0432\u044b\u0445 \u0438 instruction \u0437\u0430\u0434\u0430\u0447 \u2014 SFTTrainer.<\/p>\n<h3>6. \u041a\u0432\u0430\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u0435<\/h3>\n<p><strong>fp16 vs 8bit quantization<\/strong><\/p>\n<p>\u041a\u0432\u0430\u043d\u0442\u043e\u0432\u0430\u043d\u0438\u0435 \u2014 \u044d\u0442\u043e \u0441\u043f\u043e\u0441\u043e\u0431 \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043f\u0430\u043c\u044f\u0442\u044c \u0437\u0430 \u0441\u0447\u0451\u0442 \u0443\u043c\u0435\u043d\u044c\u0448\u0435\u043d\u0438\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u0438 \u0447\u0438\u0441\u0435\u043b. <\/p>\n<p><strong>fp16<\/strong> \u2014 \u0431\u044b\u0441\u0442\u0440\u0435\u0435 \u0438 \u044d\u043a\u043e\u043d\u043e\u043c\u043d\u0435\u0435, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u0442\u0435\u0440\u044f\u0435\u0442\u0441\u044f \u0442\u043e\u0447\u043d\u043e\u0441\u0442\u044c. \u041f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u043d\u0441\u0442\u0432\u043e\u043c \u0441\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 GPU.<\/p>\n<p><strong>8bit\/4bit<\/strong> \u2014 \u0435\u0449\u0451 \u044d\u043a\u043e\u043d\u043e\u043c\u043d\u0435\u0435, \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u043e\u0434\u043d\u043e\u0439 \u0432\u0438\u0434\u0435\u043e\u043a\u0430\u0440\u0442\u0435, \u043d\u043e \u043d\u0435 \u0432\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438 \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u044e\u0442\u0441\u044f. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 QLoRA.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0437\u0430\u043f\u0443\u0441\u043a\u0430 \u0441 8bit:<\/p>\n<blockquote>\n<p><code>python   from transformers import BitsAndBytesConfig   bnb_config = BitsAndBytesConfig(load_in_8bit=True)   model = AutoModelForCausalLM.from_pretrained(       \"model_name\",       quantization_config=bnb_config   )<\/code><\/p>\n<\/blockquote>\n<h3>7. Instruction finetuning<\/h3>\n<p><strong>\u0427\u0442\u043e \u044d\u0442\u043e \u0442\u0430\u043a\u043e\u0435 \u0438 \u0434\u043b\u044f \u0447\u0435\u0433\u043e?<\/strong><\/p>\n<p>Instruction finetuning \u2014 \u0434\u043e\u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u043d\u0430 \u0437\u0430\u0434\u0430\u0447\u0430\u0445, \u0433\u0434\u0435 \u0432 \u043f\u0440\u043e\u043c\u043f\u0442\u0435 \u044f\u0432\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u043d\u0430 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044f (&#171;\u041f\u0435\u0440\u0435\u0432\u0435\u0434\u0438 \u0442\u0435\u043a\u0441\u0442&#8230;&#187;, &#171;\u041e\u0442\u0432\u0435\u0442\u044c \u043d\u0430 \u0432\u043e\u043f\u0440\u043e\u0441&#8230;&#187;).<\/p>\n<p>\u041c\u043e\u0436\u043d\u043e \u043b\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438? \u0414\u0430, \u043d\u043e \u0438\u043d\u043e\u0433\u0434\u0430 \u043f\u0440\u043e\u0449\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u044b\u0447\u043d\u044b\u0439 supervised fine-tuning (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f DeBERTa).<\/p>\n<p>\u0414\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 LoRA \u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u0435\u043d, \u043d\u043e \u043c\u043e\u0436\u0435\u0442 \u0443\u0441\u043a\u043e\u0440\u0438\u0442\u044c \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u0435 \u0438 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u0442\u0440\u0435\u0431\u043e\u0432\u0430\u043d\u0438\u044f \u043a \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u043a\u043b\u0430\u0441\u0441\u0438\u0444\u0438\u043a\u0430\u0446\u0438\u0438 \u0441 DeBERTa:<\/p>\n<blockquote>\n<p><code>python   from<\/code><\/p>\n<\/blockquote>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-466450","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=466450"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/466450\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=466450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=466450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=466450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}