language-plus-molecules/mCLM_Pretrain_1k
Viewer • Updated • 1.66M • 144 • 1
How to use language-plus-molecules/mCLM_1k-3b with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="language-plus-molecules/mCLM_1k-3b")
messages = [
{"role": "user", "content": "Who are you?"},
]
pipe(messages) # Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("language-plus-molecules/mCLM_1k-3b")
model = AutoModelForCausalLM.from_pretrained("language-plus-molecules/mCLM_1k-3b")
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 language-plus-molecules/mCLM_1k-3b with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "language-plus-molecules/mCLM_1k-3b"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/chat/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "language-plus-molecules/mCLM_1k-3b",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'docker model run hf.co/language-plus-molecules/mCLM_1k-3b
How to use language-plus-molecules/mCLM_1k-3b with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "language-plus-molecules/mCLM_1k-3b" \
--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": "language-plus-molecules/mCLM_1k-3b",
"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 "language-plus-molecules/mCLM_1k-3b" \
--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": "language-plus-molecules/mCLM_1k-3b",
"messages": [
{
"role": "user",
"content": "What is the capital of France?"
}
]
}'How to use language-plus-molecules/mCLM_1k-3b with Docker Model Runner:
docker model run hf.co/language-plus-molecules/mCLM_1k-3b
mCLM: A Modular Chemical Language Model that Generates Functional and Makeable Molecules
:globe_with_meridians: Website | :octocat: Code | :hugs: Data and Model | :desktop_computer: Demo | :page_with_curl: Paper
Please follow installation instructions from the Github .
from mCLM.model.models import mCLM
from mCLM.tokenizer.utils import convert_instruction_to_input, message_ids_to_string, get_processor
import torch
# ===========================
# Settings
# ===========================
DTYPE = torch.bfloat16
DEVICE = torch.device("cpu")
if __name__ == "__main__":
model = mCLM.from_pretrained("language-plus-molecules/mCLM_1k-3b")
tokenizer = model.tokenizer
molecule_tokenizer = model.molecule_tokenizer
bad_words_ids = None
model.to(DEVICE).to(DTYPE) #This is important for the HF model
while True:
user_input = input("Enter an instruction (type 'quit' to exit): ")
if user_input == 'quit': break
user_input = user_input.strip()
message_tokens = convert_instruction_to_input(user_input, model, molecule_tokenizer, tokenizer)
################## Generate results ###################################
beam_size = 5
input_ids = message_tokens.to(DEVICE)
processor = get_processor(molecule_tokenizer, tokenizer) #we do this every time in case vocab was expanded
generated = model.generate(
input_ids=input_ids,
attention_mask=torch.ones_like(input_ids), #This is to turn off the attention mask warning
pad_token_id=tokenizer.eos_token_id, #This is to turn off the pad token warning
max_new_tokens=32,
num_beams=beam_size,
num_return_sequences=beam_size,
logits_processor=processor,
do_sample=False,
bad_words_ids=bad_words_ids,
diversity_penalty=1.0,
num_beam_groups=beam_size,
)
for i in [0]: #range(beam_size):
message_ids = generated[i, message_tokens.shape[1]:]
mol_msg, smiles_msg, mol_list, smiles_list = message_ids_to_string(message_ids, molecule_tokenizer, tokenizer)
if smiles_msg != None:
print(mol_msg)
if len(smiles_list) > 0:
print("SMILES list:", smiles_list)
else:
print(mol_msg)
print()
The model was trained on:
If you use this model, please cite:
@misc{edwards2025mclmmodularchemicallanguage,
title={mCLM: A Modular Chemical Language Model that Generates Functional and Makeable Molecules},
author={Carl Edwards and Chi Han and Gawon Lee and Thao Nguyen and Sara Szymkuć and Chetan Kumar Prasad and Bowen Jin and Jiawei Han and Ying Diao and Ge Liu and Hao Peng and Bartosz A. Grzybowski and Martin D. Burke and Heng Ji},
year={2025},
eprint={2505.12565},
archivePrefix={arXiv},
primaryClass={cs.AI},
url={https://arxiv.org/abs/2505.12565},
}
For questions or issues, please open an issue in the repository.
Base model
Qwen/Qwen2.5-3B