Views
No views yet
The instruct version through supervised fine-tuning (SFT) using a mix of public and proprietary datasets. Additionally, applied Direct Preference Optimization (DPO) to fine-tune the model for more accurate and contextually relevant responses.
pip install transformers1from transformers import AutoModelForCausalLM, AutoTokenizer
2
3checkpoint = "prithivMLmods/SmolLM2-1.7B-Open-Thought"
4device = "cuda" # Use "cpu" for CPU execution
5
6tokenizer = AutoTokenizer.from_pretrained(checkpoint)
7model = AutoModelForCausalLM.from_pretrained(checkpoint).to(device)
8
9messages = [{"role": "user", "content": "What is the capital of France?"}]
10input_text = tokenizer.apply_chat_template(messages, tokenize=False)
11inputs = tokenizer.encode(input_text, return_tensors="pt").to(device)
12outputs = model.generate(inputs, max_new_tokens=50, temperature=0.2, top_p=0.9, do_sample=True)
13print(tokenizer.decode(outputs[0]))npm i @huggingface/transformers1import { pipeline } from "@huggingface/transformers";
2
3// Create a text generation pipeline
4const generator = await pipeline(
5 "text-generation",
6 "prithivMLmods/SmolLM2-1.7B-Open-Thought",
7);
8
9// Define the list of messages
10const messages = [
11 { role: "system", content: "You are a helpful assistant." },
12 { role: "user", content: "Tell me a joke." },
13];
14
15// Generate a response
16const output = await generator(messages, { max_new_tokens: 128 });
17console.log(output[0].generated_text.at(-1).content);
18// Example Output: "Why don't scientists trust atoms?\n\nBecause they make up everything!"1import json
2import re
3from typing import Optional
4from jinja2 import Template
5import torch
6from transformers import AutoModelForCausalLM, AutoTokenizer
7from transformers.utils import get_json_schema
8
9system_prompt = Template("""You are an expert in composing functions. You are given a question and a set of possible functions.
10Based on the question, you will need to make one or more function/tool calls to achieve the purpose.
11If none of the functions can be used, point it out and refuse to answer.
12If the given question lacks the parameters required by the function, also point it out.
13
14You have access to the following tools:
15<tools>{{ tools }}</tools>
16
17The output MUST strictly adhere to the following format, and NO other text MUST be included.
18<tool_call>[{"name": "func_name1", "arguments": {"argument1": "value1", "argument2": "value2"}}]</tool_call>""")
19
20# Define model and tokenizer
21model_name_smollm = "prithivMLmods/SmolLM2-1.7B-Open-Thought"
22model = AutoModelForCausalLM.from_pretrained(model_name_smollm, device_map="auto", torch_dtype="auto", trust_remote_code=True)
23tokenizer = AutoTokenizer.from_pretrained(model_name_smollm)
24
25from datetime import datetime
26import random
27
28def get_current_time() -> str:
29 return datetime.now().strftime("%H:%M:%S")
30
31def get_random_number_between(min: int, max: int) -> int:
32 return random.randint(min, max)
33
34tools = [get_json_schema(get_random_number_between), get_json_schema(get_current_time)]
35toolbox = {"get_random_number_between": get_random_number_between, "get_current_time": get_current_time}
36
37query = "Give me a number between 1 and 300"
38messages = [{"role": "system", "content": system_prompt.render(tools=json.dumps(tools))}, {"role": "user", "content": query}]
39
40inputs = tokenizer.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
41outputs = model.generate(inputs, max_new_tokens=512, do_sample=False, num_return_sequences=1, eos_token_id=tokenizer.eos_token_id)
42result = tokenizer.decode(outputs[0][len(inputs[0]):], skip_special_tokens=True)
43
44print(result)