إحدى الميزات الرئيسية لـ Phi-4 هي قدرته القوية على الاستدلال. دعونا نلقي نظرة على هذه القدرة القوية في الاستدلال من خلال Phi-4-mini.
import torch
from transformers import AutoTokenizer,pipeline
model_path = "Your Phi-4-mini location"
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="cuda",
attn_implementation="flash_attention_2",
torch_dtype="auto",
trust_remote_code=True)
tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)
messages = [
{"role": "system", "content": "You are a helpful AI assistant."},
{"role": "user", "content": """I have $20,000 in my savings account, where I receive a 4% profit per year and payments twice a year. Can you please tell me how long it will take for me to become a millionaire? Thinks step by step carefully.
"""},
]
pipe = pipeline(
"text-generation",
model=model,
tokenizer=tokenizer,
)
generation_args = {
"max_new_tokens": 4096,
"return_full_text": False,
"temperature": 0.00001,
"top_p": 1.0,
"do_sample": True,
}
output = pipe(messages, **generation_args)
print(output[0]['generated_text'])
إخلاء المسؤولية:
تمت ترجمة هذا المستند باستخدام خدمات الترجمة الآلية المعتمدة على الذكاء الاصطناعي. بينما نسعى لتحقيق الدقة، يُرجى العلم بأن الترجمات الآلية قد تحتوي على أخطاء أو معلومات غير دقيقة. يجب اعتبار المستند الأصلي بلغته الأصلية هو المصدر الموثوق. للحصول على معلومات حاسمة، يُوصى بالاستعانة بترجمة بشرية احترافية. نحن غير مسؤولين عن أي سوء فهم أو تفسيرات خاطئة تنشأ عن استخدام هذه الترجمة.