Call a round of training inside tf.vectorized_map?

I have an application which uses tf.linalg.lstsq inside of tf.vectorized_map to do least-squares regression to fit parameters for a large set of problem instances.

Similarly, this Bermudan option algorithm calls training to fit a function, inside a loop of the algorithm, for a fixed number of times. It’s the same kind of fitting, just a different choice of fitter.

Generalizing, is it possible to construct a tf.function which does a training iteration on a neural net, which can be called inside tf.vectorized_map? The point again would be to simultaneously do a kind of curve fitting on a large number of similar problem instances in parallel.

Hi @Lars_Ericson,

Sorry for the delay in response.

Yes, you can use tf.function inside of tf.vectorized_map where it is more efficient in parallel processing the inputs in TF and it increase the performance when you have large set of tensors compare to eager mode. Please check out this implementation in the gist for your reference.

Thank You.