Jungmo_Ahn:

Could someone can share any idea (or alternative approach) to solve this problem?


One thing you can do is iterate over the entire module list with enumerate and only call each module if i is greater than some limit k. Performance will be worse than if you skipped the first k layers completely.



 Jungmo_Ahn:

According to torch.jit.script cannot index a ModuleList with an int returned from range() · Issue #47496 · pytorch/pytorch · GitHub, I identified that the i must be selected in compile time not runtime. Thus…, is this meaning that there no way to dynamically skip the front part of the Torchscript model?


You can dynamically skip the front part but only by annotating the LHS of your indexing statement with a module interface type. See the issue you linked for more details. I am currently working on extending this for ModuleList, it currently only works for ModuleDict.



 Jungmo_Ahn:

If this way is the unique way, why the two result are different?


I think it’s because from1 and from2 perform different computations?