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
Support %-based string formatting #45976
Conversation
[ghstack-poisoned]
ghstack-source-id: f0e3fc4fc230c283047fd5d211f9ac3b8a32f176 Pull Request resolved: #45976
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
ghstack-source-id: 23134fdb20f9e6c36ab1c76729debb8f32ed710f Pull Request resolved: #45976
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.
Reviewed part of it, please address current comments and we can iterate.
[ghstack-poisoned]
ghstack-source-id: c6542e392147904c1261f3cd82c65921522c40c6 Pull Request resolved: #45976
💊 CI failures summary and remediationsAs of commit 59b6fd0 (more details on the Dr. CI page): ✅ None of the CI failures appear to be your fault 💚
🚧 5 fixed upstream failures:These were probably caused by upstream breakages that were already fixed.
Please rebase on the
|
std::vector<char> specifiers = {'d', 'i', 'e', 'E', 'f', 'F', 's', 'c'}; | ||
auto format = peek(stack, 0, num_inputs).toStringRef(); | ||
auto args = last(stack, num_inputs - 1)[0]; | ||
auto args_size = !args.isTuple() ? 1 : args.toTuple()->elements().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.
Add a TORCH_CHECK to ensure that there is only 1 input when its type is tuple.
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.
Under what circumstances would there not be only one input? I believe that the modulo operator is always parsed into a Tree with a left child and a right child. This means that a test case like the one below would fail before hitting IREmitter at all.
# This test does not raise the correct error! Instead, it raises "cannot call a value of type 'Tuple[str, int]'"
def test_string_interpolation_with_double_tuple(self):
with self.assertRaisesRegex(RuntimeError, "Argument to format string must be a single str or Tuple"):
@torch.jit.script
def fn(arg1: str, arg2: int, arg3: float, arg4: str) -> str:
return "%s %d %f %s in template" % (arg1, arg2) (arg3, arg4)
fn("foo", 1, 1.0, "bar")
[ghstack-poisoned]
ghstack-source-id: c45db31e90244ce83cede64109bfcd5360351220 Pull Request resolved: #45976
[ghstack-poisoned]
ghstack-source-id: f7b8433f048d9cce155ae3efb8d50a895a0f8ee8 Pull Request resolved: #45976
[ghstack-poisoned]
ghstack-source-id: eca98db6201058e5efff72a0d083bb33b3d634f9 Pull Request resolved: #45976
[ghstack-poisoned]
Codecov Report
@@ Coverage Diff @@
## gh/ansleyadelaide/9/base #45976 +/- ##
=========================================================
Coverage 68.38% 68.38%
=========================================================
Files 411 411
Lines 53950 53950
=========================================================
+ Hits 36893 36895 +2
+ Misses 17057 17055 -2
Continue to review full report at Codecov.
|
[ghstack-poisoned]
ghstack-source-id: 76d8bef50d3e51cd3da887a44821ce5eeef4725c Pull Request resolved: #45976
[ghstack-poisoned]
[ghstack-poisoned]
ghstack-source-id: 86c85502befd882c8bdefff3d8c3a7d8674bc5d7 Pull Request resolved: #45976
[ghstack-poisoned]
[ghstack-poisoned]
ghstack-source-id: f5600a1af6fa36f1e2d6f140c90425b382d6b2f9 Pull Request resolved: #45976
[ghstack-poisoned]
[ghstack-poisoned]
ghstack-source-id: f2e5df2e7b6fef76bbdd63bab82d8598095a88a3 Pull Request resolved: #45976
Differential Revision: [D24374215](https://our.internmc.facebook.com/intern/diff/D24374215) [ghstack-poisoned]
ghstack-source-id: c0c94e2582be01a6288d773bf43acf0e56c1780f Pull Request resolved: #45976
Stack from ghstack:
Differential Revision: D24374215