Hello Arnav!



 arnavs:

How can I separate the two in practice?


The idea would be to preprocess your data before you feed it to your
model.
Depending on the details of your use case, you could, for example,
read your original data off of disk (independent of pytorch), construct
your Y vectors, and then write this preprocessed data back to disk.
When you run your pytorch model, just used the preprocessed data
as your input data.
Note, you will only get (significant) savings if you are going to run
(a lot) more than one epoch in your training loop.  (By “epoch” I
mean that you run each sample in your dataset through your model
once.)  If you are only going to run any given data sample through
your model once (or just a few times), it doesn’t matter whether you
perform the X_bar computation ahead of time or in during training.
So in such a case it might be more convenient to leave the X_bar
computation in your .forward().
Best.
K. Frank