Skip to content

[custom_op] support default dtype values - #129189

Closed
zou3519 wants to merge 6 commits into
gh/zou3519/1013/basefrom
gh/zou3519/1013/head
Closed

zou3519 wants to merge 6 commits into
gh/zou3519/1013/basefrom
gh/zou3519/1013/head

Conversation

@zou3519

@zou3519 zou3519 commented Jun 21, 2024 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

This PR:

  • moves some of the dtype-string utilities into ScalarType.{h, cpp}
  • adds a new utility to get a mapping from dtype name to the C++ dtype
  • the perser now checks if the string is a dtype name; if it is then it
    pulls the c++ dtype from the mapping.

Test Plan:

  • new tests

This PR:
- moves some of the dtype-string utilities into ScalarType.{h, cpp}
- adds a new utility to get a mapping from dtype name to the C++ dtype
- the perser now checks if the string is a dtype name; if it is then it
  pulls the c++ dtype from the mapping.

Test Plan:
- new tests

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jun 21, 2024 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/129189

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 41003ab with merge base 54b0006 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@pytorch-bot pytorch-bot Bot added the release notes: jit release notes category label Jun 21, 2024
This PR:
- moves some of the dtype-string utilities into ScalarType.{h, cpp}
- adds a new utility to get a mapping from dtype name to the C++ dtype
- the perser now checks if the string is a dtype name; if it is then it
  pulls the c++ dtype from the mapping.

Test Plan:
- new tests

[ghstack-poisoned]
This PR:
- moves some of the dtype-string utilities into ScalarType.{h, cpp}
- adds a new utility to get a mapping from dtype name to the C++ dtype
- the perser now checks if the string is a dtype name; if it is then it
  pulls the c++ dtype from the mapping.

Test Plan:
- new tests

[ghstack-poisoned]
This PR:
- moves some of the dtype-string utilities into ScalarType.{h, cpp}
- adds a new utility to get a mapping from dtype name to the C++ dtype
- the perser now checks if the string is a dtype name; if it is then it
  pulls the c++ dtype from the mapping.

Test Plan:
- new tests

[ghstack-poisoned]
Comment thread c10/core/ScalarType.cpp Resolved
return static_cast<int64_t>(at::Reduction::Mean);
} else if ("contiguous_format" == text) {
return static_cast<int64_t>(c10::MemoryFormat::Contiguous);
} else if (str2dtype.count(text) > 0) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Could you clarify the implication of this change? I'm not familiar with when this code is being used.

@zou3519 zou3519 Jun 21, 2024 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This function only gets called during construction of a FunctionSchema (https://www.internalfb.com/code/fbsource/[aca8f430d0152e7ffe6b24aedb8ee29808a16e3f]/fbcode/caffe2/torch/csrc/jit/frontend/function_schema_parser.cpp?lines=200%2C202%2C285%2C314%2C327): it is responsible for parsing the default values in the schema and turning them into an IValue. The implication of the change is now we support specifying the default value to be any of the keys in the str2dtype mapping (like "float64", "complex128", etc).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ok!
I guess none of these will be ambiguous!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There's a bug here though, we only want to parse this as a dtype if we're sure the type is a dtype, otherwise weird things like "int x = complex128" will work... so I'll try to fix that. The bug is pre-existing though

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah I guess anything that gets silently converted to int on the way down can have anything as it's default haha

This PR:
- moves some of the dtype-string utilities into ScalarType.{h, cpp}
- adds a new utility to get a mapping from dtype name to the C++ dtype
- the perser now checks if the string is a dtype name; if it is then it
  pulls the c++ dtype from the mapping.

Test Plan:
- new tests

[ghstack-poisoned]
This PR:
- moves some of the dtype-string utilities into ScalarType.{h, cpp}
- adds a new utility to get a mapping from dtype name to the C++ dtype
- the perser now checks if the string is a dtype name; if it is then it
  pulls the c++ dtype from the mapping.

Test Plan:
- new tests

[ghstack-poisoned]
zou3519 added a commit that referenced this pull request Jun 21, 2024
This PR:
- moves some of the dtype-string utilities into ScalarType.{h, cpp}
- adds a new utility to get a mapping from dtype name to the C++ dtype
- the perser now checks if the string is a dtype name; if it is then it
  pulls the c++ dtype from the mapping.

Test Plan:
- new tests

ghstack-source-id: ba83205
Pull Request resolved: #129189
@zou3519 zou3519 added ciflow/trunk Trigger trunk jobs on your pull request release notes: composability release notes category labels Jun 21, 2024
@zou3519

zou3519 commented Jun 23, 2024

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@github-actions
github-actions Bot deleted the gh/zou3519/1013/head branch July 23, 2024 01:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: composability release notes category release notes: jit release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants