Views
No views yet
1pip install transformers torch
2pip install accelerate
3pip install -U transformers1
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4tokenizer = AutoTokenizer.from_pretrained("EpistemeAI/Fireball-R1.1-Llama-3.1-8B")
5model = AutoModelForCausalLM.from_pretrained("EpistemeAI/Fireball-R1.1-Llama-3.1-8B")
6
7prompt = "Calculate the molar mass of sulfuric acid (H₂SO₄)."
8inputs = tokenizer(prompt, return_tensors="pt")
9outputs = model.generate(**inputs, max_length=200)
10print(tokenizer.decode(outputs[0], skip_special_tokens=True))
11
12
13##advance inference 8bit
14import torch
15from transformers import AutoTokenizer, AutoModelForCausalLM
16
17# Load the tokenizer
18tokenizer = AutoTokenizer.from_pretrained("EpistemeAI/Fireball-R1.1-Llama-3.1-8B")
19
20# Load the model in 8-bit precision using bitsandbytes (requires a CUDA GPU)
21model = AutoModelForCausalLM.from_pretrained(
22 "EpistemeAI/Fireball-R1.1-Llama-3.1-8B",
23 load_in_8bit=True, # Enable 8-bit loading to reduce memory usage
24 device_map="auto" # Automatically map model layers to the available device(s)
25)
26
27# Define the system prompt and the user prompt
28system_prompt = "You are a highly knowledgeable assistant with expertise in chemistry and physics. <think>"
29user_prompt = "Calculate the molar mass of sulfuric acid (H₂SO₄)."
30
31# Combine the system prompt with the user prompt. The format here follows a common convention for chat-like interactions.
32full_prompt = f"System: {system_prompt}\nUser: {user_prompt}\nAssistant:"
33
34# Tokenize the combined prompt and move the inputs to the GPU
35inputs = tokenizer(full_prompt, return_tensors="pt").to("cuda")
36
37# Generate output text from the model
38outputs = model.generate(**inputs, max_length=12200)
39
40# Decode and print the result, skipping special tokens
41result = tokenizer.decode(outputs[0], skip_special_tokens=True)
42print(result)
43
44## inference with 4bit:
45from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig, pipeline
46import torch
47
48# Define the quantization configuration for 4-bit mode.
49quant_config = BitsAndBytesConfig(
50 load_in_4bit=True,
51 bnb_4bit_quant_type="nf4", # Alternative: "fp4" (choose based on your model)
52 bnb_4bit_compute_dtype=torch.float16, # Use FP16 for computations
53 bnb_4bit_use_double_quant=True, # Optionally enable double quantization for better accuracy
54)
55
56# Load the tokenizer.
57tokenizer = AutoTokenizer.from_pretrained("EpistemeAI/Fireball-R1.1-Llama-3.1-8B")
58
59# Load the model with the 4-bit quantization configuration.
60model = AutoModelForCausalLM.from_pretrained(
61 "EpistemeAI/Fireball-R1.1-Llama-3.1-8B",
62 quantization_config=quant_config,
63 device_map="auto" # Automatically assigns model parts to available devices
64)
65
66# Create a text-generation pipeline.
67pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
68
69# Provide a text prompt and generate output.
70prompt = "How does the location of the Sydney Conservatorium of Music impact the academic and professional opportunities available to music students, and how does the conservatorium support student engagement with the music industry in Australia? output<think>"
71output = pipe(prompt)
72print(output)
731outputs = model.generate(
2 **inputs,
3 max_length=300,
4 temperature=0.7,
5 top_p=0.95,
6 repetition_penalty=1.2
7) @misc{Fireball-R1-Llama-3.1-8B,
author = {EpistemeAI},
title = {Fireball-R1-8B: A Neutral, Science-Optimized Language Model},
year = {2025},
url = {https://huggingface.co/EpistemeAI/Fireball-R1-Llama-3.1-8B}
}