Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Error message for non-scalar Tensor case. #278

Merged
merged 3 commits into from
Jun 22, 2019
Merged

Conversation

saeta
Copy link
Contributor

@saeta saeta commented Jun 22, 2019

When taking the gradient of a function, the function must return a scalar.
Because Tensors do not encode their shape or rank, this is checked dynamically
at runtime. Previously, we did not provide an error message, resulting in the
following error messages:

Precondition failed: file /swift-base/tensorflow-swift-apis/Sources/TensorFlow/Core/DifferentialOperators.swift, line 68
Current stack trace:
0    libswiftCore.so                    0x00007f1629f45830 swift_reportError + 50
1    libswiftCore.so                    0x00007f1629fb45d0 _swift_stdlib_reportFatalErrorInFile + 115
2    libswiftCore.so                    0x00007f1629edca7e <unavailable> + 3734142
3    libswiftCore.so                    0x00007f1629edcbf7 <unavailable> + 3734519
4    libswiftCore.so                    0x00007f1629cab10d <unavailable> + 1433869
5    libswiftCore.so                    0x00007f1629eb1a88 <unavailable> + 3558024
6    libswiftCore.so                    0x00007f1629caa569 <unavailable> + 1430889
9    repl_swift                         0x0000000000400490 <unavailable> + 1168
11   libswiftCore.so                    0x00007f1629caa569 <unavailable> + 1430889
14   repl_swift                         0x0000000000400490 <unavailable> + 1168
16   libswiftCore.so                    0x00007f1629caa569 <unavailable> + 1430889
17   libswiftTensorFlow.so              0x00007f16272250b0 <unavailable> + 2543792
18   libswiftTensorFlow.so              0x00007f1627098280 checkOk(_:file:line:) + 467
19   libswiftTensorFlow.so              0x00007f162709f480 TFE_Op.evaluateUnsafe() + 506
20   libswiftTensorFlow.so              0x00007f162709fcf0 TFE_Op.execute<A>(_:) + 132
21   libswiftTensorFlow.so              0x00007f16270a8984 <unavailable> + 985476
22   libswiftTensorFlow.so              0x00007f162713dc20 static Raw.matMul<A>(_:_:transposeA:transposeB:) + 1221
23   libswiftTensorFlow.so              0x00007f1627293c00 matmul<A>(_:transposed:_:transposed:) + 1427
24   libswiftTensorFlow.so              0x00007f16272f6210 _vjpMatmul<A>(_:transposed:_:transposed:) + 201
25   libswiftTensorFlow.so              0x00007f16273564b4 <unavailable> + 3794100
26   libswiftTensorFlow.so              0x00007f162731f960 AD__$s10TensorFlow5DenseV14callAsFunctionyAA0A0VyxGAGF__vjp_src_0_wrt_0_1 + 680
31   repl_swift                         0x0000000000400490 <unavailable> + 1168
Current stack trace:
	frame #4: 0x00007f162b926120 $__lldb_expr57`main at <Cell 8>:1

This change provides the user with a bit more context and prints out the shape
their computation produced to help them debug what might have gone wrong.

When taking the gradient of a function, the function must return a scalar.
Because Tensors do not encode their shape or rank, this is checked dynamically
at runtime. Previously, we did not provide an error message, resulting in the
following error messages:

Precondition failed: file /swift-base/tensorflow-swift-apis/Sources/TensorFlow/Core/DifferentialOperators.swift, line 68
Current stack trace:
0    libswiftCore.so                    0x00007f1629f45830 swift_reportError + 50
1    libswiftCore.so                    0x00007f1629fb45d0 _swift_stdlib_reportFatalErrorInFile + 115
2    libswiftCore.so                    0x00007f1629edca7e <unavailable> + 3734142
3    libswiftCore.so                    0x00007f1629edcbf7 <unavailable> + 3734519
4    libswiftCore.so                    0x00007f1629cab10d <unavailable> + 1433869
5    libswiftCore.so                    0x00007f1629eb1a88 <unavailable> + 3558024
6    libswiftCore.so                    0x00007f1629caa569 <unavailable> + 1430889
9    repl_swift                         0x0000000000400490 <unavailable> + 1168
11   libswiftCore.so                    0x00007f1629caa569 <unavailable> + 1430889
14   repl_swift                         0x0000000000400490 <unavailable> + 1168
16   libswiftCore.so                    0x00007f1629caa569 <unavailable> + 1430889
17   libswiftTensorFlow.so              0x00007f16272250b0 <unavailable> + 2543792
18   libswiftTensorFlow.so              0x00007f1627098280 checkOk(_:file:line:) + 467
19   libswiftTensorFlow.so              0x00007f162709f480 TFE_Op.evaluateUnsafe() + 506
20   libswiftTensorFlow.so              0x00007f162709fcf0 TFE_Op.execute<A>(_:) + 132
21   libswiftTensorFlow.so              0x00007f16270a8984 <unavailable> + 985476
22   libswiftTensorFlow.so              0x00007f162713dc20 static Raw.matMul<A>(_:_:transposeA:transposeB:) + 1221
23   libswiftTensorFlow.so              0x00007f1627293c00 matmul<A>(_:transposed:_:transposed:) + 1427
24   libswiftTensorFlow.so              0x00007f16272f6210 _vjpMatmul<A>(_:transposed:_:transposed:) + 201
25   libswiftTensorFlow.so              0x00007f16273564b4 <unavailable> + 3794100
26   libswiftTensorFlow.so              0x00007f162731f960 AD__$s10TensorFlow5DenseV14callAsFunctionyAA0A0VyxGAGF__vjp_src_0_wrt_0_1 + 680
31   repl_swift                         0x0000000000400490 <unavailable> + 1168
Current stack trace:
	frame #4: 0x00007f162b926120 $__lldb_expr57`main at <Cell 8>:1

This change provides the user with a bit more context and prints out the shape
their computation produced to help them debug what might have gone wrong.
@saeta saeta requested a review from eaplatanios June 22, 2019 17:50
@saeta
Copy link
Contributor Author

saeta commented Jun 22, 2019

Note: I'm open to suggestions for what to call the "forward pass", if you have thoughts.

@Shashi456
Copy link
Contributor

I know it's too much, but could we suggest or point to an example by which the person could debug his code?
Like for more look here type of thing. If there's one thing I don't like about error messages generally is, they only tell us what's wrong not how we could correct it.

Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

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

Thanks!

@saeta saeta merged commit 0862d9b into master Jun 22, 2019
@saeta saeta deleted the better-error-message branch June 22, 2019 19:12
@eaplatanios
Copy link
Contributor

Thanks Brennan!

@saeta
Copy link
Contributor Author

saeta commented Jun 22, 2019

Thank you @eaplatanios and @rxwei for speedy reviews! :-)

@saeta
Copy link
Contributor Author

saeta commented Jun 22, 2019

Note, looks like this is TF-320 (https://bugs.swift.org/browse/TF-320) Marking as fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants