facebookresearch / theseus

A library for differentiable nonlinear optimization
MIT License
1.78k stars 128 forks source link

Mannual vs Automatic Vectorization #591

Closed EXing closed 1 year ago

EXing commented 1 year ago

❓ Questions and Help

503 said

Note that this feature is mostly for programming convenience. The alternative of creating individual cost functions objects doesn't hurt performance, because TheseusLayer by defaults vectorizes cost functions with the same pattern so they are evaluated in a single call.

But #565 shows manual vectorization makes the optimization faster.

This makes me confused.

luisenp commented 1 year ago

The sentence is #503 is indeed misleading. There is some overhead associated with cost function vectorization, because the populating the data is done with for loops in Python. So if you have a really high number of costs being vectorized together, you may pay a significant cost.