-
Notifications
You must be signed in to change notification settings - Fork 29k
[SPARK-32907][ML][PYTHON] adaptively blockify instances - LinearSVC #30009
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
Closed
zhengruifeng
wants to merge
11
commits into
apache:master
from
zhengruifeng:adaptively_blockify_linear_svc_II
Closed
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
25f2688
resend
zhengruifeng a862d48
address comments
zhengruifeng 9f96739
directly gen new Iter
zhengruifeng 7ceb5dd
directly gen new Iter
zhengruifeng 2493562
update blockify strategy
zhengruifeng 5daa49a
address comments
zhengruifeng 823563c
try to fix 2.13
zhengruifeng 6d3000b
try to fix scala 2.13
zhengruifeng 88004a4
use 1.0 as the default value for gemv
zhengruifeng ecf3dfe
update
WeichenXu123 a69ca83
rename param
zhengruifeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,4 +74,58 @@ class InstanceSuite extends SparkFunSuite{ | |
| } | ||
| } | ||
|
|
||
| test("InstanceBlock: blokify with max memory usage") { | ||
| val instance1 = Instance(19.0, 2.0, Vectors.dense(1.0, 7.0)) | ||
| val instance2 = Instance(17.0, 1.0, Vectors.dense(0.0, 5.0).toSparse) | ||
| val instances = Seq(instance1, instance2) | ||
|
|
||
| val blocks = InstanceBlock | ||
| .blokifyWithMaxMemUsage(Iterator.apply(instance1, instance2), 128).toArray | ||
| require(blocks.length == 1) | ||
| val block = blocks.head | ||
| assert(block.size === 2) | ||
| assert(block.numFeatures === 2) | ||
| block.instanceIterator.zipWithIndex.foreach { | ||
| case (instance, i) => | ||
| assert(instance.label === instances(i).label) | ||
| assert(instance.weight === instances(i).weight) | ||
| assert(instance.features.toArray === instances(i).features.toArray) | ||
| } | ||
| Seq(0, 1).foreach { i => | ||
| val nzIter = block.getNonZeroIter(i) | ||
| val vec = Vectors.sparse(2, nzIter.toSeq) | ||
| assert(vec.toArray === instances(i).features.toArray) | ||
| } | ||
|
|
||
| // instances larger than maxMemUsage | ||
| val denseInstance = Instance(-1.0, 2.0, Vectors.dense(Array.fill(1000)(1.0))) | ||
| InstanceBlock.blokifyWithMaxMemUsage(Iterator.single(denseInstance), 64).size | ||
| InstanceBlock.blokifyWithMaxMemUsage(Iterator.fill(10)(denseInstance), 64).size | ||
|
|
||
| // different numFeatures | ||
| intercept[IllegalArgumentException] { | ||
| InstanceBlock.blokifyWithMaxMemUsage(Iterator.apply(instance1, denseInstance), 64).size | ||
| } | ||
|
|
||
| // nnz = 10 | ||
| val sparseInstance = Instance(-2.0, 3.0, | ||
| Vectors.sparse(1000, Array.range(0, 1000, 100), Array.fill(10)(0.1))) | ||
|
|
||
| // normally, memory usage of a block does not exceed maxMemUsage too much | ||
| val maxMemUsage = 1 << 18 | ||
| val mixedIter = Iterator.fill(100)(denseInstance) ++ | ||
| Iterator.fill(1000)(sparseInstance) ++ | ||
| Iterator.fill(10)(denseInstance) ++ | ||
| Iterator.fill(10)(sparseInstance) ++ | ||
| Iterator.fill(100)(denseInstance) ++ | ||
| Iterator.fill(100)(sparseInstance) | ||
| InstanceBlock.blokifyWithMaxMemUsage(mixedIter, maxMemUsage) | ||
| .foreach { block => | ||
| val doubleBytes = java.lang.Double.BYTES | ||
| val arrayHeader = 12L | ||
| val blockMemUsage = block.matrix.getSizeInBytes + | ||
| (block.labels.length + block.weights.length) * doubleBytes + arrayHeader * 2 | ||
| require(blockMemUsage < maxMemUsage * 1.05) | ||
| } | ||
| } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add test:
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.