fn
run_executable_inplace
void run_executable_inplace(CompiledExecutable * exe, const int & input_feeds, const int & output_targets)In-place variant: instead of allocating fresh MTLBuffers per output and returning new TensorImpls, write each output directly into the corresponding pre-existing TensorImpl's GPU buffer. Used by the compiled-optimizer step path where every output is a parameter (or optimizer-state buffer) that already has an allocated MTLBuffer; skipping the alloc + copy_ round-trip cuts the wrapper's overhead by ~50%.
Parameters
exeCompiledExecutable*The compiled forward (or forward+backward) graph.
input_feedsvector<TensorImplPtr>Inputs in
input_ids order — same as run_executable.output_targetsvector<TensorImplPtr>Pre-existing tensors whose buffers receive the executable's outputs. Must equal
output_ids.size() + grad_output_ids.size() in length, and each target must match its slot's shape and dtype exactly (no broadcasting).Notes
Not supported in dynamic-batch mode (output shapes vary per call,
no stable target buffers). Each target's bump_version is
called after the write so autograd's mutation tracker sees the
update. The target's MLX array reference is replaced with a
fresh one wrapping the same buffer to invalidate any cached MLX
dependency state.