Skip to content
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

Safe sampling feature #801

Merged
merged 15 commits into from
May 15, 2024
Merged

Safe sampling feature #801

merged 15 commits into from
May 15, 2024

Conversation

AYadrov
Copy link
Contributor

@AYadrov AYadrov commented May 13, 2024

This branch introduces a new feature for sampling which makes sampling safer if an unknown problem exists.
This feature checks whether all the precisions of an expressions have not increased. If this is true - then add slack to every operation.
The feature is pretty simple but can save few points where an unhandled problem occurred.

The branch also fixes small issues as: measuring ulp distance in backward pass with respect to repr instead of relying on float, and miscalculating exponent of min.bf in log2-approx

(vector-copy! vprecs 0 vprecs-new)

; Step 5. If precisions have not changed but the point didn't converge. A problem exists - add slack to every op
(when (false? (vector-member #f vrepeats))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if all the precisions are not higher than from previous run

Copy link
Contributor

Choose a reason for hiding this comment

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

The code is odd but whatever.

@AYadrov AYadrov requested a review from pavpanchekha May 14, 2024 21:11
Copy link
Contributor

@pavpanchekha pavpanchekha left a comment

Choose a reason for hiding this comment

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

I'm OK with merging this, clearly a good PR on net and I don't really want to slow down to fix the mixed-precision bug or add logging. (Though if logging is easy please do add some, just issue a warning with warn for example.)

(vector-copy! vprecs 0 vprecs-new)

; Step 5. If precisions have not changed but the point didn't converge. A problem exists - add slack to every op
(when (false? (vector-member #f vrepeats))
Copy link
Contributor

Choose a reason for hiding this comment

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

The code is odd but whatever.

[n (in-range (vector-length vprecs))])
(define prec* (min (*max-mpfr-prec*) (+ prec slack)))
(when (equal? prec* (*max-mpfr-prec*)) (*sampling-iteration* (*max-sampling-iterations*)))
(vector-set! vprecs n prec*))))
Copy link
Contributor

Choose a reason for hiding this comment

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

I would love it if this logged somewhere, but fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added

src/correct-round.rkt Show resolved Hide resolved
@@ -26,7 +26,7 @@
;; The first element of that function's output tells you if the input is good
;; The other elements of that function's output tell you the output values
(define (make-search-func pre specs ctxs)
(define fns (compile-specs (cons pre specs) (context-vars (car ctxs))))
(define fns (compile-specs (cons pre specs) (context-vars (car ctxs)) (context-repr (car ctxs))))
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this actually also maybe isn't quite right, since it assumes all outputs use the same repr. This won't be correct if an expression uses mixed binary32/binary64 code. That said, I'm not too worried about this because I think it'll need to be fixed a different way anyway.

@AYadrov AYadrov merged commit c2f4097 into main May 15, 2024
12 checks passed
@AYadrov AYadrov deleted the artem-safe-sampling branch May 15, 2024 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants