image

LlamaScientific-8B

Built with Llama.

LlamaScientific-8B is a fine-tune of Llama 3.1 8B Instruct for science problem solving with Python tool use in physics, chemistry and biology. It was trained on multi-step solutions in which the model writes code, reads the tool output, and then gives a final answer. The model introduces itself as Llama-Scientific-8B, with no system prompt needed.

Model details

Developed by Rumiii
Base model meta-llama/Llama-3.1-8B-Instruct (Meta)
Type Decoder-only causal language model, QLoRA supervised fine-tune, LoRA merged into 16-bit weights
Language English
Trained on sequences up to about 12k tokens (the base model supports up to 128k)
License Llama 3.1 Community License

Intended use

  • Science question answering and worked problems in physics, chemistry and biology, where calculations can be delegated to a Python tool.
  • Research and education, and as a starting point for further tool-calling fine-tunes.

It is not intended for medical, safety-critical or other high-stakes decisions. Always verify its answers.

Benchmarking

LlamaScientific-8B was benchmarked on 852 samples across Biology (281), Chemistry (310), and Physics (261). It achieved a reported strict tool-call-format success rate of 89.7% in Biology, 88.7% in Chemistry, and 87.0% in Physics, averaging 88.5% across the sample. Interestingly, Biology performed best despite having substantially fewer training samples. These results are promising for an experimental scientific tool-calling model, but they measure format-level success—not scientific answer accuracy or successful code execution—and further evaluation is needed.

Quick start

Requires transformers, torch and about 16 GB of GPU memory in 16-bit.

import json, subprocess, sys
from transformers import AutoTokenizer, AutoModelForCausalLM

MODEL_ID = "Rumiii/LlamaScientific-8B"
tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype="auto", device_map="auto")

def generate(messages, tools=None, max_new_tokens=1024):
    text = tokenizer.apply_chat_template(messages, tools=tools, tokenize=False,
                                         add_generation_prompt=True)
    inputs = tokenizer(text, add_special_tokens=False, return_tensors="pt").to(model.device)
    out = model.generate(**inputs, max_new_tokens=max_new_tokens, do_sample=False,
                         pad_token_id=tokenizer.pad_token_id or tokenizer.eos_token_id)
    return tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True).strip()

# 1) Plain chat (no system prompt needed)
print(generate([{"role": "user", "content": "Who are you?"}]))

# 2) Science question with a Python tool
TOOLS = [{"type": "function", "function": {
    "name": "evaluate_code",
    "description": "Evaluates the input string as Python code and returns the stdout. Timeout of around 120 seconds.",
    "parameters": {"type": "object",
                   "properties": {"source_code": {"type": "string", "description": "Source code to be executed"}},
                   "required": ["source_code"]}}}]

def run_python(code, timeout=60):
    # WARNING: this runs model-written code on your machine. Use a real sandbox in production.
    try:
        r = subprocess.run([sys.executable, "-c", code], capture_output=True, text=True, timeout=timeout)
        return (r.stdout + r.stderr).strip() or "(no output)"
    except subprocess.TimeoutExpired:
        return "Error: execution timed out"

def ask(question, max_turns=6):
    messages = [{"role": "user", "content": question}]
    for _ in range(max_turns):
        reply = generate(messages, tools=TOOLS)
        try:
            call = json.loads(reply)                       # a tool call looks like {"name": ..., "parameters": {...}}
            name = call["name"]
            args = call.get("parameters", call.get("arguments", {}))
            code = args.get("source_code") or next(iter(args.values()), "")
        except Exception:
            return reply                                   # not a tool call, so this is the final answer
        messages.append({"role": "assistant", "content": "",
                         "tool_calls": [{"type": "function", "function": {"name": name, "arguments": args}}]})
        messages.append({"role": "tool", "name": name, "content": run_python(code)})
    return "Stopped: too many tool calls."

print(ask("A reaction has dH = -92.4 kJ/mol and dS = -198.7 J/(mol K). Compute dG at 298 K."))

Tool-call format

The model uses Llama 3.1's native tool format. When it wants to run code, the assistant turn is a single JSON object, {"name": "<tool>", "parameters": {...}}. Your application runs the tool and returns the result as a tool message (rendered as the ipython role). The model then continues, either with another call or with its final answer. It makes one tool call per turn. Pass your tool schema through tools= in apply_chat_template, as in the script above.

Training data

Fine-tuned on a sample of the rqa file of nvidia/Nemotron-SFT-Science-v2 (NVIDIA, CC BY-SA 4.0), a science reasoning dataset with LLM-generated solutions. Per the metadata of the sampled rows, the solutions were generated by DeepSeek-V3.2.

Selection. Rows were drawn uniformly at random from the whole file, keeping only conversations that:

  • contain at least one real tool call, with one call per assistant turn and a result after each call;
  • end with a final assistant answer;
  • fit within 12,000 tokens (longer conversations were excluded, never truncated).

Rows whose prompts began with a developer-role message did not carry a tool schema and were not used.

Source Samples
Chemistry (tool-use) 2,000
Physics (tool-use) 1,821
Biology (tool-use) 322
Identity (short synthetic self-description chats) 72
Total 4,215

The tool names vary across the data (for example evaluate_code, stateful_python_code_exec, sandbox_exec, jupyter_kernel_run, python_interpreter), all for running Python.

Training procedure

Method QLoRA supervised fine-tuning, loss on assistant tokens only (tool calls and answers)
Starting weights Unsloth's 4-bit copy of Llama 3.1 8B Instruct (unsloth/Meta-Llama-3.1-8B-Instruct-bnb-4bit)
LoRA r = 16, alpha = 16, dropout 0, on all attention and MLP projections
Schedule 1 epoch, 264 steps, effective batch size 16
Optimizer 8-bit AdamW, learning rate 2e-4, cosine schedule, 5 warmup steps, weight decay 0.01
Sequence length up to 12,032 tokens, with no truncation
Precision / hardware fp16 on one NVIDIA Tesla T4, about 8 hours
Software Unsloth, Hugging Face Transformers
Final weights LoRA merged into 16-bit

Training loss fell from about 0.70 to about 0.35 over the run.

Evaluation

No formal benchmark has been run yet. Only informal checks were done. The model introduced itself correctly as Llama-Scientific-8B, with and without tools in the prompt. It also produced a well-formed tool call with correct Python for a thermodynamics (ΔG) problem. These checks do not show that it beats the base model on accuracy. Results from a held-out comparison will be added when available.

Limitations

  • Unverified accuracy: the training solutions were written by another LLM and were not manually checked, so errors can carry over. Always verify results.
  • Uneven coverage: Biology is the smallest domain (322 samples), so expect weaker results there than in Chemistry or Physics. Mathematics was not a training domain.
  • Self-description: its description of its own abilities can be inaccurate or over-claim.
  • Tool format: it was trained on single tool calls per turn with Python-execution tools. Other tools, parallel calls and long multi-tool workflows are untested.
  • Tool-call text: in tool-call turns the template keeps only the call JSON, so any text that originally accompanied a call was dropped from training.
  • Code execution: it writes code that you run. Execute it only in a sandbox.
  • Language and length: English only, and long contexts beyond about 12k tokens were not tuned.

License and attribution

Llama 3.1 is licensed under the Llama 3.1 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved. Use of this model must comply with that license and Meta's Acceptable Use Policy. The training data is CC BY-SA 4.0; please check its terms for your use case.

Acknowledgements

Downloads last month
146
Safetensors
Model size
8B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Rumiii/LlamaScientific-8B

Finetuned
(3286)
this model
Quantizations
2 models

Dataset used to train Rumiii/LlamaScientific-8B