lamm-mit/Bioinspired-SmolLM-1.7B-Instruct
This model was constructed from the SmolLM-1.7B base model using a combination of Continued Pre-training (CPT), Supervised fine-tuning (SFT), and DPO.
The model was trained on a mix of publically available datasets and a corpus of around 5,000 scientific papers in the bio-inspired materials field. During the CPT phase, the raw text of all papers is used. During SFT and ORPO, the model is shown a high-quality mix of question-answer pairs and question-answer-rejected triples, respectively, along with other datasets to train the model for instructions and chat interactions.

Inference
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
def generate_response(model, tokenizer, text_input="Biology offers amazing materials. Tell me more!", system_prompt='You are a materials scientist.',
num_return_sequences=1, temperature=0.3, max_new_tokens=256, do_sample=True,
num_beams=1, eos_token_id=[2],
device='cuda', top_k=50, top_p=0.9, repetition_penalty=1.1, messages=None, ):
if messages is None:
if system_prompt:
messages = [{"role": "user", "content": system_prompt + text_input}]
else:
messages = [{"role": "user", "content": text_input}]
else:
messages.append({"role": "user", "content": text_input})
text_input = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
inputs = tokenizer([text_input], add_special_tokens=False, return_tensors='pt').to(device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_new_tokens=max_new_tokens,
temperature=temperature,
num_beams=num_beams,
top_k=top_k,
do_sample=do_sample,
top_p=top_p,
eos_token_id=eos_token_id,
num_return_sequences=num_return_sequences,
repetition_penalty=repetition_penalty,
)
outputs = outputs[:, inputs["input_ids"].shape[1]:]
return tokenizer.batch_decode(outputs.detach().cpu().numpy(), skip_special_tokens=True), messages
def load_model(model_name, chat_template=None, compile_mode=None,
attn_implementation="flash_attention_2", quant=False):
if quant:
bnb_config4bit = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_compute_dtype=torch.bfloat16,
bnb_4bit_use_double_quant=True,
)
model = AutoModelForCausalLM.from_pretrained(
model_name,
trust_remote_code=True,
use_cache=False,
quantization_config=bnb_config4bit,
device_map="auto",
torch_dtype=torch.bfloat16,
attn_implementation=attn_implementation,
)
else:
model = AutoModelForCausalLM.from_pretrained(
model_name,
trust_remote_code=True,
use_cache=False,
device_map="auto",
torch_dtype=torch.bfloat16,
attn_implementation=attn_implementation,
)
if compile_mode:
model.generation_config.cache_implementation = "static"
model.forward = torch.compile(model.forward, mode=compile_mode, fullgraph=True)
tokenizer = AutoTokenizer.from_pretrained(
model_name,
trust_remote_code=True,
add_bos_token=False
)
if chat_template:
tokenizer.chat_template = chat_template
return model, tokenizer
Chat template
The model uses the ChatML template, as so (with <|im_end|> as end token):
messages = [
{"role": "system", "content": "You are a biomaterials scientist."},
{"role": "user", "content": "What is the role of collagen in bone?"},
{"role": "assistant", "content": "Collagen is a key structural protein."},
]
prompt = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
print (prompt)
The output:
<|begin_of_text|><|im_start|>system
You are a biomaterials scientist.<|im_end|>
<|im_start|>user
What is the role of collagen in bone?<|im_end|>
<|im_start|>assistant
Collagen is a key structural protein.<|im_end|>
<|im_start|>assistant
Example use case
Load the model:
model, tokenizer,=load_model (model_name='lamm-mit/Bioinspired-SmolLM-1.7B-Instruct')
Collagen and the Glass Bead Game
messages=[]
result,messages=generate_response (model, tokenizer, text_input="Collagen and the Glass Bead Game, discuss their relationship.",
num_return_sequences=1, temperature=0.3,max_new_tokens=1024 , messages=[]
system_prompt="You are materials scientist. ",)
for res in result:
print(res, "\n")
messages.append ( {"role": "assistant", "content":result[0]})
You can ask a follow-up question like so:
result,messages=generate_response (model, tokenizer, text_input="Summarize the key points in JSON format.",num_return_sequences=1,
temperature=0.3,max_new_tokens=1024 , messages=messages)
for res in result:
print(res, "\n")
messages.append ( {"role": "assistant", "content":result[0]})
<pre style="white-space: pre-wrap;">
Here's a summary of collagen and the Glass Bead Game in JSON format:
```json
{
"collagen": {
"structure": "proteinous fibrous network",
"composition": "glycoprotein",
"properties": "high tensile strength, low stiffness",
"functions": "structural support, cell signaling, wound healing",
"types": ["alpha", "beta", "gamma", "delta"]
},
"glass bead game": {
"rules": "a strategy game where players collect and trade glass beads, simulating the process of collagen synthesis and mineralization",
"components": ["glass beads", "mineral deposits", "cell signaling molecules", "growth factors"],
"goal": "collect and trade the most beads to achieve mineralization and growth",
"rules of play": "players must collect beads, deposit them in cells, and stimulate mineralization through signaling molecules and growth factors",
"game mechanics": "players earn points for successful mineralization, trade beads for resources, and manage their cells' mineralization and growth rates"
},
}
In this JSON representation, collagen is a proteinous fibrous network with a high tensile strength and low stiffness, while the Glass Bead Game is a strategy game where players collect and trade glass beads to simulate the process of collagen synthesis and mineralization. The Glass Bead Game components include glass beads, mineral deposits, cell signaling molecules, and growth factors, with the goal of collecting and trading the most beads to achieve mineralization and growth. The rules of play involve collecting beads, depositing them in cells, and stimulating mineralization through signaling molecules and growth factors.
Benchmark
Performance on the bioinspired benchmark (testing with domain questions to assess performance relative to the training corpus around biological materials and spider silk):

Citation
Please cite as:
@article{LuLuuBuehler2024,
title={Fine-tuning large language models for domain adaptation: Exploration of training strategies, scaling, model merging and synergistic capabilities},
author={Wei Lu and Rachel K. Luu and Markus J. Buehler},
journal={arXiv: https://arxiv.org/abs/2409.03444},
year={2024},
}
@article{LuuBuehler2023bioinspiredLLM,
title={BioinspiredLLM: Conversational Large Language Model for the Mechanics of Biological and Bio-Inspired Materials},
author={Rachel K. Luu and Markus J. Buehler},
year={2023},
journal={Advanced Science},
doi={10.1002/advs.202306724},
eprint={2309.08788},
archivePrefix={arXiv},
primaryClass={cs.LG},
url={https://arxiv.org/abs/2309.08788}
}
@article{Buehler2024XLoRA,
title={X-LoRA: Mixture of low-rank adapter experts, a flexible framework for large language models with applications in protein mechanics and molecular design},
author={Eric L. Buehler and Markus J. Buehler},
year={2024},
journal={APL Machine Learning},
volume={2},
number={2},
pages={026119},
doi={10.1063/5.0203126},
note={\url{https://doi.org/10.1063/5.0203126}}
}