Skip to content

[SPARK-2907] [MLlib] Use mutable.HashMap to represent model in Word2Vec - #1871

Closed
Ishiihara wants to merge 4 commits into
apache:masterfrom
Ishiihara:Word2Vec-improve
Closed

Ishiihara wants to merge 4 commits into
apache:masterfrom
Ishiihara:Word2Vec-improve

Conversation

@Ishiihara

Copy link
Copy Markdown
Contributor

@mengxr Please review the code.
Change list:

  1. Used mutable.HashMap to represent syn0Global and syn1Global to reduce shuffle size.
  2. Introduced local vocabulary to perform more precise learning rate update.
  3. Replace layer1Size with vectorSize to correctly set vector size. Previously, layer1Size was always the default value of vectorSize.
  4. Set alpha to be the correct startingAlpha.

For 100 partitions, using mutable.HashMap reduces shuffle size from 8.1G to 4G.

@SparkQA

SparkQA commented Aug 10, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Aug 10, 2014

Copy link
Copy Markdown

QA results for PR 1871:
- 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/18267/consoleFull

@SparkQA

SparkQA commented Aug 10, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Aug 10, 2014

Copy link
Copy Markdown

QA results for PR 1871:
- 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/18272/consoleFull

@SparkQA

SparkQA commented Aug 10, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Aug 10, 2014

Copy link
Copy Markdown

QA results for PR 1871:
- This patch FAILED 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/18277/consoleFull

@SparkQA

SparkQA commented Aug 10, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Aug 10, 2014

Copy link
Copy Markdown

QA results for PR 1871:
- 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/18279/consoleFull

@mengxr

mengxr commented Aug 10, 2014

Copy link
Copy Markdown
Contributor

@Ishiihara Did you compare the speed?

@Ishiihara

Copy link
Copy Markdown
Contributor Author

@mengxr It is about 1-2 minutes slower with vector size = 100 for different number of partitions.

@Ishiihara

Copy link
Copy Markdown
Contributor Author

@mengxr Some benchmark result
Environment: OSX 10.9, 8G memory, 2.5G i5 CPU, 4 threads
startingAlpha = 0.0025
vecterSize = 100
Driver memory 2g

syn0 and syn1 as mutable.HashMap

numPartition numIteration time total shuffle write
1 1 9m30.828s 42.6MB
4 1 5m47.192s 43.6MB
10 1 6m12.333s 490.4MB
100 1 6m24.663s 2.0G

syn0 and syn1 as big Array

numPartition numIteration time total shuffle write
1 1 9m1.675s 42.6MB
4 1 5m3.130s 43.6MB
10 1 5m24.283s 580MB
100 1 5m52.446s 4.1G

@mateiz

mateiz commented Aug 10, 2014

Copy link
Copy Markdown
Contributor

Just FYI, mutable.HashMap can be pretty inefficient in space usage, compared e.g. to java.util.HashMap or to Spark's AppendOnlyMap. In this case it will depend on how many keys there are and how big the arrays of floats are (if that's the bulk of the data, it won't matter).

@mateiz

mateiz commented Aug 10, 2014

Copy link
Copy Markdown
Contributor

Even better might be Spark's PrimitiveKeyOpenHashMap here. Again, if there are lots of keys.

@SparkQA

SparkQA commented Aug 11, 2014

Copy link
Copy Markdown

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

@SparkQA

SparkQA commented Aug 11, 2014

Copy link
Copy Markdown

QA results for PR 1871:
- 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/18335/consoleFull

@mateiz

mateiz commented Aug 12, 2014

Copy link
Copy Markdown
Contributor

Just wondering, any noticeable perf difference with this change?

@Ishiihara

Copy link
Copy Markdown
Contributor Author

@mateiz The performance of PrimitiveKeyOpenHashMap is on par with mutable.HashMap. For one partition case, the PrimitiveKeyOpenHashMap is slightly faster than using big array.

@Ishiihara Ishiihara closed this Aug 18, 2014
@mateiz

mateiz commented Aug 19, 2014

Copy link
Copy Markdown
Contributor

@Ishiihara why did you close this, has this been fixed elsewhere now?

@mengxr

mengxr commented Aug 19, 2014

Copy link
Copy Markdown
Contributor

We merged #1932 instead.

@Ishiihara

Copy link
Copy Markdown
Contributor Author

@mateiz This is taken care of by #1932 and is already merged in master and 1.1. In that PR, the model output by each partition is using PrimitiveKeyOpenHashMap. As the implementation is different, we started another PR.

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.

4 participants