nvidia/OpenScienceReasoning-2
Viewer • Updated • 803k • 1.48k • 57
How to use yasserrmd/SciReason-LFM2-2.6B with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="yasserrmd/SciReason-LFM2-2.6B")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("yasserrmd/SciReason-LFM2-2.6B")
model = AutoModelForCausalLM.from_pretrained("yasserrmd/SciReason-LFM2-2.6B")
messages = [
{"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
messages,
add_generation_prompt=True,
tokenize=True,
return_dict=True,
return_tensors="pt",
).to(model.device)
outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))How to use yasserrmd/SciReason-LFM2-2.6B with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "yasserrmd/SciReason-LFM2-2.6B"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "yasserrmd/SciReason-LFM2-2.6B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/yasserrmd/SciReason-LFM2-2.6B
How to use yasserrmd/SciReason-LFM2-2.6B with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "yasserrmd/SciReason-LFM2-2.6B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "yasserrmd/SciReason-LFM2-2.6B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker run --gpus all \
--shm-size 32g \
-p 30000:30000 \
-v ~/.cache/huggingface:/root/.cache/huggingface \
--env "HF_TOKEN=<secret>" \
--ipc=host \
lmsysorg/sglang:latest \
python3 -m sglang.launch_server \
--model-path "yasserrmd/SciReason-LFM2-2.6B" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "yasserrmd/SciReason-LFM2-2.6B",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use yasserrmd/SciReason-LFM2-2.6B with Unsloth Studio:
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for yasserrmd/SciReason-LFM2-2.6B to start chatting
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for yasserrmd/SciReason-LFM2-2.6B to start chatting
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for yasserrmd/SciReason-LFM2-2.6B to start chatting
pip install unsloth
from unsloth import FastModel
model, tokenizer = FastModel.from_pretrained(
model_name="yasserrmd/SciReason-LFM2-2.6B",
max_seq_length=2048,
)How to use yasserrmd/SciReason-LFM2-2.6B with Docker Model Runner:
docker model run hf.co/yasserrmd/SciReason-LFM2-2.6B
SciReason-LFM2-2.6B is a fine-tuned version of LiquidAI/LFM2-2.6B, trained with Unsloth on the OpenScienceReasoning-2 dataset.
The fine-tuning enhances the base model’s ability to handle multi-step scientific reasoning and produce coherent chain-of-thought explanations.
from transformers import AutoModelForCausalLM, AutoTokenizer
# Load model and tokenizer
model_id = "yasserrmd/SciReason-LFM2-2.6B"
model = AutoModelForCausalLM.from_pretrained(
model_id,
device_map="auto",
torch_dtype="bfloat16",
# attn_implementation="flash_attention_2" <- uncomment on compatible GPU
)
tokenizer = AutoTokenizer.from_pretrained(model_id)
# Generate answer
prompt = """
Solve the following problem. Make sure to put the answer (and only answer) inside \boxed{}.
Based on analysis of multinational aeromedical databases (e.g., EASA's EMPR, FAA's CAMI database, and military longitudinal studies), which statement accurately characterizes a fundamental limitation in definitively establishing cause-and-effect relationships for cardiovascular morbidity trends among commercial aircrew?
A: Stratified sampling protocols universally eliminate survivorship bias
B: Retroactive harmonization of biochemical markers across jurisdictions enables precise meta-analysis
C: Inability to fully adjust for dominant confounding variables (e.g., socioeconomic status, undisclosed supplement use)
D: Cohort studies consistently show declining age-adjusted myocardial infarction rates compared to the general population
E: Mandatory polysomnography data provides complete correction for sleep disorder comorbidities
F: Radiation dose metrics exhibit a linear correlation with arrhythmia incidence in jet aircraft pilots
G: Genome-wide association studies have identified fully penetrant monogenic risk variants specific to aviators
H: Continuous blood pressure monitoring during all flight phases yields statistically significant longitudinal datasets
I: Pharmacokinetic interactions between hypoxia and statins are conclusively established in CRF models
J: Regulatory divergence causes morbidity rates to universally decline across all regions after 2018"""
input_ids = tokenizer.apply_chat_template(
[{
"role":"system",
"content":"""
You are a reasoning assistant.
When solving problems:
- Always place your reasoning inside think tags.
- Think in structured steps, but keep it concise (3–4 short steps maximum).
- Avoid repeating yourself or giving unnecessary background.
- Use bullet points or brief numbered steps for clarity inside think tag.
- After think end tag, provide only the final answer clearly and directly.
- Do not include reasoning outside of the think tags.
"""
},
{"role": "user", "content": prompt}],
add_generation_prompt=True,
return_tensors="pt",
tokenize=True,
).to(model.device)
output = model.generate(
input_ids,
do_sample=True,
temperature=0.3,
min_p=0.15,
repetition_penalty=1.05,
max_new_tokens=1024,
)
print(tokenizer.decode(output[0], skip_special_tokens=False))
# <|startoftext|><|im_start|>user
# What is C. elegans?<|im_end|>
# <|im_start|>assistant
# C. elegans, also known as Caenorhabditis elegans, is a small, free-living
# nematode worm (roundworm) that belongs to the phylum Nematoda.
This model is designed for:
⚠️ Disclaimer: Not intended for clinical or legal decision-making.
Apache-2.0 License. See LICENSE.