Follow-up on Pyre implementation of Broadcast and Literal Arithmetic
Thank you again Pradeep and Brandon for the presentation last Monday! It is great to see the progress of Pyre and I appreciate the effort that you make for implementing new features in Pyre. I wanted to make sure that I fully understand what was presented in case that we can provide additional feedback. Regarding the implementation in Pyre of the Broadcast operator, I was wondering if the implementation follows the proposal that I made in 14-09-2020 (https://docs.google.com/presentation/d/16VGNfVo6Kxk9lBhm1cx1-Jr19dqESyy10Wkh...) or if you have made any change on its behavior or properties. For example, you mentioned that you were doing some normalization even if it was not in the slides, so I was curious if maybe you have spotted new equivalences of Broadcasting expressions. And as of literal arithmetic, I was wondering if it is available in Pyre. Although I said in (https://docs.google.com/presentation/d/16VGNfVo6Kxk9lBhm1cx1-Jr19dqESyy10Wkh...) that it requires standardization to be ready (typeshed) but I was wondering if it is already supported by rewriting typeshed internally. Best, Alfonso.
And as of literal arithmetic, I was wondering if it is available in Pyre
Yes, it is. As Brandon mentioned in his talk, he added support for it in Pyre's copy of typeshed. re Broadcast: Normalization is handled for properties like commutativity `BC[A, B] == BC[B, A]`. Concrete broadcasts are directly normalized to tuples. Associativity is feasible but not something we are prioritizing right now (`BC[A, BC[B,C]] == BC[BC[A, B], C]`). As we dogfood on more code, we will learn about other use cases that actually need to be handled. Another change was to raise broadcast errors to the user. This wasn't done by any existing type arithmetic operators (including `Divide[N, L[0]]`, which would silently fail). It required some special handling since the error needs to be raised at function call sites, not at the usage site of `Broadcast` itself: ``` def add(x: Tensor[float, *Ts], y: Tensor[float, *Rs]) -> Tensor[float, *Broadcast[Tuple[*Ts], Tuple[*Rs]]]: ... # No error here. x: Tensor[float, L[3], L[4]] y: Tensor[float, L[9], L[9]] add(x, y) # Broadcast error: Cannot broadcast (3, 4) with (9, 9) ``` Best,
participants (2)
-
Alfonso L. Castaño
-
S Pradeep Kumar