-
Notifications
You must be signed in to change notification settings - Fork 543
[SYSTEMDS-3951] MM Chain Optimization w/ Basic Average Estimator #2525
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
Open
ywcb00
wants to merge
5
commits into
apache:main
Choose a base branch
from
ywcb00:fix/hops/rewrite/sparse
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+101
−69
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e3c8065
chore(main/hops/rewrite/RewriteMatrixMultChainOptimizationSparse.java…
ywcb00 a09a8d4
feat(main/hops/estim/MMNode.java): add constructor to create a MMNode…
ywcb00 74c43bb
fix(test/functions/rewrite/RewriteMatrixMultChainOptSparseTest.java):…
ywcb00 ad8e2bb
fix(RewriteMatrixMultChainOptimizationSparse.java): replace the mnc e…
ywcb00 08d7eac
fix(test/functions/rewrite/RewriteMatrixMultChainOptSparseTest.java):…
ywcb00 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,33 +19,75 @@ | |
|
|
||
| package org.apache.sysds.test.functions.rewrite; | ||
|
|
||
| import org.apache.log4j.Level; | ||
| import org.apache.log4j.Logger; | ||
| import org.apache.log4j.spi.LoggingEvent; | ||
| import org.apache.sysds.common.Opcodes; | ||
| import org.apache.sysds.hops.OptimizerUtils; | ||
| import org.apache.sysds.hops.recompile.Recompiler; | ||
| import org.apache.sysds.runtime.matrix.data.MatrixValue; | ||
| import org.apache.sysds.test.AutomatedTestBase; | ||
| import org.apache.sysds.test.TestConfiguration; | ||
| import org.apache.sysds.test.TestUtils; | ||
| import org.apache.sysds.test.LoggingUtils; | ||
| import org.apache.sysds.test.LoggingUtils.TestAppender; | ||
|
|
||
| import org.junit.Assert; | ||
| import org.junit.runners.Parameterized; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.stream.DoubleStream; | ||
| import java.util.stream.Stream; | ||
|
|
||
| @RunWith(value = Parameterized.class) | ||
| @net.jcip.annotations.NotThreadSafe | ||
| public class RewriteMatrixMultChainOptSparseTest extends AutomatedTestBase { | ||
|
|
||
| private static final String TEST_NAME = "RewriteMatrixMultChainOpSparse"; | ||
| private static final String TEST_DIR = "functions/rewrite/"; | ||
| private static final String TEST_CLASS_DIR = | ||
| TEST_DIR + RewriteMatrixMultChainOptSparseTest.class.getSimpleName() + "/"; | ||
| private static final String PACKAGE = "org.apache.sysds.hops.rewrite.HopRewriteRule"; | ||
| private static Level _oldLevel; | ||
|
|
||
| @Parameterized.Parameter(0) | ||
| public int rows; | ||
|
|
||
| @Parameterized.Parameter(1) | ||
| public int cols; | ||
|
|
||
| private static final int rows = 1000; | ||
| private static final int cols = 300; | ||
| private static final double eps = Math.pow(10, -10); | ||
| @Parameterized.Parameter(2) | ||
| public double[] sparsities; | ||
|
|
||
| @Parameterized.Parameter(3) | ||
| public double eps; | ||
|
|
||
| @Parameterized.Parameters | ||
| public static Collection<Object[]> data() { | ||
| return Arrays.asList(new Object[][] { | ||
| // {rows, cols, sparsities, eps}, | ||
| {1000, 300, new double[]{0.10d, 0.10d}, Math.pow(10, -10)}, | ||
| // {2, 300, new double[]{0.005, 1}, Math.pow(10, -10)}, | ||
| }); | ||
| } | ||
|
|
||
| @Override | ||
| public void setUp() { | ||
| TestUtils.clearAssertionInformation(); | ||
| addTestConfiguration(TEST_NAME, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[] {"R"})); | ||
| _oldLevel = Logger.getLogger(PACKAGE).getLevel(); | ||
| Logger.getLogger(PACKAGE).setLevel(Level.TRACE); | ||
| } | ||
|
|
||
| @Override | ||
| public void tearDown() { | ||
| super.tearDown(); | ||
| Logger.getLogger(PACKAGE).setLevel(_oldLevel); | ||
| } | ||
|
|
||
| @Test | ||
|
|
@@ -74,13 +116,19 @@ private void testRewriteMatrixMultChainOpSparse(boolean rewrites) { | |
|
|
||
| OptimizerUtils.ALLOW_ADVANCED_MMCHAIN_REWRITES = rewrites; | ||
| OptimizerUtils.ALLOW_SUM_PRODUCT_REWRITES = rewrites; | ||
| double[][] X = getRandomMatrix(rows, cols, -1, 1, 0.10d, 7); | ||
| double[][] Y = getRandomMatrix(cols, 1, -1, 1, 0.10d, 3); | ||
| writeInputMatrixWithMTD("X", X, true); | ||
| writeInputMatrixWithMTD("Y", Y, true); | ||
| double[][] X = getRandomMatrix(rows, cols, -1, 1, sparsities[0], 7); | ||
| double[][] Y = getRandomMatrix(cols, 1, -1, 1, sparsities[1], 3); | ||
| long X_nnz = Stream.of(X).mapToLong(row -> DoubleStream.of(row).filter(val -> val != 0).count()).sum(); | ||
| long Y_nnz = Stream.of(Y).mapToLong(row -> DoubleStream.of(row).filter(val -> val != 0).count()).sum(); | ||
| writeInputMatrixWithMTD("X", X, X_nnz, true); | ||
| writeInputMatrixWithMTD("Y", Y, Y_nnz, true); | ||
|
|
||
|
|
||
| //execute tests | ||
| TestAppender appender = LoggingUtils.overwrite(); // capture log output | ||
| runTest(true, false, null, -1); | ||
| List<LoggingEvent> log_out = LoggingUtils.reinsert(appender); // revert the logger to print to stdout | ||
|
|
||
| runRScript(true); | ||
|
|
||
| //compare matrices | ||
|
|
@@ -89,12 +137,16 @@ private void testRewriteMatrixMultChainOpSparse(boolean rewrites) { | |
| TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R"); | ||
|
|
||
| if(rewrites) { | ||
| Assert.assertTrue(log_out.stream().anyMatch( | ||
| l -> l.getMessage().toString().contains("mmchainoptsparse"))); | ||
|
Comment on lines
+140
to
+141
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. It would be good to check more of the logging string. |
||
| Assert.assertTrue(heavyHittersContainsSubString(Opcodes.MMCHAIN.toString()) || | ||
| heavyHittersContainsSubString("sp_mapmmchain")); | ||
| } | ||
| else { | ||
| Assert.assertFalse(log_out.stream().anyMatch( | ||
| l -> l.getMessage().toString().contains("mmchainoptsparse"))); | ||
| Assert.assertFalse(heavyHittersContainsSubString(Opcodes.MMCHAIN.toString()) || | ||
| heavyHittersContainsSubString("sp_mapmmchain")); | ||
| heavyHittersContainsSubString("sp_mapmmchain")); | ||
| } | ||
| } | ||
| finally { | ||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you changed it to parameterized, enable the other test as well