-
Notifications
You must be signed in to change notification settings - Fork 24.5k
DOC Improves shape documentation for *Flatten #60980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
💊 CI failures summary and remediationsAs of commit cad4578 (more details on the Dr. CI page and at hud.pytorch.org/pr/60980):
🕵️ 1 new failure recognized by patternsThe following CI failures do not appear to be due to upstream breakages:
|
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 for the update! Mind making the analogous change in Flatten
for consistency?
torch/nn/modules/flatten.py
Outdated
- Input: :math:`(N, *dims)` | ||
- Output: :math:`(N, C_{\text{out}}, H_{\text{out}}, W_{\text{out}})` | ||
- Input: :math:`(*)`. Input can be any shape. | ||
- Output: :math:`(*, *unflattened\_size, *)`. |
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.
Any way to indicate that *unflattened_size
is expanded at dim
? Maybe something like (*, dim, *)
before and (*, *unflattened\_size, *)
after (where *
represents any number of dimensions, including none)- wdyt?
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.
(*, dim, *)
would be inconsistent with how the size is normally specified in other Shape descriptions.
What do you think of using dim
as a subscript: (*, S_{dim}, *)
, where S_{dim}
is the "size at dimension dim
".
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.
Cool, I agree with you that using dim
as a subscript is more accurate. We could even explicitly point out that S_{dim} = \prod *unflattened\_size
must hold - thoughts on that?
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.
Looking good! Not to spend too much time on this, but since a bunch of doc updates are coming down the pipe soon, probably good to get a consistent set of rules in place. What are your opinions on:
- Defining explicitly what
S_{i}
represents (e.g.where S_{i} is the size at dimension i
) - does this add anything or is it obvious? - Using
N_{i}
instead ofS_{i}
here - doesN_{i}
fit with other docs or is it confusing? - Defining explicitly what
*
represents - should we do this in the shape section of every doc? - Explicitly indicating that the rest of output matches the input shape like the
Linear
docs do - does this add anything or is it obvious? - Maybe there should be a section somewhere in the PyTorch docs defining the notation used in Shape sections? vs. defining everything in-place.
I guess in general there is a spectrum of notational rigor from loose + possibly implicit to tightly defined + explicit, with the end goal of having docs that are readable, understandable, and unambiguous to at least a reasonable extent. I think the strategy up until now has been taking it on a case-by-case basis, and this unfortunately has lead to some inconsistencies throughout the docs
torch/nn/modules/flatten.py
Outdated
- Input: :math:`(N, *dims)` | ||
- Output: :math:`(N, \prod *dims)` (for the default case). | ||
- Input: :math:`(*, S_{start}, *, S_{end}, *)` | ||
- Output: :math:`(*, \prod_{i=start}^{end} S_{i}, *)` (for the default case). |
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.
nit: I don't think "(for the default case)" is needed now since the more precise edit should cover all cases I believe
I think it's good to discuss now and spend a little time on this. Looks like we are going to end up working on #59566 for the "Shape" sections, while updating for no-batch.
I prefer explicit standing it.
I think we need to do this. Sometimes
Having a section defining the notation is good to have for developers regardless of if we define it in place. I do like having definitions in-place for users. Overall I think the "Shape" section should be more on the explicit slide. |
For the Linear case, I think it is obvious because of how the Something like this: |
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.
Flatten
update looks good to me! Unflatten
is pretty good and I do agree with your thoughts that explicit is better in general.
Only thing I'm wondering is if a U_{i}
notation will help readability- wdyt? something like:
Input: (*, S_{dim}, *), where S_{dim} is the size at dimension dim
Output: (*, U_1, ..., U_n, *), where U = unflattened_size and \prod_i^n U_i = S_{dim}
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.
LGTM!
@jbschlosser has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
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.
Nice! Thanks for fixing. Btw, the formatting will look slightly nicer if you use \text{start}
and \text{end}
. No worries if you want to merge this as-is, since this is already drastic improvement.
@jbschlosser has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator. |
@jbschlosser merged this pull request in 5503a4a. |
Fixes #60841