Skip to content
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

Editorial: Fix glitch with otherwise clause in pool op creation #806

Merged
merged 2 commits into from
Jan 27, 2025

Conversation

inexorabletash
Copy link
Member

@inexorabletash inexorabletash commented Jan 21, 2025

A pair of steps in "create pooling operation" had an "If" condition with multiple clauses, and a subsequent "Otherwise" step that needs to apply if only the first clause is true. Rework the lines to correct the logic, and also align with subsequent argument validation.

Also, put "Otherwise, ..." steps on their own line consistently.


Preview | Diff

A pair of steps in "create pooling operation" had an "If" condition
with multiple clauses, and a subsequent "Otherwise" step that needs to
apply if only the first clause is true. Rework the lines to correct
the logic, and also align with subsequent argument validation.

Also, put "Otherwise, ..." steps on their own line consistently.
@inexorabletash
Copy link
Member Author

@huningxin @fdwr - super minor fix, can you please take a look?

But while I'm here... the step "set options.windowDimensions to the height and width dimensions of the shape of input." could be made more rigorous by actually giving the dimensions. This would be most easily done by pulling "calculate pool2d output sizes" steps inline so that inputHeight and inputWidth are calculated earlier given options.layout. I didn't want to do that without asking for opinions first. Thoughts?

Copy link
Collaborator

@fdwr fdwr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@fdwr
Copy link
Collaborator

fdwr commented Jan 22, 2025

But while I'm here... the step "set options.windowDimensions to the height and width dimensions of the shape of input." could be made more rigorous by actually giving the dimensions. This would be most easily done by pulling "calculate pool2d output sizes" steps inline so that inputHeight and inputWidth are calculated earlier given options.layout. I didn't want to do that without asking for opinions first. Thoughts?

I'm unsure why "calculate pool2d output sizes" is separate from the main algorithm, since it doesn't appear to be commonly shared anywhere else, but maybe it's that way because these others are also in independent sections...

  • calculate reduction output sizes
  • calculate conv2d output sizes
  • calculate convtranspose2d output sizes
  • calculate matmul output sizes
  • calculate padding output sizes

...and if we're keeping the output calculation separate in the other operators, then consistency is nice. Maybe we can refer to it rather than move inline?

@inexorabletash
Copy link
Member Author

I'm unsure why "calculate pool2d output sizes" is separate from the main algorithm, since it doesn't appear to be commonly shared anywhere else, but maybe it's that way because these others are also in independent sections...

(snip)

...and if we're keeping the output calculation separate in the other operators, then consistency is nice.

I did a quick poll of my fellow Googlers a while back, and they were in favor of inlining algorithms that are used in only one place. I think with the Calculate the output shape: (etc) subsections in the algorithms we maintain readability

Maybe we can refer to it rather than move inline?

Yeah, I think the intent is pretty obvious right now. We could also pull just the "Switch on layout..." step out and pass batches, channels, inputHeight, and inputWidth in, rather than inputShape. But at that point there's not much left and the description of the algorithm inputs is almost as long as the algorithm itself.

@huningxin
Copy link
Contributor

But while I'm here... the step "set options.windowDimensions to the height and width dimensions of the shape of input." could be made more rigorous by actually giving the dimensions.

+1

Maybe we can refer to it rather than move inline?

Yeah, I think the intent is pretty obvious right now. We could also pull just the "Switch on layout..." step out and pass batches, channels, inputHeight, and inputWidth in, rather than inputShape. But at that point there's not much left and the description of the algorithm inputs is almost as long as the algorithm itself.

I prefer to inline the "calculate pool2d output sizes" steps, because this algorithm internally calls "calculating conv2d output sizes" steps. By inline it, "pool2d" steps can be consistent with "conv2d" steps.

index.bs Outdated Show resolved Hide resolved
Co-authored-by: Ningxin Hu <[email protected]>
Copy link
Contributor

@huningxin huningxin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@huningxin
Copy link
Contributor

@inexorabletash , is this PR ready to merge? "calculate pool2d output sizes" change could be done by a separate CL, WDYT?

@inexorabletash
Copy link
Member Author

@inexorabletash , is this PR ready to merge? "calculate pool2d output sizes" change could be done by a separate CL, WDYT?

Agreed, I'd prefer to merge this and do a follow-on. Thanks for fixing my glitch, too!

@huningxin huningxin merged commit 751ca31 into webmachinelearning:main Jan 27, 2025
2 checks passed
github-actions bot added a commit that referenced this pull request Jan 27, 2025
SHA: 751ca31
Reason: push, by huningxin

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
@inexorabletash inexorabletash deleted the otherwise-tweaks branch January 27, 2025 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants