Beam search optimizer that generates a single segment with beam search at each boundary
This optimizer is open source. Any third-party models, product names, or trademarks referenced are the property of their respective owners, and Proto is not affiliated with them.
View sourceBeam search optimizer for sequence generation.This optimizer implements beam search for sequence optimization where a single target
segment is generated with beam search. The optimizer maintains K beams (running sequences)
and generates K x N total proposals at each step by producing N variations per beam.
After constraint evaluation on the FULL accumulated sequence, only the top K sequences by
energy are retained for the next step.The segment is split into ceil(sequence_length / beam_length) steps. Each step asks the single
autoregressive generator for beam_length new tokens per proposal (the last step is truncated to
the remaining tokens), scores each proposal on its full accumulated sequence, and resamples any
beam left with fewer than proposals_per_result valid proposals (up to max_resample_attempts,
raising RuntimeError if a beam still falls short) before ranking. Within a beam, proposals are
kept by their most recent step energy; across beams, the top num_results survivors are ranked by
score_by (“mean” averages a beam’s per-step energies, “last” uses only the most recent), become
the next step’s parent beams, and seed the final result_sequences. prepend_prompt controls whether
the prompt is included in the output, and use_kv_caching reuses generator cache state across steps
(requires a KV-cache-capable generator). Use it for long autoregressive design under sequence-level
constraints; it targets a single segment and requires a protein/DNA language-model generator
(Evo1/Evo2/ProGen2), not a CPU generator.
Beam search extends a single segment step by step, pruning weak beams as it grows.Beam search grows one segment left to right. The segment is split into num_beams = ⌈ L / beam_length ⌉ steps; at each step every one of the K = num_results beams is extended by beam_length tokens in proposals_per_result variations, each candidate is scored on its full accumulated sequence, and only the top K beams survive:
num_beams = ⌈ L / beam_length ⌉score_agg(beam) = mean(beam_scores) if score_by = "mean" = beam_scores[-1] if score_by = "last"keep the K beams with smallest score_agg
Beams left with too few valid proposals are resampled (up to max_resample_attempts). Beam search starts from prompt and ignores upstream results; use_kv_caching reuses the generator’s KV cache across steps.
Configuration object for BeamSearchOptimizer.This class defines configuration parameters for the beam search optimizer, which
generates a single long segment by splitting it into beams of beam_length tokens
and performing beam search at each beam boundary.