Update README.md
Browse files
README.md
CHANGED
@@ -24,21 +24,42 @@ goal-directed molecule generation tasks.
|
|
24 |
## How to load
|
25 |
|
26 |
```python
|
27 |
-
from transformers import AutoTokenizer, AutoModelForCausalLM
|
28 |
-
tokenizer = AutoTokenizer.from_pretrained("chandar-lab/NovoMolGen_32M_SMILES_BPE", trust_remote_code=True)
|
29 |
-
model = AutoModelForCausalLM.from_pretrained("chandar-lab/NovoMolGen_32M_SMILES_BPE", trust_remote_code=True)
|
30 |
```
|
31 |
|
32 |
## Quick-start (FlashAttention + bf16)
|
33 |
|
34 |
```python
|
35 |
-
from accelerate import Accelerator
|
36 |
|
37 |
-
acc = Accelerator(mixed_precision='bf16')
|
38 |
-
model = acc.prepare(model)
|
39 |
|
40 |
-
outputs = model.sample(tokenizer=tokenizer, batch_size=4)
|
41 |
-
print(outputs['SMILES'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
```
|
43 |
|
44 |
## Citation
|
|
|
24 |
## How to load
|
25 |
|
26 |
```python
|
27 |
+
>>> from transformers import AutoTokenizer, AutoModelForCausalLM
|
28 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("chandar-lab/NovoMolGen_32M_SMILES_BPE", trust_remote_code=True)
|
29 |
+
>>> model = AutoModelForCausalLM.from_pretrained("chandar-lab/NovoMolGen_32M_SMILES_BPE", trust_remote_code=True)
|
30 |
```
|
31 |
|
32 |
## Quick-start (FlashAttention + bf16)
|
33 |
|
34 |
```python
|
35 |
+
>>> from accelerate import Accelerator
|
36 |
|
37 |
+
>>> acc = Accelerator(mixed_precision='bf16')
|
38 |
+
>>> model = acc.prepare(model)
|
39 |
|
40 |
+
>>> outputs = model.sample(tokenizer=tokenizer, batch_size=4)
|
41 |
+
>>> print(outputs['SMILES'])
|
42 |
+
```
|
43 |
+
|
44 |
+
## Transformers-native HF checkpoint (`revision="hf-checkpoint"`)
|
45 |
+
|
46 |
+
We also publish a Transformers-native checkpoint on the `hf-checkpoint` revision. This version loads directly with `AutoModelForCausalLM` and works out-of-the-box with `.generate(...)`.
|
47 |
+
|
48 |
+
```python
|
49 |
+
>>> import torch
|
50 |
+
>>> from transformers import AutoTokenizer, AutoModelForCausalLM
|
51 |
+
|
52 |
+
>>> model = AutoModelForCausalLM.from_pretrained("chandar-lab/NovoMolGen_32M_SMILES_BPE", revision='hf-checkpoint', device_map='auto')
|
53 |
+
>>> tokenizer = AutoTokenizer.from_pretrained("chandar-lab/NovoMolGen_32M_SMILES_BPE", revision='hf-checkpoint')
|
54 |
+
|
55 |
+
>>> input_ids = torch.tensor([[tokenizer.bos_token_id]]).expand(4, -1).contiguous().to(model.device)
|
56 |
+
>>> outs = model.generate(input_ids=input_ids, temperature=1.0, max_length=64, do_sample=True, pad_token_id=tokenizer.eos_token_id)
|
57 |
+
|
58 |
+
>>> molecules = [t.replace(" ", "") for t in tokenizer.batch_decode(outs, skip_special_tokens=True)]
|
59 |
+
['CCO[C@H](CNC(=O)N(CC(=O)OC(C)(C)C)c1cccc(Br)n1)C(F)(F)F',
|
60 |
+
'CCn1nnnc1CNc1ncnc(N[C@H]2CCO[C@@H](C)C2)c1C',
|
61 |
+
'CC(C)(O)CNC(=O)CC[C@H]1C[C@@H](NC(=O)COCC(F)F)C1',
|
62 |
+
'Cc1ncc(C(=O)N2C[C@H]3[C@H](CNC(=O)c4cnn[nH]4)CCC[C@H]3C2)n1C']
|
63 |
```
|
64 |
|
65 |
## Citation
|