pavel alex james zach panchekha sanchez stern wilcox
play

Pavel Alex James Zach Panchekha Sanchez-Stern Wilcox Tatlock - PowerPoint PPT Presentation

Automatically Improving Accuracy for Floating Point Expressions error Pavel Alex James Zach Panchekha Sanchez-Stern Wilcox Tatlock Floating Points Wild Success Floating Points Wild Success F R Often floating point is


  1. Automatically Improving Accuracy for Floating Point Expressions error ⇒ Pavel Alex James Zach Panchekha Sanchez-Stern Wilcox Tatlock

  2. Floating Point’s Wild Success

  3. Floating Point’s Wild Success F ≈ R Often floating point is close to real arithmetic But not always !

  4. Floating Point’s Wild Success But not always ! Numerous articles retracted [Altman ’99, ’03] Financial regulations [Euro ’98] Market distortions [McCullough ’99, Quinn ’83]

  5. Rounding Error in Sculpture Blake Courter @bcourter

  6. Rounding Error in Sculpture Blake Courter @bcourter Rounding error ⇒

  7. Rounding Error in Sculpture Blake Courter @bcourter Rounding error ⇒

  8. Existing options Big Float - Unreliable + More Reliable + Reliable - Slow Code + Fast Code + Fast Code - Expert Task

  9. e’ e Heuristic search to find expert transformations

  10. e’ e Heuristic search to find expert transformations Worked Example How Herbie Works Evaluation

  11. e’ e e R e F Heuristic search to find expert transformations Worked Example How Herbie Works Evaluation

  12. Rounding Error in Quadratic √ b 2 − 4 ac − b + 2 a 64 error

  13. Rounding Error in Quadratic √ b 2 − 4 ac − b + 2 a What is rounding error? exact computed J e K R J e K F 64                error 7 ULPs

  14. Rounding Error in Quadratic √ b 2 − 4 ac − b + 2 a What is rounding error? exact computed J e K R J e K F 64 log(ULPs)                7 ULPs log(ULPs) estimates # of incorrect bits

  15. Rounding Error in Quadratic √ b 2 − 4 ac − b + 2 a 64 log(ULPs) b

  16. Rounding Error in Quadratic  c b − b if b ∈ A a     √ b 2 − 4 ac  − b + √ if b ∈ B  b 2 − 4 ac − b +  2 a  ⇒ 2 c 2 a if b ∈ C √  b 2 − 4 ac − b −     − c if b ∈ D   b  A B C D 64 log(ULPs) b

  17. Rounding Error in Quadratic  c b − b A if b ∈ A a     √ b 2 − 4 ac  − b + √ if b ∈ B  b 2 − 4 ac − b +  2 a  ⇒ 2 c 2 a if b ∈ C √  b 2 − 4 ac − b −     − c if b ∈ D   b  A B C D 64 log(ULPs) Overflow J b 2 K F b If is large, overflows and the the whole expression returns . ∞ b

  18. Rounding Error in Quadratic  c b − b A if b ∈ A a     √ b 2 − 4 ac  − b + B √ if b ∈ B  b 2 − 4 ac − b +  2 a  ⇒ 2 c 2 a if b ∈ C √  b 2 − 4 ac − b −     − c if b ∈ D   b  Pretty Accurate A B C D 64 log(ULPs) b

  19. Rounding Error in Quadratic  b − b c A if b ∈ A a     √ b 2 − 4 ac  − b + B √ if b ∈ B  b 2 − 4 ac − b +  2 a  ⇒ 2 c 2 a C if b ∈ C √  b 2 − 4 ac − b −     − c if b ∈ D   b  Catastrophic Cancellation A B C D 64 log(ULPs) If is large, but and are small, b a c p and the difference b 2 − 4 ac b ≈ is rounded off. b

  20. Rounding Error in Quadratic  b − b c A if b ∈ A a     √ b 2 − 4 ac  − b + B √ if b ∈ B  b 2 − 4 ac − b +  2 a  ⇒ 2 c 2 a C if b ∈ C √  b 2 − 4 ac − b −     − c if b ∈ D D   b  Overflow again A B C D 64 log(ULPs) b

  21. Rounding Error in Quadratic  b − b c A if b ∈ A a     √ b 2 − 4 ac  − b + B √ if b ∈ B  b 2 − 4 ac − b +  2 a  ⇒ 2 c 2 a C if b ∈ C √  b 2 − 4 ac − b −     − c if b ∈ D D   b  A B C D 64 64 log(ULPs) ⇒ b b

  22. e’ e e R e F Heuristic search to find expert transformations Worked Example How Herbie Works Evaluation

  23. e’ e e R e F Heuristic search to find expert transformations Worked Example How Herbie Works Evaluation

  24. Herbie Architecture regimes sample cands e’ e e R e F focus generate more candidates

  25. Herbie Architecture Ground truth regimes sample cands e’ e e R e F focus generate more candidates

  26. Herbie Architecture regimes sample cands e’ e e R e F focus Localize error generate more candidates

  27. Herbie Architecture regimes sample cands e’ e e R e F focus generate more Heuristic search candidates

  28. Herbie Architecture regimes sample cands e’ e e R e F focus generate Keep all good more candidates candidates

  29. Herbie Architecture Combine candidates sample regimes cands e’ e e R e F focus generate more candidates

  30. Herbie Architecture Ground truth regimes sample cands e’ e e R e F focus generate more candidates

  31. Determine ground truth 64 random bits X = sample ( domain ( e )) e.g. X = { 1 . 2 · 10 − 17 , − 3 . 8 · 10 204 , 173 . 5 , . . . } Round ( J e K R ( X )) J e K F ( X ) Compute in F Get 64-bit prefix with MPFR. error Subtle ! See paper. e.g. { 13 . 2 b , 51 . 7 b , 1 b , . . . }

  32. Herbie Architecture Ground truth regimes sample cands e’ e e R e F focus generate more candidates

  33. Herbie Architecture regimes sample cands e’ e e R e F focus Localize error generate more candidates

  34. Focus: Estimate Error Source Overflow Cancellation 1. For each op in f e √ 2. Evaluate args in R b 2 − 4 ac − b + 3. Apply to them f R 2 a 4. Apply to them f F 5. Compare + F + R Round ( x + R y ) ( x + F y ) + K R K R J J p − b y = b 2 − 4 ac x =

  35. Herbie Architecture regimes sample cands e’ e e R e F focus Localize error generate more candidates

  36. Herbie Architecture regimes sample cands e’ e e R e F focus generate more Heuristic search candidates

  37. Herbie Architecture regimes sample cands e’ e e R e F focus rewrite Create candidates series simplify

  38. Apply rewrites to √ b 2 − 4 ac Recursive rewrites: − b + - Database of rules 2 a - Flexible - Chains of rewrites No cancellation − x 0 − x in denominator x + y x 2 − y 2 √ ! ( − b ) 2 − ( b 2 − 4 ac ) 2 / 2 a √ − b − b 2 − 4 ac x − y ( x − y ) + z √ √ � � (0 − b ) + b 2 − 4 ac b 2 − 4 ac b − 0 − x − ( y − z ) 2 a 2 a … 120 more … Rule DB

  39. Herbie Architecture regimes sample cands e’ e e R e F focus rewrite Create candidates series simplify

  40. Herbie Architecture regimes sample cands e’ e e R e F focus rewrite Approximate expr series simplify

  41. Series Expansions Idea: near -identities √ b 2 − 4 ac − b + √ 2 a 1 − x ≈ 1 − x/ 2 (for ) x ≈ 0 − b + b (1 − 4 ac/ 2 b 2 ) 2 a Bounded Laurent series: - Transcendental functions - Singularities - Number of terms to take

  42. Herbie Architecture regimes sample cands e’ e e R e F focus rewrite Approximate expr series simplify

  43. Herbie Architecture regimes sample cands e’ e e R e F focus rewrite series Cancel & clean up simplify

  44. Simplify Expressions √ ! ( − b ) 2 − ( b 2 − 4 ac ) 2 Difficult! [Caviness ’70] / 2 a √ − b − b 2 − 4 ac - many possible rewrites - huge search space √ ! b 2 − ( b 2 − 4 ac ) 2 = / 2 a - avoid undoing progress! √ − b − b 2 − 4 ac ✓ b 2 − ( b 2 − 4 ac ) ◆ = / 2 a √ − b − b 2 − 4 ac E-graphs [Nelson ’79] - Terminate early ✓ ◆ 4 ac / 2 a = - Prune useless nodes √ − b − b 2 − 4 ac - Restrict rewrites 2 c = √ b 2 − 4 ac − b −

  45. Herbie Architecture regimes sample cands e’ e e R e F focus rewrite series simplify Cancel & clean up

  46. Herbie Architecture regimes sample cands e’ e e R e F focus rewrite Keep all good series candidates simplify

  47. Herbie Architecture Combine candidates sample regimes cands e’ e e R e F focus rewrite series simplify

  48. Regime Inference √ c b − b − c 2 c b 2 − 4 ac − b + √ a b b 2 − 4 ac 2 a − b −

  49. Regime Inference  c b − b if b ∈ ( ∞ , − 1 . 15 E 122] Dynamic programming:  a    √ - Bounds quickly b 2 − 4 ac  − b + if b ∈ ( − 1 . 125 E 122 , 1 . 06 E − 304]   2 a  - Tune: binary search 2 c if b ∈ (1 . 06 E − 304 , 4 . 62 E 63] √  b 2 − 4 ac − b − - Pick best variable     − c if b ∈ (4 . 62 E 63 , ∞ )   b  A B C D

  50. Herbie Architecture Combine candidates sample regimes cands e’ e e R e F focus rewrite series simplify

  51. e’ e e R e F Heuristic search to find expert transformations Worked Example How Herbie Works Evaluation

  52. e’ e e R e F Heuristic search to find expert transformations Worked Example How Herbie Works Evaluation

  53. Evaluating Herbie A. Does accuracy improve? B. Does it reproduce expert transformations? C. Is the output code fast? D. Does it work in the real world?

Recommend


More recommend