Views
No views yet
1## 🧠 Example: Inference with Unsloth FastLanguageModel
2
3You can run this model using [Unsloth](https://github.com/unslothai/unsloth) for optimized 4-bit inference:
4
5
6
7# Uploaded model
8
9- **Developed by:** gbalachandhiran
10- **License:** apache-2.0
11- **Finetuned from model :** unsloth/gpt-oss-20b-unsloth-bnb-4bit
12
13This gpt_oss model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
14
15[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
16
17```python
18from unsloth import FastLanguageModel
19from transformers import TextStreamer
20from huggingface_hub import login
21
22# Optional: login if your model is private
23# login("YOUR_HF_TOKEN")
24
25model, tokenizer = FastLanguageModel.from_pretrained(
26 model_name = "gbalachandhiran/oss_psychologist_merged_model_4bit",
27 max_seq_length = 2048,
28 dtype = None,
29 load_in_4bit = True,
30)
31
32FastLanguageModel.for_inference(model) # Enable inference mode
33
34messages = [
35 {
36 "role": "user",
37 "content": "Can you help me with insomnia?"
38 }
39]
40
41inputs = tokenizer.apply_chat_template(
42 messages,
43 add_generation_prompt=False,
44 return_tensors="pt",
45 return_dict=True,
46 reasoning_effort="medium"
47).to("cuda")
48
49text_streamer = TextStreamer(tokenizer, skip_prompt=True)
50
51print("Psychologist AI:")
52outputs = model.generate(
53 **inputs,
54 max_new_tokens=150,
55 temperature=0.9,
56 top_p=0.99,
57 streamer=text_streamer,
58 do_sample=False,
59)