--- license: apache-2.0 base_model: Qwen/Qwen2.5-7B-Instruct library_name: transformers pipeline_tag: text-generation tags: - chemistry - retrosynthesis - reaction-prediction - qwen2.5 - merged-lora --- # retro-agent-qwen25-7b-merged-fp16 Standalone fp16 retrosynthesis assistant model for serving. The model is based on `Qwen/Qwen2.5-7B-Instruct` with these LoRA adapters merged into the base weights: - retro-reactants-qwen25-7b - retro-conditions-qwen25-7b Because the LoRA weights are merged, deployment does not need PEFT adapter loading. Load and serve this repository as a normal causal language model. ## Intended Use This model is intended for structured retrosynthesis assistance: - predict likely reactants for a target product SMILES - predict plausible reaction conditions - return machine-readable JSON for downstream validation and rendering Use RDKit or another chemistry toolkit to validate generated SMILES before acting on model output. ## Prompt Templates Use explicit task labels and request JSON only. Low temperature is recommended for repeatable API calls. ### Reactant Prediction ```text System: You are a retrosynthesis assistant. Return valid JSON only. User: Task: predict_reactants Product SMILES: CC(=O)Oc1ccccc1C(=O)O Return JSON with keys: reactants_smiles, confidence, rationale. ``` ### Condition Prediction ```text System: You are a reaction condition assistant. Return valid JSON only. User: Task: predict_conditions Product SMILES: CC(=O)Oc1ccccc1C(=O)O Reactants SMILES: CC(=O)O.Oc1ccccc1C(=O)O Return JSON with keys: solvent, reagents, catalyst, temperature_celsius, time, confidence, rationale. ``` ### Combined Planning Prompt ```text System: You are a retrosynthesis assistant. Return valid JSON only. User: Task: retrosynthesis_step Target product SMILES: CC(=O)Oc1ccccc1C(=O)O Return one JSON object with keys: reactants_smiles, conditions, confidence, rationale. ``` ## Python Example ```python import torch from transformers import AutoModelForCausalLM, AutoTokenizer model_id = "/retro-agent-qwen25-7b-merged-fp16" tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained( model_id, torch_dtype=torch.float16, device_map="auto", trust_remote_code=True, ) messages = [ {"role": "system", "content": "You are a retrosynthesis assistant. Return valid JSON only."}, {"role": "user", "content": "Task: retrosynthesis_step\nTarget product SMILES: CC(=O)Oc1ccccc1C(=O)O\nReturn one JSON object with keys: reactants_smiles, conditions, confidence, rationale."}, ] text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True) inputs = tokenizer(text, return_tensors="pt").to(model.device) with torch.no_grad(): output_ids = model.generate( **inputs, max_new_tokens=512, temperature=0.1, do_sample=False, ) new_tokens = output_ids[0][inputs.input_ids.shape[-1]:] print(tokenizer.decode(new_tokens, skip_special_tokens=True)) ``` ## REST API Examples ### Hugging Face Router / OpenAI-compatible Chat Completions This works only if the model is available through Hugging Face Inference Providers. For custom merged models, a dedicated endpoint is often more reliable. ```bash export HF_TOKEN=hf_... curl https://router.huggingface.co/v1/chat/completions \ -H "Authorization: Bearer $HF_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "model": "/retro-agent-qwen25-7b-merged-fp16", "messages": [ {"role": "system", "content": "You are a retrosynthesis assistant. Return valid JSON only."}, {"role": "user", "content": "Task: retrosynthesis_step\nTarget product SMILES: CC(=O)Oc1ccccc1C(=O)O"} ], "temperature": 0.1, "max_tokens": 512, "stream": false }' ``` ### Dedicated Hugging Face Inference Endpoint Create a dedicated endpoint from this model repository, then call the endpoint URL directly. ```bash export HF_TOKEN=hf_... export ENDPOINT_URL=https://...endpoints.huggingface.cloud curl "$ENDPOINT_URL" \ -X POST \ -H "Authorization: Bearer $HF_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "inputs": "Task: retrosynthesis_step\nTarget product SMILES: CC(=O)Oc1ccccc1C(=O)O\nReturn one JSON object with keys: reactants_smiles, conditions, confidence, rationale.", "parameters": { "max_new_tokens": 512, "temperature": 0.1, "return_full_text": false } }' ``` ## Notes This model merges adapters trained for related but distinct tasks. Evaluate both reactant prediction and condition prediction after merge, because independently trained LoRA adapters can interfere with each other.