Run this model with HF Jobs

Run gmxn/C3LM on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/gmxn/C3LM. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/gmxn/C3LM on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/gmxn/C3LM. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.

Quantize for lower memory use

Use HF Jobs to create a 4-bit version of https://huggingface.co/gmxn/C3LM. Push it to a new model repo, then reload it from there and report its memory footprint. Run `hf jobs --help` first to learn the CLI.
File size: 3,728 Bytes
2496b19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
---
library_name: transformers
license: other
license_name: lfm1.0
base_model: LiquidAI/LFM2-2.6B
base_model_relation: finetune
pipeline_tag: text-generation
language:
- en
tags:
- chemistry
- retrosynthesis
- chemical-synthesis
- single-step-retrosynthesis
- synthetic-dataset
- virtual-synthesis
---
<div align="center">

# C3LM

**Chemistry Constraint–Consistent Language Model**

[![Paper](https://img.shields.io/badge/Paper-arXiv%3A2602.03554-B31B1B?style=flat-square&logo=arxiv&logoColor=white)](https://arxiv.org/abs/2602.03554)
[![ChemCensor](https://img.shields.io/badge/github-ChemCensor-blue?logo=github)](https://github.com/insilicomedicine/ChemCensor)

<br/>

<img src="CREED_overview.png" alt="CREED overview" width="80%" />

</div>

---
## Overview

C3LM is a chemistry-focused language model for Single-Step Retrosynthesis task. This checkpoint was initialized from **LFM2-2.6B** and trained with **supervised fine-tuning (SFT)** on a combined **CREED + USPTO-full** dataset.

---

## Load model

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load model and tokenizer
model_id = "insilicomedicine/C3LM"
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)
```

---

## Usage example

```python
import re

ATOM_TOKENS = ["Ag","Al","As","Au","Bi","Br","Ca","Cl","Cr","Cu","Fe","Ga","Gd","Ge","Hg","Li","Mg","Mo","Na","Pt","Ru","Sb","Se","Si","Sn","Sc","B","C","F","H","I","K","M","N","O","P","S","V","W","Z","c","e","n","o","p","s"]

SMI_REGEX_PATTERN = (
    r"(\[|\]|\(|\)|\.|=|#|-|\+|\\|\/|:|~|@|\?|>>?|\*|\$|\%[0-9]{2}|[0-9]|"
    + "|".join(ATOM_TOKENS)
    + ")"
)
smi_regex = re.compile(SMI_REGEX_PATTERN)

def isolate_sequence(s):
    return "".join(["<sm_" + tok + ">" for tok in smi_regex.findall(s)])

def deisolate_sequence(s):
    s = re.sub("[<\s]?sm_[^>]+>", lambda matchobj: matchobj.group(0)[4:-1], s).strip()
    return s

# Prepare prompts
product_smiles = "N1C(=O)Cc2ccc(Nc3ccc(N[C@@H]4CN(C(c5cc(NCCO)ccc5)=O)C[C@@H]4c4scnc4)cc3)cc21"
prompt = f"What are the possible reactants that could have formed the following product <smiles>{isolate_sequence(product_smiles)}</smiles>? Wrap an answer in <smiles> tags/think"

input_ids = tokenizer.apply_chat_template(
    [
        {"role": "system", "content": "You are a helpful assistant in chemistry and biology."},
        {"role": "user", "content": prompt}
    ],
    add_generation_prompt=True,
    return_tensors="pt",
    tokenize=True,
)['input_ids'].to(model.device)

# Generate answer
output = model.generate(
    input_ids,
    do_sample=True,
    temperature=0.3,
    min_p=0.15,
    repetition_penalty=1.05,
    max_new_tokens=512,
)

for out in output:
    out = tokenizer.decode(out, skip_special_tokens=False)
    answer_part = out.split('</think>')[1].split('<smiles>')[1].split('</smiles>')[0]
    answer_part = deisolate_sequence(answer_part)
    print('Reactants: ', answer_part)
```


---

## Citation

```
@misc{zagribelnyy2026singleanswerenoughrethinking,
      title={When Single Answer Is Not Enough: Rethinking Single-Step Retrosynthesis Benchmarks for LLMs}, 
      author={Bogdan Zagribelnyy and Ivan Ilin and Maksim Kuznetsov and Nikita Bondarev and Roman Schutski
                and Thomas MacDougall and Rim Shayakhmetov and Zulfat Miftakhutdinov
                and Mikolaj Mizera and Vladimir Aladinskiy and Alex Aliper and Alex Zhavoronkov},
      year={2026},
      eprint={2602.03554},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2602.03554}, 
}
```