代理式 AI 正在重塑科学研究和创新。研究人员使用自然语言传达复杂的科学假设,让自主智能体能够独立规划任务、执行模拟、评估结果,并在多个迭代中进行自我修正。科学智能体的工作流程越来越耗时、复杂且可视化程度越来越高。
准确性和推理效率在每一步都至关重要。如果不进行验证,整个工作流程中的错误会更加复杂,而延迟和计算成本会随着持续运行而成倍增加。
NVIDIA Nemotron for Science 是用于加速代理式科学工作负载的模型、数据集、工具和方法的集合,可解决这些障碍。它包括 Nemotron 3.5 Super VL (适用于这些专业工作流程的开放、可定制的多模态模型) 和 NVIDIA Nemotron Litmus-Bench V2.0 (开源化学推理数据集和基准测试,旨在训练和评估 LLM 和代理式 AI 模型的分子特性) 。Nemotron 开箱即用,可为科学基准测试提供前沿级别的准确性 (见下图 1) ,并可更快地提供科学编码解决方案。

Nemotron 模型的一个重要优势是 NVIDIA 后训练支持。您可以为自己的特定研究领域定制模型,以提高准确性。
本博客提供了针对科学用例对 Nemotron 3.5 Super VL 进行后训练的实用方法。从原始实验数据集开始,您将介绍如何使用 NVIDIA NeMo Gym 构建自定义强化学习 (RL) 环境,应用 RL,并使用分子相似性评分来衡量改进情况。NeMo Gym 提供环境基础架构,NVIDIA NeMo RL 提供后训练框架。
本指南以药物代谢预测为实际示例。给定一种母化合物、起始分子及其转化酶,该模型会预测生成的代谢产物。以下示例使用 MetxBioDB 的记录,后者是经实验证实的生物转化反应的综合数据库。
博客首先介绍了直接学习,然后介绍了一个可选的蒸馏步骤,当教师模型提供有用的示例时,可以在学习之前使用该步骤。
根据实验数据构建强化学习环境
起点是现有实验记录的 CSV 文件,例如序列、简化分子输入行输入系统 (SMILES) 字符串、反应条件以及与测量属性或结果配对的任何其他元数据。在本示例中,分子结构以 SMILES 字符串表示,SMILES 字符串是描述分子原子和键的文本符号。
这些输入 – 输出对被重新格式化为问答或用户/ 助手提示词对,并以实验性真值作为验证器,对模型的回答进行评分。此设置构成了具有可验证奖励 (RLVR) 环境的基本强化学习,无需人类偏好标记:奖励信号直接来自数据。
奖励信号的保真度可以根据任务进行调整。简单的序列相似性函数可用作轻量级验证器,而化学信息学库、分子模拟器甚至实时自主实验室等更复杂的工具都可以作为工具调用,并且都可以连接作为环境的评分层。工具越丰富,模型就越准确地转向具有化学或生物学意义的输出。
在代谢示例中,模型接收母分子和酶,然后提交预测的代谢产物。该验证器使用 Tanimoto 相似性比较预测和参考分子指纹 (结构特征的数值表示) 。Tanimoto 相似性是一种用于测量两个集合或二进制向量之间重叠的指标,通过将它们的交集大小除以它们的并集大小来计算。对于此处使用的位指纹,分数介于 0 到 1 之间;分数越高表示类似指纹越多。

在自定义环境中直接进行 RL 后训练
环境就位后,使用低秩适配器 (LoRA) 的组相对策略优化 (GRPO) 对模型进行微调。环境会向模型展示实验性输入,并要求其在通过工具调用提交预测答案之前,按部就班地对问题进行推理。验证者会自动为每个提交的作品打分,从而给出密集的奖励信号,而无需进一步标注。训练循环、奖励服务器、线束和部署工作流是完全独立的,因此同一工作流可泛化到可以返回标量奖励的任何域。
在药物代谢 RLVR 环境的输出预算 (以 16384 Token 计) 下,监督式微调 (SFT) 将 Nemotron for Science 的准确率提高了 12%,而 RL 经过后训练后又将准确率提高了 17%。它表明,在针对特定领域的任务提供有针对性的 RL 反馈时,即使是功能高度强大的指令调整模型也能继续获得有意义的改进。

来自更强大模型的蒸馏将成为 RL 的“热启动”
如果基础模型需要在 RL 训练前提升能力,或者 RL 收速度较慢,蒸馏步骤可以显著提升能力。更强的教师模型 (例如。在相同的环境中运行,以生成高质量的推理痕迹。如果教师模型用于识别酶、预测反应位点和推导代谢物结构的分步逻辑导致与真值代谢物相匹配的 SMILES,则推理痕迹是高质量的。即使推理看起来流畅且合理,但存在一些导致错误预测的逻辑缺陷,它也是低质量的推理痕迹。
高质量的推理痕迹用于通过 SFT 或 Direct on-policy 蒸馏对学生模型进行微调,从而在 RL 循环开始之前为其提供更好的起点。这被称为“热启动”,通常会加速收并提高性能下限,从而提高后续 RL 训练的效率,更有可能找到强大的策略。
适用于 SFT 的 Data 蒸馏
蒸馏工作流在整个训练集上运行 Anthropic 的 Claude Sonnet 5.5,根据 Tanimoto 相似度 (工具调用) 对每一次推出的真值代谢物进行评分,并仅保留模型正确的 (问题、推理追踪) 对。这些会成为较小模型的 SFT 语料库。
在此环境中,在 Tanimoto 值 = 0.7 时,从 1934 年的训练提示词中过滤了 1123 个高质量推理痕迹。这是 Claude Sonnet 5.5 问答对的蒸推理轨迹。请注意,每个请求都包含一个固定的系统提示,该提示可能会因环境而异。LLM 请求的格式为聊天消息,其中包含问题和系统提示。
MetxBioDB 环境 ( CYP1A2 N – 脱甲基)
问题:
Parent compound SMILES: Cc1nn(C)c(Cl)c1C(O)=Nc1cccc2c1C(C)OC2(C)C Metabolising enzyme: CYP1A2 Reason through this biotransformation step by step, then call submit_metabolite with the predicted SMILES of the primary metabolite.
真值:
Cc1[nH]nc(Cl)c1C(O)=Nc1cccc2c1C(C)OC2(C)C — Tanimoto similarity = 1.0 (exact match)
系统提示:
You are an expert computational chemist specializing in drug metabolism. Your task is to predict the SMILES string of the metabolite produced when a given parent compound is biotransformed by a specified enzyme or enzyme family. Response format: 1. Provide step-by-step scientific reasoning: a. Identify the functional groups in the parent compound relevant to the enzyme. b. Describe the enzyme's known reaction mechanism and regioselectivity. c. Identify the specific site of biotransformation and explain why. d. Describe the chemical transformation applied (e.g. hydroxylation, glucuronidation). e. State the resulting structural change to the parent SMILES. 2. Finish by calling the submit_metabolite tool with your predicted metabolite SMILES. Rules: - The SMILES passed to submit_metabolite must be valid, canonical, and represent the chemically correct metabolic product — no extra text in the argument. - Apply knowledge of the named enzyme's typical reaction mechanism (e.g. CYP450 hydroxylation/oxidation, UGT glucuronidation, SULT sulfation, MAO deamination, NAT acetylation, etc.). - If multiple enzymes are listed (semicolon-separated), use their combined or most likely reaction on the substrate.
推理追踪 (Claude Sonnet 5.5) :
a. Functional groups relevant to CYP1A2: The parent contains an N-methyl pyrazole (N–CH3 on the ring nitrogen). CYP1A2 is well known for N-demethylation of aromatic amines and N-alkyl heterocycles via alpha-carbon hydroxylation followed by hemi-aminal collapse. b. Enzyme mechanism: CYP1A2 abstracts a hydrogen from the N-methyl carbon (N–CH3 → N–CH2•), then oxygen rebound gives N–CH2OH; the hemi-aminal spontaneously collapses to the free N–H and formaldehyde. c. Site of biotransformation: The 1-methyl (N1-CH3) on the pyrazole is the primary target. The C3-methyl is on a carbon, not nitrogen, and is far less reactive. d. Chemical transformation: N-Demethylation: –N(CH3)– → –NH–, loss of CH2O. e. Structural change to SMILES: Original N-methyl: Cc1nn(C)c(Cl)c1… ← the nn(C) nitrogen loses its CH3 Product: Cc1[nH]nc(Cl)c1… ← becomes [nH]
工具调用:
submit_metabolite({"smiles": "Cc1[nH]nc(Cl)c1C(O)=Nc1cccc2c1C(C)OC2(C)C"})
代码入门
以下方法取自 nemo-rl 和 nemo-gym 训练模块。每个代码段都是独立的,可以通过替换相应的配置来适应新的领域。
NemoGym 环境注册
以下代码段注册了来自实验性 CSV 的 NemoGym RLVR 环境。注册环境需要完成四个部分。
1. CSV 到 Gym JSONL
每个 CSV 行变成一行 JSONL 行。这些额外的密钥 (此处为 ground_truth_smiles ) 将传递给服务器的 seed_session 并进行验证。
import csv
import json
SYSTEM = open("system_prompt.txt").read()
TOOLS = [{
"type": "function",
"name": "submit_metabolite",
"strict": True,
"description": (
"Submit your predicted metabolite SMILES. Returns validity and Tanimoto"
" similarity (0-1)."
),
"parameters": {
"type": "object",
"additionalProperties": False,
"required": ["smiles"],
"properties": {
"smiles": {
"type": "string",
"description": "Predicted metabolite SMILES (no extra text).",
}
},
},
}]
with open("train.jsonl", "w") as f:
for r in csv.DictReader(
open("metxbiodb.csv")
): # columns: parent_smiles, enzyme, reaction_type, metabolite_smiles
user = (
f"Parent compound SMILES: {r['parent_smiles']}\nMetabolising"
f" enzyme: {r['enzyme']}\n\nReason through this biotransformation"
" step by step, then call submit_metabolite with the predicted"
" SMILES of the primary metabolite."
)
f.write(
json.dumps({
"responses_create_params": {
"input": [
{"role": "system", "content": SYSTEM},
{"role": "user", "content": user},
],
"tools": TOOLS,
},
"agent_ref": {"name": "metxbiodb_simple_agent"},
"parent_smiles": r["parent_smiles"],
"enzyme": r["enzyme"],
"reaction_type": r["reaction_type"],
"ground_truth_smiles": r["metabolite_smiles"],
})
+ "\n"
)
2. 资源服务器:resources_servers/metxbiodb/app.py
这是唯一一个特定于域的代码,包含三个部分:
Seed_session存储每个会话的真值。submit_metabolite工具端点使用 Morgan-fingerprint Tanimoto (半径 2,2048 位) 对首次提交的内容进行评分。Verify会返回该分数作为奖励。
它还需要带有 rdkit 的 pyproject.toml 。要使其适应新域,请替换 tanimoto_similarity 和工具模式。
3。注册 yaml
metxbiodb:
resources_servers:
metxbiodb:
entrypoint: app.py
domain: knowledge
metxbiodb_simple_agent:
responses_api_agents:
simple_agent:
entrypoint: app.py
max_steps: 2 # submit, then one closing turn; only the first submission is scored
resources_server: {type: resources_servers, name: metxbiodb}
model_server: {type: responses_api_models, name: policy_model}
datasets:
- {name: train, type: example, jsonl_fpath: data/train.jsonl}
- {name: validation, type: example, jsonl_fpath: data/validation.jsonl}
代理名称必须等于 JSONL 行中的 agent_ref.name。
4. 训练器配置中的布线
data:
train: {dataset_name: NemoGymDataset, data_path: data/train.jsonl}
validation: {data_path: data/validation.jsonl}
default: {dataset_name: NemoGymDataset, env_name: nemo_gym, processor: nemo_gym_data_processor,
prompt_file: null, system_prompt_file: null}
nemo_gym:
metxbiodb_simple_agent:
datasets:
train: {jsonl_fpath: data/train.jsonl}
validation: {jsonl_fpath: data/validation.jsonl}
env:
should_use_nemo_gym: true
nemo_gym:
config_paths:
- responses_api_models/vllm_model/configs/vllm_model_for_training.yaml
- resources_servers/metxbiodb/configs/metxbiodb.yaml
启动 GRPO 训练
使用以下命令启动 GRPO 训练:
# Multi-node GRPO run (16 GPUs)
python examples/nemo_gym/run_grpo_nemo_gym.py \
--config configs/grpo_metxbiodb_super_vl.yaml \
cluster.num_nodes=4 cluster.gpus_per_node=4 \
grpo.max_num_steps=100
注意: grpo_metxbiodb_super_vl.yaml 是本博客中环境的完整 GRPO 训练器配置。
GRPO 策略配置
以下显示了 GRPO 训练器配置的策略部分。完整配置包括发布、奖励服务器和日志记录设置。
policy:
model_name: nvidia/NVIDIA-Nemotron-3.5-Super-VL-120B-A128-BF16
tokenizer:
- name: $(policy.model_name)
chat_template_kwargs: null
hf_config_overrides:
num_next_predict_layers: 0
train_micro_batch_size: 1
logprob_batch_size: 1
logprob_chunk_size: 2048
max_total_sequence_length: 5120
make_sequence_length_divisible_by: 256
precision: bfloat16
offload_optimizer_for_logprob: true
optimizer:
- name: transformer_engine.pytorch.optimizers.fused_adam.FusedAdam
kwargs:
lr: 1.0e-06
weight_decay: 0.1
betas: [0.9, 0.999]
eps: 1.0e-08
master_weights: true
store_param_remainders: true
exp_avg_dtype: torch.bfloat16
exp_avg_sq_dtype: torch.bfloat16
scheduler:
- name: torch.optim.lr_scheduler.ConstantLR
kwargs:
factor: 1.0
total_iters: 1000000000
- milestones: []
automodel_cfg:
enabled: true
tensor_parallel_size: 1
context_parallel_size: 1
expert_parallel_size: 4
sequence_parallel: false
activation_checkpointing: true
cpu_offload: false
moe_parallelizer:
ignore_router_for_ac: true
reshard_after_forward: true
automodel_kwargs:
backend:
_target_: nemo_automodel.components.models.common.utils.BackendConfig
attn: te
linear: te
rms_norm: torch_fp32
experts: gmm
dispatcher: hybridep
fake_balanced_gate: false
rope_fusion: false
enable_hf_state_dict_adapter: true
注意:设置 loss_fn.use_importance_sampling_correction=True 以减少 vLLM 推出引擎和 Megatron 训练引擎之间的方差。这对于混合专家 (MoE) 模型尤为重要。
蒸馏工作流
以下片段根据 Tanimoto 相似度对教师进行评分,并根据用户设置的分数值为 SFT 语料库过滤痕迹。
生成脚本和启动命令如下所示:
export POLICY_API_KEY=<your-inference-api-key>
# Step 1: Generate rollouts from Claude Sonnet 5.5
python3 tools/generate_sft.py \
--model anthropic/claude-sonnet-5-5 \
--split train \
--num-repeats 8 \
--min-reward 0.7 \
--out-dir runs/metxbiodb_sft_distilled
# Step 2: Build OpenAI-format SFT dataset
python3 tools/build_metxbiodb_sft_messages.py \
--in-file runs/metxbiodb_sft_distilled/generated.jsonl \
--out-dir metxbiodb/distilled_datasets \
--val-frac 0.05 \
--seed 42
其中 generate_sft.py 为:
async def generate(row, semaphore):
async with semaphore:
resp = await client.responses.create(
model=model,
instructions=SYSTEM_PROMPT,
input=[{"role": "user", "content": row["prompt"]}],
tools=TOOLS,
temperature=1.0,
)
predicted_smiles = None
response_text = getattr(resp, "output_text", "") or ""
for item in getattr(resp, "output", []):
if (
getattr(item, "type", None) == "function_call"
and getattr(item, "name", None) == "submit_metabolite"
):
predicted_smiles = (
json.loads(item.arguments).get("smiles", "").strip()
)
break
valid, reward = (
tanimoto(predicted_smiles, ground_truth)
if predicted_smiles
else (False, 0.0)
)
return {
"id": row["id"],
"prompt": row["prompt"],
"response": response_text,
"predicted_smiles": predicted_smiles,
"reward": reward,
}
注意:在 score == 1.0 (精确的 Tanimoto 匹配) 处进行过滤,仅保留教师推理符合化学逻辑的痕迹,并生成确切的增长真值作为最终答案。为了让更柔和的真值引入一些变体,请改为设置值 (例如,分数 > = 0.7) 。
SFT 训练器发布
使用以下命令启动 SFT 训练:
# Multi-node SFT run (16 GPUs)
python examples/run_sft.py \
--config configs/sft_metxbiodb_super_vl_lora.yaml \
cluster.num_nodes=4 cluster.gpus_per_node=4 \
sft.max_num_steps=55
注意: sft_metxbiodb_super_vl_lora.yaml 是本博客中环境的完整 SFT 训练器配置。
SFT 训练器配置
在 RL 循环开始之前,以下 SFT 训练器配置可在蒸痕迹上热启动学生模型:
policy:
optimizer:
kwargs:
lr: 1.0e-5
weight_decay: 0.0
automodel_cfg:
model_save_format: safetensors
checkpoint:
save_consolidated: final
consolidation_timeout_minutes: 120
lora_cfg:
enabled: false
后训练为研究团队提供了一种方法,使 Nemotron 模型适应您所在领域中重要的任务和实验证据。此方法可将实验记录转化为提示和参考答案,将模型提交内容连接到自动验证器,并使用强化学习根据该反馈进行训练。
设计的核心选择是奖励:它应该衡量你想要的科学成果。教师模型蒸馏提供了一个可选的起点,而暂停评估有助于确定这两种训练路径是否会提高初始模型以外的性能。
特定领域的数据、适合任务的验证和可复制的评估共同为开发专业的科学智能体奠定了实际基础。从狭义定义的任务开始,验证评分方法,并仅在证据支持的情况下扩展工作流程。