Commit Graph

35 Commits

Author SHA1 Message Date
Kazuaki Ishizaki
e664420b79 minor spelling tweaks 2019-12-09 18:21:12 +09:00
David Majnemer
bcc6b7a33d [XLA] Print more digits when hitting miscomparisons
We should print enough digits to make the output unambiguous.

PiperOrigin-RevId: 278990208
Change-Id: I198a9f0d4c16015b1d7b6c5bb81a9e1400d3678f
2019-11-06 19:21:27 -08:00
David Majnemer
d6fee25d1d [XLA] Clean up some floating point printing code
- When doing *exact* floating point comparisons, print out enough digits of the
  floating point number to unambiguously round trip to the float in question.
- The exhaustive op test had an off-by-one for precision when printing a float.

PiperOrigin-RevId: 277988562
Change-Id: I9d30190a754d698e009fd51aa7fe6ca5661e2bc0
2019-11-01 13:34:51 -07:00
George Karpenkov
070b7044de [XLA] s/float/double in literal_comparison to avoid ubsan warning.
Sometimes the double we pass does not fit into double, which triggers ubsan

PiperOrigin-RevId: 254852050
2019-06-24 15:54:16 -07:00
A. Unique TensorFlower
abd1460193 Near comparison now works for non-fp types. Callback uses ShapeIndex parameter.
literal_comparison::Near will now make a call to miscompare_callback when non
floating/complex types fail the check.

literal_comparison::Near may now accept nullptr as a miscompare_callback. In
this case, it will return on the first failed comparison.

MiscompareCallback functions now have the ShapeIndex of the LiteralSlice being
compared as a parameter.

PiperOrigin-RevId: 251722837
2019-06-05 16:01:58 -07:00
A. Unique TensorFlower
41a2e0676f Added equality checking rules for S8, S16, and U16 primitive types.
PiperOrigin-RevId: 249695571
2019-05-23 13:03:14 -07:00
Bixia Zheng
aa4765a141 [XLA] Fix literal_comparison to avoid cast overflow undefined behavior.
In partcular, templated function FpAbsoluteValue is used to compute the abs of
a value and previously, it returns a float. Change this function to return
a double instead to avoid cast overfloat for inputs with types double and
complex128.

Add a test case.

PiperOrigin-RevId: 240984454
2019-03-29 08:46:36 -07:00
A. Unique TensorFlower
1f6e793504 [XLA] Fix bug in functions comparing complex values: avoid double decrement of the number of mismatches when only the real parts of the values are different.
PiperOrigin-RevId: 239736734
2019-03-21 22:09:06 -07:00
Justin Lebar
a827a4bee1 [XLA] By default, display a detailed breakdown when comparing large literals.
Literal comparison has the option of displaying a "detailed breakdown", which
includes things like the distribution of errors.  Previously, you'd only get
this breakdown if you asked for it, but there are many routines that don't
expose this knob.  We could expose it piecemeal, but I think in general if
you're comparing a "large" literal and you have mismatches, you probably want
this breakdown.  At least, it's not going to be a lot of noise.  So this patch
makes us show the default breakdown by default when the array being compared is
above a certain size.

PiperOrigin-RevId: 230834776
2019-01-24 19:30:27 -08:00
Justin Lebar
d058a78ac3 [XLA] Add ErrorSpec::fewer_infs_ok knob.
This allows us to accept actual results that overflow to inf when the correct
answer is a large, finite value.

PiperOrigin-RevId: 230810756
2019-01-24 16:53:05 -08:00
Justin Lebar
d54d31d8ed [XLA] Fix literal_comparison's handling of nan vs inf.
Previously, we'd always report expected nan vs. actual inf as a miscompare,
even if relaxed_nan was set.  This is just a bug; the intent of relaxed_nan is
to allow any actual value if the expected is nan.

PiperOrigin-RevId: 230763808
2019-01-24 12:25:48 -08:00
Peter Hawkins
937ff1b4cf [XLA] Add complex128 support.
Minimally tested at the moment (tested via the TF tests).

PiperOrigin-RevId: 228931680
2019-01-11 13:11:43 -08:00
Justin Lebar
79126ece73 [XLA] Avoid fp division by 0 in literal_comparison.cc.
Found by running hlo_evaluator_test with ubsan.

PiperOrigin-RevId: 226937627
2018-12-26 11:38:01 -08:00
Mark Heffernan
83dbe37b4b Replace ShapeUtil::Is(Array|Tuple|Token|Opaque) with
Shape::Is(Array|Tuple|Token|Opaque).
No functional change. ShapeUtil methods are marked as deprecated. These methods
will be removed in a later CL.

PiperOrigin-RevId: 226425321
2018-12-20 18:26:20 -08:00
Mark Heffernan
1ed59e52b1 Replace calls to ShapeUtil::Rank with Shape::rank.
No functional change. ShapeUtil::Rank is marked as deprecated. A later CL will remove it.

PiperOrigin-RevId: 226412117
2018-12-20 16:38:08 -08:00
A. Unique TensorFlower
23b92345f4 [TF:XLA] Speed up Literal::Near comparisons.
Avoid eagerly generating an error status string. Instead only generate the error status lazily when a comparison fails.

PiperOrigin-RevId: 225443548
2018-12-13 15:18:23 -08:00
Mark Heffernan
b32d3167ff Add HLO test with tuple-shaped output containing a token.
Also, fix CHECK failure in proto deserialization when the shape of an infeed was not a tuple.

PiperOrigin-RevId: 221209419
2018-11-12 21:40:34 -08:00
Michael Kuperstein
6b8e08a932 [XLA] Avoid UB in absl::bitcast from Eigen::half.
PiperOrigin-RevId: 219331320
2018-10-30 11:13:50 -07:00
Justin Lebar
aaade421b3 Switch tensorflow::bit_cast -> absl::bit_cast.
PiperOrigin-RevId: 219228749
2018-10-29 18:37:33 -07:00
Tim Shen
6f879f891a [XLA] Rename all (Mutable)ArraySlice to absl::Span.
PiperOrigin-RevId: 210998142
2018-08-30 16:07:27 -07:00
Tim Shen
09f2c342c0 Remove (Mutable)ArraySlice implementation and alias them to absl::Span.
There are several API migrations happening:
* ArraySlice's sub-slice constructor => .subspan
* MutableArraySlice's container pointer constructor => absl::MakeSpan

PiperOrigin-RevId: 210946124
2018-08-30 11:29:03 -07:00
Kay Zhu
e105c101f1 [XLA] In literal_comparison, set absolute error and relative error to infinity
if:

- expected is infinity
- actual != expected

This prevents Near from generating a NaN for relative error.

Also compare the real and imaginary parts of complex numbers independently.

PiperOrigin-RevId: 210637112
2018-08-28 17:26:35 -07:00
Justin Lebar
d57f5a8202 [XLA] Switch to absl::StrFormat.
Unlike Printf, StrFormat does not require type-length qualifiers, e.g
%z, %ll.  Nor does it require that you call c_str() to print strings.
So these are fixed up here as well.

PiperOrigin-RevId: 210435915
2018-08-27 14:55:29 -07:00
Justin Lebar
769f83b041 [XLA] Use absl::Hex instead of tensorflow::strings::Hex.
PiperOrigin-RevId: 210058186
2018-08-23 23:40:22 -07:00
Mark Heffernan
3ed1f31b1a Clean up Literal comparision mismatch messages.
Make the error messages more consistent between "Near" comparisons and "Equal" comparisons, and give Shape index for mismatches in tuples. Also, polish flag descriptions and test output in run_hlo_module.

==== BEFORE:

Mismatches in shape (s32[], s32[], s32[]) (3 elements):
Expected equality of these values:
  470211269
  0
at index {}:
expected: 470211269
actual:   0

==== AFTER:

Mismatches in shape (s32[], s32[], s32[]) (3 elements):

Array at shape index {1}, first mismatch at array index {}:
  expected value: 470211269
  actual value:   0

Expected literal:
(s32[], s32[], s32[]) (
-1865008400,
470211269,
470211269
)

Actual literal:
(s32[], s32[], s32[]) (
-1865008400,
0,
470211269
)

PiperOrigin-RevId: 210017733
2018-08-23 16:10:33 -07:00
Justin Lebar
90d9d2b194 [XLA] Use absl string types and functions instead of the TF versions.
Unfortunately this has to be one big patch, because e.g. absl::StrCat
doesn't accept a TF StringPiece, but as soon as we switch to
absl::string_view, we have to switch away from all of the TF functions.
PiperOrigin-RevId: 209957896
2018-08-23 10:27:38 -07:00
Mark Heffernan
3e96a135d9 Fix bug in reporting of the mismatch index in literal comparison.
Previously, for equal comparisons the reported mismatched index would always be the last index in the shape rather than the index of the actual miscompare.

PiperOrigin-RevId: 209086635
2018-08-16 18:46:58 -07:00
Kay Zhu
8779f768a3 [TF:XLA] Split literal_util into {literal, literal_util}.
Currently Literal classes sits in literal_util.{h,cc} instead of literal.{h,cc}.
It also contains helper functions that are better fit to be their own separate
class/namespace. This change starts this process by moving most static factory
methods to LiteralUtil namespace.

PiperOrigin-RevId: 203217065
2018-07-03 19:06:26 -07:00
Mark Heffernan
f01d25471d Add support for TOKEN type to CPU/GPU backends.
TOKENs will be used for ordering side-effecting operations. They are not materialized but can be contained in tuples and flow into and out of computations. This CL adds a trivial representation for the cpu and gpu backends to support TOKENs and modifies copy insertion to avoid making copies of tokens.

This also adds a Literal TOKEN which is required for the interpreter backend.

PiperOrigin-RevId: 200623120
2018-06-14 14:54:32 -07:00
Mark Heffernan
e1296c15a3 Fix assumptions that a Shape must be a tuple or an array.
A TOKEN primitive type was added with cl/199215963 and XLA also has an OPAQUE primitive type. However, in many places in XLA we assume either a tuple or array. This CL fixes many of those instances, but some may remain. Identified instances were discovered by searching for IsTuple or IsArray so the set of fixes is not exhaustive.

Also opportunistically addressed a couple potential points of confusion in the ShapeUtil interface:

(1) Rename ShapeUtil::HasZeroElements to ShapeUtil::IsZeroElementArray. The point of confusion here is that tuples can also have zero elements and HasZeroElements would check fail on tuple shapes. Method no longer check fails if the given shape is not an array.

(2) ShapeUtil::IsNil now returns true only for empty tuples. Previously it also returned true for zero-element array types which was confusing because ShapeUtil::MakeNil creates an empty tuple.

PiperOrigin-RevId: 200452672
2018-06-13 14:24:30 -07:00
Justin Lebar
f3b20d8270 Automated g4 rollback of changelist 198137414
PiperOrigin-RevId: 198477942
2018-05-29 16:43:35 -07:00
Justin Lebar
336d77ea19 [XLA] Don't compute relative error when the expected value is 0.
In literal_comparison, don't try to compute a relative error when the
expected value is 0, because doing so would mean that the only
acceptable value *is* zero, which probably isn't what you mean.

PiperOrigin-RevId: 198137414
2018-05-25 20:26:13 -07:00
Nick Desaulniers
a39fa2d526 [TF:XLA] make miscomparison error messages more readable
PiperOrigin-RevId: 197620560
2018-05-22 14:11:48 -07:00
Chris Leary
b613f399ee [XLA] Move more comparison functions to non-test library.
PiperOrigin-RevId: 196605347
2018-05-14 19:23:36 -07:00
Chris Leary
400dd49b4c [XLA] Break out literal comparisons from testonly target.
Moves methods from LiteralTestUtil::* to Literal::* where they have nothing
to do with test infrastructure.

Pares down the "void" variants of the LiteralTestUtil methods and consolidates
to the version that return success/failure such that the values can be
EXPECT_TRUE / ASSERT_TRUE asserted in the caller test cases.

This way the literal comparison functionality can be used from cc_libraries
that are not test only / cc_binary.

PiperOrigin-RevId: 196209410
2018-05-10 20:13:33 -07:00