Skip to content

[SPARK-2601] [PySpark] Fix Py4J error when transforming pickleFiles - #1605

Closed
JoshRosen wants to merge 1 commit into
apache:masterfrom
JoshRosen:spark-2601
Closed

JoshRosen wants to merge 1 commit into
apache:masterfrom
JoshRosen:spark-2601

Conversation

@JoshRosen

Copy link
Copy Markdown
Contributor

Similar to SPARK-1034, the problem was that Py4J didn’t cope well with the fake ClassTags used in the Java API. It doesn’t look like there’s any reason why PythonRDD needs to take a ClassTag, since it just ignores the type of the previous RDD, so I removed the type parameter and we no longer pass ClassTags from Python.

Similar to SPARK-1034, the problem was that Py4J didn’t cope well with
the fake ClassTags used in the Java API.  It doesn’t look like there’s
any reason why PythonRDD needs to take a ClassTag, since it just ignores
the type of the previous RDD, so I removed the type parameter and we
no longer need to pass ClassTags from Python.
@SparkQA

SparkQA commented Jul 26, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Jul 26, 2014

Copy link
Copy Markdown

QA results for PR 1605:
- 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/17231/consoleFull

@mateiz

mateiz commented Jul 27, 2014

Copy link
Copy Markdown
Contributor

Thanks Josh; merged this.

@asfgit asfgit closed this in ba46bbe Jul 27, 2014
xiliu82 pushed a commit to xiliu82/spark that referenced this pull request Sep 4, 2014
Similar to SPARK-1034, the problem was that Py4J didn’t cope well with the fake ClassTags used in the Java API.  It doesn’t look like there’s any reason why PythonRDD needs to take a ClassTag, since it just ignores the type of the previous RDD, so I removed the type parameter and we no longer pass ClassTags from Python.

Author: Josh Rosen <joshrosen@apache.org>

Closes apache#1605 from JoshRosen/spark-2601 and squashes the following commits:

b68e118 [Josh Rosen] Fix Py4J error when transforming pickleFiles [SPARK-2601]
MaxGekk added a commit to MaxGekk/spark that referenced this pull request Nov 22, 2026
…ictMath (apache#1609)

<!-- title: [VARKA-345] Emit fdlibm's exp as IR nodes in the kernel, exact to StrictMath -->

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

`exp` as the first function written on the `PORT` frame (apache#1607): `VarkaMathPort.exp` expands fdlibm 5.3's `e_exp.c` into ordinary IR nodes (lane arithmetic, compares, blends, the long bit views) inside the kernel's one method. No call is made at run time. Every branch of the C is computed in every lane and the lanes are blended in the C's order of precedence, so no lane is finished by a per-lane `StrictMath.exp`. Three planted faults of the sequence (a dropped correction term, a constant one ulp off, a moved threshold) are a package-private `Fault` argument, so the production expansion has none.

Three supporting changes:

- `D2I` (`DOUBLE` to `INT`, Java's `(int)`) passes `VarkaKernelPlan`'s conversion refusal and is lowered by `convertShape` on every host; `exp` takes its integer `k` through it. No compiler arm builds it for a SQL cast, so no SQL answer moves.
- The auto chain cap of apache#1605 (`VarkaEmitBudget.chainDepthCap`) gets a third arm, `PORT_MAX_CHAIN_DEPTH` = 64, for a tree that holds a `ReinterpretLane`, the node only the ports build. Every other tree keeps its cap (64 for an int-lane tree, 16 else), and an explicit `maxChainDepth` still wins. The emitter's analysis and the compiler's `fitsBudgets` both read `chainDepthCap`, so they agree.
- The test oracle is `io.github.vecbricks:vfdlibm:0.1.0` from Maven Central, a test-scope dependency of `sql/catalyst`. `javap` shows `VFdlibm.exp(DoubleVector[, VectorMask])` public, which is all the suite calls. No source copy, manifest or sync script.

### Why are the changes needed?

The exact default of the math family has to match `StrictMath` bit for bit, and a per-lane call is the only form that does today; it costs the scalar call and keeps the surrounding vector code but not the function. Writing the function's sequence as IR makes it vectorised, and `exp` is the template the other ports follow.

Why the result is bit-identical (the full argument is in `VARKA-345.md` 10.2): `StrictMath.exp` is fdlibm's `e_exp.c`, each step one correctly rounded IEEE double operation, and a vector add, subtract, multiply or divide on a double lane is that same operation, so a lane that follows the C's path gets the C's bits. The only difference is control flow. The port runs the far reduction for every lane with `k = 0` where the C does not reduce, which returns the C's inputs unchanged, tests `|x|`'s bits against constant words as the C tests its high word, and applies the blends in the C's order, so the last blend a lane satisfies is the C's `return`.

The cap is the real reason for the second change. `exp` is 36 levels deep (its polynomial alone ten) over the double, long and int lanes, so the auto cap declined it at 16 ("chain deeper than MAX_CHAIN_DEPTH=16"). Measured: layering `x + 1.0` over the port, the compiler's mirror admits exactly 28 more levels, a stop at 64, and the 65th is declined by the emitter with "MAX_CHAIN_DEPTH=64". At that depth the largest emitted method is 2070 bytes of the 8000-byte budget, so the cap, not the byte budget, is the stop and it is far from the method limit. The alternatives were a higher shared cap (it would change which fuzz draws and compiler folds fit) or a depth that counts only arithmetic (a second notion of depth beside `height`); a branch of the auto value touches only trees that already hold a port.

At `methodByteBudget` 0 (an option matrix arm) the op cap `MAX_FUSED_NODES` (64) applies and `exp` holds 68 ops, so the port is declined there, cleanly, and the row engine runs. A test holds that.

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

No. No compiler arm builds a port yet, so no SQL shape fuses with one and no answer moves.

### How was this patch tested?

`VarkaMathPortSuite` (its own JVM), against `StrictMath.exp` and `VFdlibm.exp` by raw bits, NaN payloads included:

- the sampled differential over four draws, 2^24 inputs;
- the fixed vectors (each `e_exp.c` threshold in both signs with 64 neighbours each way, the subnormal scale-back's start, special values, eight NaN patterns, 4136 inputs) at 2, 4 and 8 lanes over four null patterns and four lengths;
- the reference evaluator over the port's tree; `D2I` against Java's `(int)` at three widths; each planted fault caught; the constants' words;
- the depth and the stop at 64 above, the explicit cap, and the decline at `methodByteBudget` 0.

Also `VarkaEmitterFloatingCastSuite` (D2I admitted) and the option, budget, rounding, reproduction, math-contract and compiler suites around the cap. Scalastyle, scalafmt, errorprone and `dev/varka_push_check.py` are clean.

`/code-review high` (one round): 1 important finding, fixed: the port suite's kernels ran under the option matrix's `maxChainDepth` 16 or 32 and `methodByteBudget` 0, which decline `exp` by design, so the suite now builds its kernels with those two budgets put back (the decline itself has its own tests). Also fixed: errorprone's float-literal warnings on the constants, comments that still named the old cap, a decline test that did not check the cap's name. Left as nits: the port cap keys on `ReinterpretLane` (documented, only the ports build it), and a bare D2I root is untested, only D2I under a widening to long.

No issue was filed against `vfdlibm`: every `exp` lane was bit-identical to `StrictMath.exp` and nothing was measured against its node sequence.

The port's speed against the per-lane call is not measured here; the per-lane form is row 356's and the runners are dispatched separately.

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

Generated-by: Claude Code (Claude Sonnet 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