Views
No views yet
transformers library. We advise you to use version 4.40.0 or higher. Using older versions may result in unexpected errors.pip install --upgrade transformers1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3
4model_name = "Billy-Liu-DUT/OmniChem-7B-v1"
5
6model = AutoModelForCausalLM.from_pretrained(
7 model_name,
8 torch_dtype="auto", # or torch.bfloat16 for better performance
9 device_map="auto"
10)
11tokenizer = AutoTokenizer.from_pretrained(model_name)
12
13# Example prompt for a chemistry task
14prompt = "Plan a synthetic route for the small molecule drug lidocaine."
15messages = [
16 {"role": "system", "content": "You are a chemistry expert. Your task is to answer the user's problem using the most academic and rigorous professor-level language in a structured format. Think step by step."},
17 {"role": "user", "content": prompt}
18]
19
20text = tokenizer.apply_chat_template(
21 messages,
22 tokenize=False,
23 add_generation_prompt=True
24)
25model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
26
27generated_ids = model.generate(
28 **model_inputs,
29 max_new_tokens=1024,
30 do_sample=True,
31 temperature=0.7,
32 top_p=0.9,
33)
34generated_ids = [
35 output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
36]
37
38response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
39print(response)1{
2 "rope_scaling": {
3 "factor": 4.0,
4 "original_max_position_embeddings": 32768,
5 "type": "yarn"
6 }
7}