Metric guidance#
How to configure metric guidance: the smoke test, metric and output keys, schedules, and building a real objective. See Metric guidance first if you haven’t: it explains what guidance does and why its pieces behave the way they do.
Smoke-test the mechanics#
The repository ships +guidance=contract_ca as a dependency-free mechanics test:
rfd4-generate \
inputs=data/benchmarks/monomer \
out_dir=./runs/metric-guidance-smoke \
num_replicates=1 \
+guidance=contract_ca
For a submitted job:
./scripts/launch_generate.sh --njobs 1 \
inputs=data/benchmarks/monomer \
out_dir=/path/to/runs/metric-guidance-smoke \
num_replicates=1 \
+guidance=contract_ca
contract_ca is not a useful protein-design objective. It minimizes the summed squared
distance of Cα coordinates from the origin, so it contracts and translates a structure toward an
arbitrary coordinate-system origin. Its purpose is to prove that Hydra composition, metric
evaluation, autograd, scheduling, and sampler updates are connected.
Metric and output keys#
metrics names and constructs the metric:
metrics:
contract_ca:
_target_: rfproteina.metrics.contract_ca_metric.ContractCAMetric
terms chooses one scalar output from that metric. The key must have the form
metric_name.output_key; contract_ca.sq_norm matches the metric’s {"sq_norm": scalar} return
value:
terms:
contract_ca.sq_norm:
bb_ca:
_target_: rfproteina.guidance.schedules.window
_partial_: true
w: -0.1
t_start: 0.0
t_end: 0.1
A missing output key fails when that term becomes active. Multiple terms are allowed, and their per-modality gradient contributions are added.
Schedules and signs#
See Schedules and signs for what the sign and window mean and how to choose a starting magnitude. The current schedule helpers are:
Schedule |
Meaning |
|---|---|
|
Return |
|
Return |
Modality weights#
Each term maps modalities to separate schedules:
terms:
objective.score:
bb_ca:
_target_: rfproteina.guidance.schedules.window
_partial_: true
w: 0.02
t_start: 0.5
t_end: 0.9
local_latents:
_target_: rfproteina.guidance.schedules.constant
_partial_: true
w: 0.005
Omitting a modality gives it no direct gradient update. A listed modality also has no effect if the metric output does not depend differentiably on that state leaf.
Build a real objective#
The shipped source currently contains only one metric explicitly marked differentiable=True:
ContractCAMetric. A real objective therefore usually requires a metric class of your own.
Implement a
Metricwhose computation stays in PyTorch and returns a scalar tensor with its gradient intact. Setdifferentiable = True.Map its arguments to differentiable inputs through
kwargs_to_compute_args. Read("state", "bb_ca")or("state", "local_latents")for raw sampler leaves. A metric that needs atom37 coordinates can read the lazily provideddecodednamespace, at extra decoder cost.Copy
configs/guidance/contract_ca.yaml, replace the metric target andmetric_name.output_key, then choose schedules for only the modalities your output actually depends on.Save the config as
configs/guidance/<name>.yamland select it with+guidance=<name>.First run one replicate with a short active window. Compare against the same seed with no guidance, inspect the metric trajectory, and increase magnitude gradually.
Do not convert the objective to Python floats, NumPy arrays, external programs, or detached tensors. Such operations break the gradient path. Ordinary reporting, refolding, and oracle metrics are generally not differentiable guidance objectives.
Troubleshooting#
Symptom |
Check |
|---|---|
Hydra cannot find |
Add a new group with |
|
Set |
|
Match |
No visible change |
Confirm the term’s window is active, its weight is nonzero, and its output depends on the listed modality |
Samples collapse or become non-finite |
Reduce |
Out of memory or severe slowdown |
Shorten the window, reduce |
