-
Notifications
You must be signed in to change notification settings - Fork 137
Lazy tensor: automatically promote constants to inputs based on history #476
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @bgogul! This is great. I'm really curious as to how big the performance gains / number of materializations reduced are after this change. I made some stylistic comments and I will try to go through the logic later today.
1218184
to
1310cb8
Compare
Thanks for the review, @eaplatanios! I have addresed your style comments. This is absolutely critical for performance. e.g., the step size constant changes often due to decay. If we don't promote the step size as an input, we will pay the cost of XLA compilation for almost every step. XLA compilation is not cheap; for MNIST, it takes about 6 s for compiling a single step of the training loop. |
@rxwei this is not super urgent, but can you take a look at this when you get a chance? |
Sorry for the delay! |
No worries. I addressed your comments and left some clarification questions. |
213a648
to
7c3b9bd
Compare
This PR implements the logic to promote constants to inputs (https://bugs.swift.org/browse/TF-704). Suppose that we have the following traces:
The above two functions are different and will need to be compiled individually. Suppose that we promote these constants to inputs as follows:
Only the inputs change and the function remains constant, which eliminates the additional compilation overhead.