Commit d29575b
refactor(fk_steering): extract per-particle guided step into a helper (#299)
## Summary
Fixes #77.
`FKSteering._run_step` was a ~125-line method that mixed two concerns:
the unguided batched fast path and the guided per-particle loop (with
its 4D restacking and `SamplerStepOutput` reassembly). Extracted the
guided branch into `_run_guided_step_per_particle`, so `_run_step` now
reads as a small dispatch:
```python
coords_4d = coords.reshape(num_particles, self.ensemble_size, -1, 3)
if step_scaler is None:
... # batched fast path, early return
return self._run_guided_step_per_particle(coords_4d, model, sampler, features, context, step_scaler, num_particles)
```
**Pure extraction — no behavior change.** The guided body (per-particle
`sampler.step`, loss/log-correction reduction, `torch.stack` restacking)
is moved verbatim.
### Why the two paths stay separate
The issue notes the guided/unguided paths look duplicated, but they
can't be fully merged: the unguided path runs a **single batched forward
pass** over all `particles * ensemble` structures (one `sampler.step`),
while the guided path must step **each particle independently** so its
guidance gradient is computed only from its own state (correct FK
semantics). Funneling the batched output through the per-particle
stacker would misinterpret the whole batch as one particle. So the split
is intentional; this change makes that boundary explicit and readable
rather than collapsing it. Documented the rationale in the new method's
docstring.
Closes #77.
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
* **Refactor**
* Improved the stepping flow for guided sampling by separating the
per-particle path into a dedicated internal routine.
* Preserved the existing fast path when no step scaling is used,
including returning denoised coordinates when available.
* Kept guided particle-by-particle behavior unchanged, with results
still aggregated and reshaped into the expected output format.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Co-authored-by: xraymemory <me.anzuoni@gmail.com>
Co-authored-by: M E A <xraymemory@users.noreply.github.com>1 parent 990372a commit d29575b
1 file changed
Lines changed: 46 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
286 | 286 | | |
287 | 287 | | |
288 | 288 | | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
289 | 335 | | |
290 | 336 | | |
291 | 337 | | |
| |||
0 commit comments