From 8c2d07de9307d8ac0e9249b01e5656709603215d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=9C=D0=B0=D0=B7=D1=83=D1=80=20=D0=93=D1=80=D0=B5=D1=82?=
 =?UTF-8?q?=D0=B0=20=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D1=8C=D0=B5=D0=B2=D0=BD?=
 =?UTF-8?q?=D0=B0?= <gemazur_1@edu.hse.ru>
Date: Tue, 25 Mar 2025 11:20:10 +0300
Subject: [PATCH] obuch with cross and graphic SAVING LORA

---
 .ipynb_checkpoints/checkLora-checkpoint.py | 25 ++++++++++++++++++----
 checkLora.py                               | 25 ++++++++++++++++++----
 2 files changed, 42 insertions(+), 8 deletions(-)

diff --git a/.ipynb_checkpoints/checkLora-checkpoint.py b/.ipynb_checkpoints/checkLora-checkpoint.py
index 10ddf8e..45ccfe0 100644
--- a/.ipynb_checkpoints/checkLora-checkpoint.py
+++ b/.ipynb_checkpoints/checkLora-checkpoint.py
@@ -1,5 +1,22 @@
-from peft import PeftConfig
+from transformers import BertModel, BertTokenizer
+from peft import PeftModel
+import torch
 
-config = PeftConfig.from_pretrained("./fine-tuned-bert-lora")
-print("Базовая модель:", config.base_model_name_or_path)
-print("LoRA config:", config)
\ No newline at end of file
+device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
+
+# Загружаем базовую модель
+base_model = BertModel.from_pretrained("bert-base-uncased").to(device)
+
+# Загружаем адаптер LoRA
+model = PeftModel.from_pretrained(base_model, "./fine-tuned-bert-lora_new").to(device)
+
+# Загружаем токенизатор
+tokenizer = BertTokenizer.from_pretrained("./fine-tuned-bert-lora_new")
+
+# Пример инференса
+text = "This is a test prompt."
+inputs = tokenizer(text, return_tensors="pt").to(device)
+with torch.no_grad():
+    outputs = model(**inputs)
+
+print("LoRA адаптер загружен, выходы модели:", outputs)
\ No newline at end of file
diff --git a/checkLora.py b/checkLora.py
index 10ddf8e..45ccfe0 100644
--- a/checkLora.py
+++ b/checkLora.py
@@ -1,5 +1,22 @@
-from peft import PeftConfig
+from transformers import BertModel, BertTokenizer
+from peft import PeftModel
+import torch
 
-config = PeftConfig.from_pretrained("./fine-tuned-bert-lora")
-print("Базовая модель:", config.base_model_name_or_path)
-print("LoRA config:", config)
\ No newline at end of file
+device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
+
+# Загружаем базовую модель
+base_model = BertModel.from_pretrained("bert-base-uncased").to(device)
+
+# Загружаем адаптер LoRA
+model = PeftModel.from_pretrained(base_model, "./fine-tuned-bert-lora_new").to(device)
+
+# Загружаем токенизатор
+tokenizer = BertTokenizer.from_pretrained("./fine-tuned-bert-lora_new")
+
+# Пример инференса
+text = "This is a test prompt."
+inputs = tokenizer(text, return_tensors="pt").to(device)
+with torch.no_grad():
+    outputs = model(**inputs)
+
+print("LoRA адаптер загружен, выходы модели:", outputs)
\ No newline at end of file
-- 
GitLab