Skip to content

SPARK-2748 [MLLIB] [GRAPHX] Loss of precision for small arguments to Math.exp, Math.log - #1659

Closed
srowen wants to merge 1 commit into
apache:masterfrom
srowen:SPARK-2748
Closed

srowen wants to merge 1 commit into
apache:masterfrom
srowen:SPARK-2748

Conversation

@srowen

@srowen srowen commented Jul 30, 2014

Copy link
Copy Markdown
Member

In a few places in MLlib, an expression of the form log(1.0 + p) is evaluated. When p is so small that 1.0 + p == 1.0, the result is 0.0. However the correct answer is very near p. This is why Math.log1p exists.

Similarly for one instance of exp(m) - 1 in GraphX; there's a special Math.expm1 method.

While the errors occur only for very small arguments, given their use in machine learning algorithms, this is entirely possible.

Also note the related PR for Python: #1652

@SparkQA

SparkQA commented Jul 30, 2014

Copy link
Copy Markdown

QA tests have started for PR 1659. This patch merges cleanly.
View progress: https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17444/consoleFull

@SparkQA

SparkQA commented Jul 30, 2014

Copy link
Copy Markdown

QA results for PR 1659:
- This patch PASSES unit tests.
- This patch merges cleanly
- This patch adds no public classes

For more information see test ouptut:
https://amplab.cs.berkeley.edu/jenkins/job/SparkPullRequestBuilder/17444/consoleFull

@mengxr

mengxr commented Jul 30, 2014

Copy link
Copy Markdown
Contributor

LGTM. Merged into master. Thanks!!

@asfgit asfgit closed this in ee07541 Jul 30, 2014
@srowen
srowen deleted the SPARK-2748 branch July 30, 2014 16:45
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
…Math.exp, Math.log

In a few places in MLlib, an expression of the form `log(1.0 + p)` is evaluated. When p is so small that `1.0 + p == 1.0`, the result is 0.0. However the correct answer is very near `p`. This is why `Math.log1p` exists.

Similarly for one instance of `exp(m) - 1` in GraphX; there's a special `Math.expm1` method.

While the errors occur only for very small arguments, given their use in machine learning algorithms, this is entirely possible.

Also note the related PR for Python: apache#1652

Author: Sean Owen <srowen@gmail.com>

Closes apache#1659 from srowen/SPARK-2748 and squashes the following commits:

c5926d4 [Sean Owen] Use log1p, expm1 for better precision for tiny arguments
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 23, 2026
…e it (apache#1659)

<!-- title: [VARKA-570] Stop an option-matrix bin at three times its plan and name it -->
### What changes were proposed in this pull request?

The option matrix packs its units into bins of about eight minutes each. The planner knows each bin's planned seconds, but nothing in the bin job read them. Now a bin that runs far past its plan stops itself and says so.

- A watchdog beside the bin's units fires at three times the plan, never before 32 minutes.
- It writes `straggler.txt` (the plan, the time, the CPU, each unit's state), stops the running units by their process groups, prints a `Straggler` annotation and exits 3.
- The report's summary lists the stragglers. The CI ledger records one as a `slow` line and still reads the failures of units that finished before the stop.
- `dev/varka_matrix_stragglers.py history` reads the units steps' times; the floor of 32 minutes comes from that.
- A dispatch input, `plant-straggler=bNNN`, makes one bin sleep past its deadline, to test the path on CI.

<details>
<summary>Design details</summary>

Each unit starts under `setsid`, so it has a process group of its own. TERM goes first, KILL after 30 s, and nothing is stopped by pattern.
The loop checks for the marker before it starts each unit, so units waiting for a slot are listed as not run.
`wait -n` names the units' PIDs, so the step never waits on its watchdog. A bin that ends on time stops the sleeping watchdog.

The floor: in 19 runs, 3,049 bin jobs, the longest green units step took 24.3 minutes (`results/VARKA-570-units-history.txt`). The next multiple of the planner's 480 s lane is 1,920 s.

A rerun keeps the first attempt's artifact, and the report downloads only the newest copy of a name, so the ledger reads the straggler from its annotation.
Nothing here reruns a straggler. A follow-up adds the automatic rerun.

</details>

### Why are the changes needed?

A job keeps the runner it was given, and the pool sometimes hands out a machine many times slower. Bin b021 of run 40942811546 ran 91 minutes against a median of 8, until the 90-minute timeout cancelled it. Bin b023 of a 5 November run ran 43 minutes and the run had to be cancelled by hand.

### Does this PR introduce _any_ user-facing change?

No. CI and tooling only.

### How was this patch tested?

On the laptop, on head `6b599a601d4` (the branch merged with master `241125b2f37`):

- Both lints, Error Prone and the invariant and proof suites passed (`extra-gate.sh`).
- The push check passed: 738 counted lines.
- `python3 -m unittest dev/varka_ci_ledger.py` passed, the straggler case included.
- Not run: the planted straggler on CI, a Build and the option matrix.

<details>
<summary>Full test record</summary>

The gate was `~/varka-ops/pre-pr.sh`: no regeneration, since the branch changes no input of the generated files, and no arm sweep, since it changes no suite.
The watchdog's shell was checked before the rebase with the same shape under `setsid`: a stopped JVM writes no `exit` file, so the report lists it as "did not finish" and fails on neither.

Owed: one dispatch with `plant-straggler` on CI, which the owner starts.

</details>

### Review

`/code-review high` on the rebased branch found one important issue: a test failure in a stopped bin vanished from the ledger. It is fixed, with its test. Two of seven nits are fixed.

<details>
<summary>The nits left</summary>

- A unit started between the watchdog's listing and its TERM can be left out of `straggler.txt` and run until the KILL.
- The deadline has no cap below the job's 90-minute timeout, so a bin planned past about 1,100 s is cancelled before it fires.
- After a rerun, the report's summary says "Stragglers: none".
- `history` lists every attempt's jobs, so a rerun's bins may be counted twice in the history file.
- A bin whose last unit ends at the deadline can be failed as a straggler.

</details>

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 24, 2026
…e#1678)

### What changes were proposed in this pull request?

`varka-option-matrix.yml` can now run a pull request's option matrix on vecbricks/varka's runners, beside the fork's (MaxGekk/spark).

- New dispatch inputs `pr` and `sha`, for vecbricks/varka only. There a dispatch without them fails, and the fork refuses them. Each checkout (build, bins, report) takes vecbricks/varka at `sha`, which is the pull request's head. The first step of the build job checks with `git ls-remote` that `refs/pull/<pr>/head` is still `sha`, and fails the run if it is not. The run is named `Varka option matrix of #<pr> at <sha>`. Without `pr` the name stays `Varka option matrix`.
- New dispatch input `slots`, which sets the bins' `max-parallel`. If it is blank, the value is 16 on vecbricks/varka and 38 on other repositories, as before.
- The build job runs only for a dispatch, so it refuses the Sunday schedule on both repositories until row 522 moves the schedule to the fork (`m9/VARKA-522.md` 2.1, which gets a dated line). Before this change the schedule ran only on vecbricks/varka, where the workflow has been disabled since 29 October, so enabling it there would have started a full matrix on 20 runners every week.
- A run with `pr` does not look for the fork's Build. It compiles the test classes itself and says why in its warning.
- The workflow token is read-only (`contents: read`, `actions: read`), and the checkouts do not keep it. `report-failure` keeps its own permissions.
- A run with `pr` saves its sbt and Coursier caches under `pr-` keys, which no other run restores, and does not save the engine's Maven cache. The pull request's code writes those directories, and the run saves them in master's scope.
- `VARKA-638.md` section 8 gets a dated note: the owner's word of 23 November overtakes its "not a row now". `sql/varka/AGENTS.md` and `skills/testing-and-debugging.md` no longer mention a weekly option matrix.

### Why are the changes needed?

On 23 November about 380 option-matrix jobs waited on the fork's 40 runners at midday, while most of vecbricks/varka's 20 runners were idle between benchmarks. A pull request's branch lives on the fork, so a vecbricks/varka dispatch runs from master, and before this change the workflow could only test master there. With `pr` and `sha` it tests the pull request's head. The cap of 16 bins leaves runners for the benchmarks. A vecbricks/varka run cannot download the fork Build's artifacts without a token (an unauthenticated download returns 401), so it compiles and runs without the reach record. This makes it about 2.5 to 3 times slower than a run on an idle fork. The dispatcher outside the repository sends a matrix there only when the fork's queue is long.

### Does this PR introduce _any_ user-facing change?

No. It changes only a CI workflow, a plan and two developer documents.

### How was this patch tested?

Master `0d99ed25ba0` (with apache#1659, row 570's straggler stop, and apache#1677) is merged in `c26ba5e2878`. The one conflict was the dispatch inputs: master's `plant-straggler` now sits beside `pr`, `sha` and `slots`, and the rewritten "Run this bin's units" step merged unchanged under this branch's checkouts. After the merge `actionlint` and the selftests of `dev/varka_bin_units_test.py`, `varka_matrix_bins.py`, `varka_matrix_reuse.py`, `varka_matrix_stragglers.py`, `varka_ci_ledger.py` and `varka_scheduled_failure_test.py` pass, and the light gate passed on `088c275fc18`.

Before the merge, the local gate passed on `77cae98b6ba` as a light gate: master `323733401c6` already merged, no regeneration needed, lints, Error Prone and the push check passed (152 counted lines), no suite to sweep. Also `actionlint`, a YAML parse of the new expressions, and `dev/varka_bin_units_test.py --selftest`, which runs the bin step's shell from the workflow. A GitHub Actions run is the first real check: a fork dispatch without `pr` (the old path), then one vecbricks/varka dispatch with `pr`, after this merges and the workflow is enabled there.

### Review

`/code-review high` on `b619370a5f4` found four important problems and four nits. All are fixed in `a8bced1cb7e`, except one nit noted below. The important ones:
- A dispatch on vecbricks/varka without `pr` skipped every job instead of failing. It now fails in the input check.
- A fork dispatch with `pr` gave up the fork's own Build reuse, and the CI tools would have filed its results under the dispatched commit. The fork now refuses `pr`.
- A pull request run could save caches that master's runs restore. It now uses `pr-` keys.

The nits: the dead schedule (kept, since row 522 turns it to the fork, and the comments say so in `77cae98b6ba`), the docs that named a weekly run, a comment on the reuse step, and a note that the dispatcher, not a `concurrency` group, keeps vecbricks/varka to one matrix at a time. A group would cancel the older of two pending runs.

A second `/code-review high`, after the merge of master, found nothing in the resolution. Its nits are fixed in `088c275fc18`: the testing skill no longer promises a run "a day later", `AGENTS.md` says a vecbricks/varka run has no reach record and runs every test, and `VARKA-522.md` names `report-failure`'s condition instead of stale line numbers. Its important findings are trade-offs of this design, kept:
- Pull request runs share their `pr-` caches with each other, and a pull request's code runs in a job scoped to master's caches. Every pull request on vecbricks/varka is the owner's, and only the owner dispatches.
- On vecbricks/varka master's copy of the workflow runs over the pull request's scripts. The dispatcher refuses a pull request that changes this workflow, so such a pull request's matrix runs on the fork.
- The CI readers that look for a matrix by branch and head on the fork (`watch-any-ready.sh`, `watch-infra.sh`, `matrix-link.sh`, `dev/varka_ci_ledger.py`) do not see a vecbricks/varka run, whose branch is master and whose pull request head is only in its title. A follow-up teaches them the title lookup. Until then the run is read through its link on the pull request.
- There is still no `concurrency` group, for the reason above.

### Was this patch authored or co-authored using generative AI tooling?

Generated-by: Claude Code (Claude Opus 5.5)
MaxGekk pushed a commit to MaxGekk/spark that referenced this pull request Nov 25, 2026
Resolves the option matrix workflow and its bin-step test against row
570's straggler stop (apache#1659): both stages' bin step takes the bin's
reach beside its plan seconds, deadline and planted straggler, and the
dispatch inputs keep stages beside plant-straggler. The test's step
environment gains REACH.

Generated-by: Claude Code (Claude Opus 5.5)
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.

3 participants