1from unsloth import FastLanguageModel
2import torch
3max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
4dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
5load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
6model, tokenizer = FastLanguageModel.from_pretrained(
7 model_name = "saishshinde15/Clyrai_Vortex",
8 max_seq_length = max_seq_length,
9 dtype = dtype,
10 load_in_4bit = load_in_4bit
11)
12
13FastLanguageModel.for_inference(model)
14instruction = """You are an advanced AI assistant. Provide answers in a clear, step-by-step manner."""""
15
16messages = [
17 {"role": "system", "content": instruction},
18 {"role": "user", "content": "who made you?"}
19]
20
21# Apply chat template (without tokenization but adding a generation prompt)
22prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
23
24# Tokenize prompt properly for model input
25inputs = tokenizer(prompt, return_tensors='pt', padding=True, truncation=True).to("cuda")
26
27# Generate response
28outputs = model.generate(**inputs, max_new_tokens=1500, num_return_sequences=1)
29
30# Decode output correctly
31text = tokenizer.decode(outputs[0], skip_special_tokens=True)
32
33# Extract assistant response safely
34assistant_start = text.find("assistant")
35if assistant_start != -1:
36 response = text[assistant_start + len("assistant"):].strip()
37else:
38 response = text # Fallback: return full text if "assistant" is not found
39
40print(response)
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch
3
4# Load tokenizer and model
5model_name = "saishshinde15/Clyrai_Vortex"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForCausalLM.from_pretrained(model_name)
8
9# Move model to GPU if available
10device = "cuda" if torch.cuda.is_available() else "cpu"
11model.to(device)
12
13# Define the system instruction
14instruction = """You are an advanced AI assistant. Provide answers in a clear, step-by-step manner."""
15
16# Prepare input prompt using chat template
17messages = [
18 {"role": "system", "content": instruction},
19 {"role": "user", "content": "Who made you?"}
20]
21
22# Format the prompt
23prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
24
25# Tokenize input
26inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True).to(device)
27
28# Generate response with proper sampling parameters
29output_ids = model.generate(
30 **inputs,
31 max_new_tokens=1500,
32 temperature=0.8,
33 top_p=0.95,
34 do_sample=True,
35)
36
37# Decode output correctly
38response = tokenizer.decode(output_ids[0], skip_special_tokens=True)
39
40# Extract assistant response safely
41assistant_start = response.find("assistant")
42if assistant_start != -1:
43 response = response[assistant_start + len("assistant"):].strip()
44
45print(response)