Why isn't torch::jit::script::Module::forward const?

Wondering why the forward method isn’t const? And since it’s not, what’s the proper way to get back to the loaded state of the module without having to actually reload?


@kb1ooo Would you like to post this question in https://discuss.pytorch.org/c/jit? The JIT team monitors that channel more closely and we would be able to have a response there.

@yf225 ok, thanks. Is there a way to just move it there or do I repost?

@kb1ooo Reposting might be the easiest, thanks and sorry for the bad experience :frowning:

@yf225 oops, ok I saw that I could change the category so that’s what I did. Maybe not as effective as a repost.

Modules can have stateful data attached to themselves as parameters or attributes. These can be mutated during forward (or any other method that is run on the Module), so it doesn’t make sense to have it be const.

We don’t have any way of backing out changes to Module state, so re-loading is the only way to get back a known state. We may in the future have a user-accessible way of stating that some method is pure and has no mutable operations, but that’s still something we’re discussing.

Ok, understood, thank you.