Large Language Models are In-Context Molecule Learners
Paper • 2403.04197 • Published • 2
How to use phenixace/ICMA-Galactica-125M-M2C with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-generation", model="phenixace/ICMA-Galactica-125M-M2C") # Load model directly
from transformers import AutoTokenizer, AutoModelForMultimodalLM
tokenizer = AutoTokenizer.from_pretrained("phenixace/ICMA-Galactica-125M-M2C")
model = AutoModelForMultimodalLM.from_pretrained("phenixace/ICMA-Galactica-125M-M2C")How to use phenixace/ICMA-Galactica-125M-M2C with vLLM:
# Install vLLM from pip:
pip install vllm
# Start the vLLM server:
vllm serve "phenixace/ICMA-Galactica-125M-M2C"
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:8000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "phenixace/ICMA-Galactica-125M-M2C",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'docker model run hf.co/phenixace/ICMA-Galactica-125M-M2C
How to use phenixace/ICMA-Galactica-125M-M2C with SGLang:
# Install SGLang from pip:
pip install sglang
# Start the SGLang server:
python3 -m sglang.launch_server \
--model-path "phenixace/ICMA-Galactica-125M-M2C" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "phenixace/ICMA-Galactica-125M-M2C",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'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 "phenixace/ICMA-Galactica-125M-M2C" \
--host 0.0.0.0 \
--port 30000
# Call the server using curl (OpenAI-compatible API):
curl -X POST "http://localhost:30000/v1/completions" \
-H "Content-Type: application/json" \
--data '{
"model": "phenixace/ICMA-Galactica-125M-M2C",
"prompt": "Once upon a time,",
"max_tokens": 512,
"temperature": 0.5
}'How to use phenixace/ICMA-Galactica-125M-M2C with Docker Model Runner:
docker model run hf.co/phenixace/ICMA-Galactica-125M-M2C
A simple inference example:
from transformers import AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained("phenixace/ICMA-Galactica-125M-M2C")
from transformers import AutoTokenizer
tk = AutoTokenizer.from_pretrained("phenixace/ICMA-Galactica-125M-M2C")
from transformers import GenerationConfig
text = """Generate a caption for the molecule: C[C@]12CCC(=O)C=C1CC[C@@H]3[C@@H]2C(=O)C[C@]4([C@H]3CCC4=O)C
Caption: The molecule is a 3-oxo Delta(4)-steroid that is androst-4-ene carrying three oxo-substituents at positions 3, 11 and 17. It has a role as an androgen, a human urinary metabolite, a marine metabolite and an EC 1.1.1.146 (11beta-hydroxysteroid dehydrogenase) inhibitor. It is a 3-oxo-Delta(4) steroid, a 17-oxo steroid, an androstanoid and an 11-oxo steroid. It derives from a hydride of an androstane.
Generate a caption for the molecule: C[C@]12CCC(=O)C=C1CC[C@@H]3[C@@H]2C(=O)C[C@]4([C@H]3CC[C@@H]4C(=O)CO)C
Caption: The molecule is an 11-oxo steroid that is corticosterone in which the hydroxy substituent at the 11beta position has been oxidised to give the corresponding ketone. It has a role as a human metabolite and a mouse metabolite. It is a 21-hydroxy steroid, a 3-oxo-Delta(4) steroid, a 20-oxo steroid, an 11-oxo steroid, a corticosteroid and a primary alpha-hydroxy ketone. It derives from a corticosterone.
Based on the above examples, analyse the similarities and differences between the examples and finally generate a caption for the molecule: C[C@]12CCC(=O)C=C1CC[C@@H]3[C@@H]2C(=O)C[C@]\\4([C@H]3CC/C4=C/C(=O)OC)C."""
generation_config = GenerationConfig(
do_sample=True,
temperature=0.7,
top_p=0.85,
top_k=40,
num_beams=1,
repetition_penalty=1.0,
pad_token_id=0,
)
inputs = tk(text, return_tensors="pt", return_token_type_ids=False)
outputs = model.generate(**inputs, return_dict_in_generate=True, output_scores=True, num_return_sequences=1, max_new_tokens=256, generation_config=generation_config)
# decode
decoded = tk.decode(outputs.sequences[0], skip_special_tokens=True)
print(decoded)
Paper Link: https://arxiv.org/abs/2403.04197