Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,6 +18,43 @@ from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
|
|
| 18 |
from langchain.llms.huggingface_pipeline import HuggingFacePipeline
|
| 19 |
from huggingface_hub import login
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
# Load the model and tokenizer
|
| 23 |
# model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
|
|
|
|
| 18 |
from langchain.llms.huggingface_pipeline import HuggingFacePipeline
|
| 19 |
from huggingface_hub import login
|
| 20 |
|
| 21 |
+
#### Model Testing ###########
|
| 22 |
+
print(f"-- Model test started")
|
| 23 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 24 |
+
|
| 25 |
+
model_name = "Qwen/Qwen2.5-0.5B-Instruct"
|
| 26 |
+
|
| 27 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 28 |
+
model_name,
|
| 29 |
+
)
|
| 30 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 31 |
+
|
| 32 |
+
prompt = "Give me a short introduction to large language model."
|
| 33 |
+
messages = [
|
| 34 |
+
{"role": "system", "content": "You are Qwen, created by Alibaba Cloud. You are a helpful assistant."},
|
| 35 |
+
{"role": "user", "content": prompt}
|
| 36 |
+
]
|
| 37 |
+
text = tokenizer.apply_chat_template(
|
| 38 |
+
messages,
|
| 39 |
+
tokenize=False,
|
| 40 |
+
add_generation_prompt=True
|
| 41 |
+
)
|
| 42 |
+
print(f"-- Model Invoking")
|
| 43 |
+
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
|
| 44 |
+
|
| 45 |
+
generated_ids = model.generate(
|
| 46 |
+
**model_inputs,
|
| 47 |
+
max_new_tokens=512
|
| 48 |
+
)
|
| 49 |
+
generated_ids = [
|
| 50 |
+
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
|
| 51 |
+
]
|
| 52 |
+
|
| 53 |
+
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
|
| 54 |
+
print(f"-- Model testresponse{model_inputs}")
|
| 55 |
+
|
| 56 |
+
##########################
|
| 57 |
+
|
| 58 |
|
| 59 |
# Load the model and tokenizer
|
| 60 |
# model_name = "deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B"
|