This is an automated email from the ASF dual-hosted git repository.
baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push:
new d048d35869 [SYSTEMDS-3380] Federated Codegen Test Not Running
d048d35869 is described below
commit d048d35869dfd6eaae9edbc35e43163a40642ce6
Author: baunsgaard <[email protected]>
AuthorDate: Thu Apr 21 14:36:46 2022 +0200
[SYSTEMDS-3380] Federated Codegen Test Not Running
The federated codegen tests were not enabled on github, and they
were not running when executed. This commit fixes both.
The issue in executing the federated codegen tests was two bugs.
1. Trying to get lineage items that did not exist, this is now dependent
on lineage being enabled.
2. Unary instruction parsing in federated that did not handle 4 input
arguments.
Closes #1595
---
.github/workflows/functionsTests.yml | 1 +
scripts/builtin/als.dml | 8 +++---
scripts/builtin/alsCG.dml | 8 +++---
scripts/builtin/alsDS.dml | 8 +++---
.../instructions/fed/SpoofFEDInstruction.java | 16 ++++++------
.../instructions/fed/UnaryFEDInstruction.java | 21 +++++++---------
src/test/java/org/apache/sysds/test/TestUtils.java | 1 +
.../federated/algorithms/FederatedAlsCGTest.java | 4 +--
.../codegen/FederatedRowwiseTmplTest.java | 29 ++++++++++++----------
9 files changed, 53 insertions(+), 43 deletions(-)
diff --git a/.github/workflows/functionsTests.yml
b/.github/workflows/functionsTests.yml
index b9ad9d76dd..344b821bbc 100644
--- a/.github/workflows/functionsTests.yml
+++ b/.github/workflows/functionsTests.yml
@@ -55,6 +55,7 @@ jobs:
"**.functions.binary.matrix_full_cellwise.**,**.functions.binary.matrix_full_other.**",
"**.functions.federated.algorithms.**,**.functions.federated.io.**,**.functions.federated.paramserv.**",
"**.functions.federated.primitives.**,**.functions.federated.transform.**",
+ "**.functions.federated.codegen.**",
"**.functions.codegenalg.partone.**",
"**.functions.builtin.part1.**",
"**.functions.builtin.part2.**",
diff --git a/scripts/builtin/als.dml b/scripts/builtin/als.dml
index 5fa18ff6da..c63323da6e 100644
--- a/scripts/builtin/als.dml
+++ b/scripts/builtin/als.dml
@@ -43,6 +43,8 @@
# thr Double 0.0001 Assuming check is set to TRUE, the
algorithm stops and convergence is declared
# if the decrease in loss in any two
consecutive iterations falls below this threshold;
# if check is FALSE thr is ignored
+# seed Integer 1324521 The seed to random parts of the algorithm
+# verbose Boolean TRUE If the algorithm should run verbosely
#
----------------------------------------------------------------------------------------------------------------------
#
# OUTPUT:
@@ -54,14 +56,14 @@
#
----------------------------------------------------------------------------------------------------------------------
m_als = function(Matrix[Double] X, Integer rank = 10, String regType = "L2",
Double reg = 0.000001,
- Integer maxi = 50, Boolean check = TRUE, Double thr = 0.0001, Boolean
verbose = TRUE)
+ Integer maxi = 50, Boolean check = TRUE, Double thr = 0.0001, Integer seed =
1342516, Boolean verbose = TRUE)
return (Matrix[Double] U, Matrix[Double] V)
{
N = 10000; # for large problems, use scalable alsCG
if( reg != "L2" | nrow(X) > N | ncol(X) > N )
[U, V] = alsCG(X=X, rank=rank, regType=regType, reg=reg,
- maxi=maxi, check=check, thr=thr, verbose=verbose);
+ maxi=maxi, check=check, thr=thr, seed = seed,
verbose=verbose);
else
[U, V] = alsDS(X=X, rank=rank, reg=reg, maxi=maxi,
- check=check, thr=thr, verbose=verbose);
+ check=check, thr=thr, seed =seed, verbose=verbose);
}
diff --git a/scripts/builtin/alsCG.dml b/scripts/builtin/alsCG.dml
index 2d0be0dd80..1a8697b4d8 100644
--- a/scripts/builtin/alsCG.dml
+++ b/scripts/builtin/alsCG.dml
@@ -43,6 +43,8 @@
# thr Double 0.0001 Assuming check is set to TRUE, the
algorithm stops and convergence is declared
# if the decrease in loss in any two
consecutive iterations falls below this threshold;
# if check is FALSE thr is ignored
+# seed Integer 1324521 The seed to random parts of the algorithm
+# verbose Boolean TRUE If the algorithm should run verbosely
#
----------------------------------------------------------------------------------------------------------------------
#
# OUTPUT:
@@ -54,7 +56,7 @@
#
----------------------------------------------------------------------------------------------------------------------
m_alsCG = function(Matrix[Double] X, Integer rank = 10, String regType = "L2",
Double reg = 0.000001, Integer maxi = 50,
- Boolean check = TRUE, Double thr = 0.0001, Boolean verbose = TRUE)
+ Boolean check = TRUE, Double thr = 0.0001, Integer seed = 132521, Boolean
verbose = TRUE)
return (Matrix[Double] U, Matrix[Double] V)
{
r = rank;
@@ -65,8 +67,8 @@ m_alsCG = function(Matrix[Double] X, Integer rank = 10,
String regType = "L2", D
n = ncol (X);
# initializing factor matrices
- U = rand (rows = m, cols = r, min = -0.5, max = 0.5); # mxr
- V = rand (rows = n, cols = r, min = -0.5, max = 0.5); # nxr
+ U = rand (rows = m, cols = r, min = -0.5, max = 0.5, seed = seed); # mxr
+ V = rand (rows = n, cols = r, min = -0.5, max = 0.5, seed = seed+1); # nxr
W = (X != 0);
diff --git a/scripts/builtin/alsDS.dml b/scripts/builtin/alsDS.dml
index 4f7a5cffe6..2a35d4fa52 100644
--- a/scripts/builtin/alsDS.dml
+++ b/scripts/builtin/alsDS.dml
@@ -36,6 +36,8 @@
# thr Double 0.0001 Assuming check is set to TRUE, the
algorithm stops and convergence is declared
# if the decrease in loss in any two
consecutive iterations falls below this threshold;
# if check is FALSE thr is ignored
+# seed Integer 1324521 The seed to random parts of the algorithm
+# verbose Boolean TRUE If the algorithm should run verbosely
#
----------------------------------------------------------------------------------------------------------------------
#
# OUTPUT:
@@ -47,7 +49,7 @@
#
----------------------------------------------------------------------------------------------------------------------
m_alsDS = function(Matrix[Double] X, Integer rank = 10, Double reg = 0.000001,
- Integer maxi = 50, Boolean check = FALSE, Double thr = 0.0001, Boolean
verbose = TRUE)
+ Integer maxi = 50, Boolean check = FALSE, Double thr = 0.0001, Integer seed
= 321452, Boolean verbose = TRUE)
return (Matrix[Double] U, Matrix[Double] V)
{
r = rank;
@@ -84,8 +86,8 @@ m_alsDS = function(Matrix[Double] X, Integer rank = 10,
Double reg = 0.000001,
n = ncol (X);
# initializing factor matrices
- U = rand (rows = m, cols = r, min = -0.5, max = 0.5);
- V = rand (rows = n, cols = r, min = -0.5, max = 0.5);
+ U = rand (rows = m, cols = r, min = -0.5, max = 0.5, seed=seed);
+ V = rand (rows = n, cols = r, min = -0.5, max = 0.5, seed=seed+1);
# initializing transformed matrices
Xt = t(X);
diff --git
a/src/main/java/org/apache/sysds/runtime/instructions/fed/SpoofFEDInstruction.java
b/src/main/java/org/apache/sysds/runtime/instructions/fed/SpoofFEDInstruction.java
index 0edad44621..6bd5aeb985 100644
---
a/src/main/java/org/apache/sysds/runtime/instructions/fed/SpoofFEDInstruction.java
+++
b/src/main/java/org/apache/sysds/runtime/instructions/fed/SpoofFEDInstruction.java
@@ -19,9 +19,15 @@
package org.apache.sysds.runtime.instructions.fed;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.concurrent.Future;
+
import org.apache.commons.lang3.ArrayUtils;
+import org.apache.sysds.api.DMLScript;
import org.apache.sysds.hops.fedplanner.FTypes.AlignType;
import org.apache.sysds.hops.fedplanner.FTypes.FType;
+import org.apache.sysds.runtime.DMLRuntimeException;
import org.apache.sysds.runtime.codegen.CodegenUtils;
import org.apache.sysds.runtime.codegen.SpoofCellwise;
import org.apache.sysds.runtime.codegen.SpoofCellwise.AggOp;
@@ -40,18 +46,13 @@ import
org.apache.sysds.runtime.controlprogram.federated.FederatedResponse;
import org.apache.sysds.runtime.controlprogram.federated.FederationMap;
import org.apache.sysds.runtime.controlprogram.federated.FederationUtils;
import org.apache.sysds.runtime.controlprogram.federated.MatrixLineagePair;
-import org.apache.sysds.runtime.DMLRuntimeException;
+import org.apache.sysds.runtime.instructions.InstructionUtils;
import org.apache.sysds.runtime.instructions.cp.CPOperand;
import org.apache.sysds.runtime.instructions.cp.Data;
import org.apache.sysds.runtime.instructions.cp.ScalarObject;
-import org.apache.sysds.runtime.instructions.InstructionUtils;
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
import org.apache.sysds.runtime.matrix.operators.AggregateUnaryOperator;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.concurrent.Future;
-
public class SpoofFEDInstruction extends FEDInstruction
{
private final SpoofOperator _op;
@@ -118,7 +119,8 @@ public class SpoofFEDInstruction extends FEDInstruction
for(CPOperand cpo : _inputs) {
Data tmpData = ec.getVariable(cpo);
if(tmpData instanceof MatrixObject) {
- MatrixLineagePair mo =
MatrixLineagePair.of((MatrixObject) tmpData, ec.getLineageItem(cpo));
+ MatrixLineagePair mo =
MatrixLineagePair.of((MatrixObject) tmpData,
+ DMLScript.LINEAGE ?
ec.getLineageItem(cpo) : null);
if(mo.isFederatedExcept(FType.BROADCAST)) {
frIds[index++] =
mo.getFedMapping().getID();
}
diff --git
a/src/main/java/org/apache/sysds/runtime/instructions/fed/UnaryFEDInstruction.java
b/src/main/java/org/apache/sysds/runtime/instructions/fed/UnaryFEDInstruction.java
index dea0acfc4c..1c66e77768 100644
---
a/src/main/java/org/apache/sysds/runtime/instructions/fed/UnaryFEDInstruction.java
+++
b/src/main/java/org/apache/sysds/runtime/instructions/fed/UnaryFEDInstruction.java
@@ -57,11 +57,16 @@ public abstract class UnaryFEDInstruction extends
ComputationFEDInstruction {
static String parseUnaryInstruction(String instr, CPOperand in,
CPOperand out) {
//TODO: simplify once all fed instructions have consistent flags
- int num = InstructionUtils.checkNumFields(instr, 2, 3);
+ int num = InstructionUtils.checkNumFields(instr, 2, 3, 4);
if(num == 2)
- return parse(instr, in, null, null, out);
- else
- return parseWithFedOutFlag(instr, in, out);
+ return parse(instr, in, null, null, out);
+ else {
+ String[] parts =
InstructionUtils.getInstructionPartsWithValueType(instr);
+ String opcode = parts[0];
+ in.split(parts[1]);
+ out.split(parts[2]);
+ return opcode;
+ }
}
static String parseUnaryInstruction(String instr, CPOperand in1,
CPOperand in2, CPOperand out) {
@@ -103,14 +108,6 @@ public abstract class UnaryFEDInstruction extends
ComputationFEDInstruction {
return opcode;
}
- private static String parseWithFedOutFlag(String instr, CPOperand in1,
CPOperand out) {
- String[] parts =
InstructionUtils.getInstructionPartsWithValueType(instr);
- String opcode = parts[0];
- in1.split(parts[1]);
- out.split(parts[parts.length - 2]);
- return opcode;
- }
-
/**
* Parse and return federated output flag from given instr string at
given position.
* If the position given is greater than the length of the instruction,
FederatedOutput.NONE is returned.
diff --git a/src/test/java/org/apache/sysds/test/TestUtils.java
b/src/test/java/org/apache/sysds/test/TestUtils.java
index 227c1630a5..64785c4ed8 100644
--- a/src/test/java/org/apache/sysds/test/TestUtils.java
+++ b/src/test/java/org/apache/sysds/test/TestUtils.java
@@ -1839,6 +1839,7 @@ public class TestUtils
public static double[][] generateTestMatrix(int rows, int cols, double
min, double max, double sparsity, long seed) {
double[][] matrix = new double[rows][cols];
Random random = (seed == -1) ? TestUtils.random : new
Random(seed);
+
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
if (random.nextDouble() > sparsity)
diff --git
a/src/test/java/org/apache/sysds/test/functions/federated/algorithms/FederatedAlsCGTest.java
b/src/test/java/org/apache/sysds/test/functions/federated/algorithms/FederatedAlsCGTest.java
index 325d36d41f..5e880166af 100644
---
a/src/test/java/org/apache/sysds/test/functions/federated/algorithms/FederatedAlsCGTest.java
+++
b/src/test/java/org/apache/sysds/test/functions/federated/algorithms/FederatedAlsCGTest.java
@@ -45,7 +45,7 @@ public class FederatedAlsCGTest extends AutomatedTestBase
private final static String TEST_CLASS_DIR = TEST_DIR +
FederatedAlsCGTest.class.getSimpleName() + "/";
private final static String OUTPUT_NAME = "Z";
- private final static double TOLERANCE = 0.01;
+ private final static double TOLERANCE = 0.06;
private final static int BLOCKSIZE = 1024;
@Parameterized.Parameter()
@@ -149,7 +149,7 @@ public class FederatedAlsCGTest extends AutomatedTestBase
runTest(true, false, null, -1);
// compare the results via files
- HashMap<CellIndex, Double> refResults =
readDMLMatrixFromExpectedDir(OUTPUT_NAME);
+ HashMap<CellIndex, Double> refResults =
readDMLMatrixFromExpectedDir(OUTPUT_NAME);
HashMap<CellIndex, Double> fedResults =
readDMLMatrixFromOutputDir(OUTPUT_NAME);
TestUtils.compareMatrices(fedResults, refResults, TOLERANCE,
"Fed", "Ref");
diff --git
a/src/test/java/org/apache/sysds/test/functions/federated/codegen/FederatedRowwiseTmplTest.java
b/src/test/java/org/apache/sysds/test/functions/federated/codegen/FederatedRowwiseTmplTest.java
index 89475d85d9..5508af3dd9 100644
---
a/src/test/java/org/apache/sysds/test/functions/federated/codegen/FederatedRowwiseTmplTest.java
+++
b/src/test/java/org/apache/sysds/test/functions/federated/codegen/FederatedRowwiseTmplTest.java
@@ -20,6 +20,10 @@
package org.apache.sysds.test.functions.federated.codegen;
import java.io.File;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+
import org.apache.sysds.common.Types.ExecMode;
import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex;
import org.apache.sysds.runtime.meta.MatrixCharacteristics;
@@ -30,18 +34,14 @@ import org.apache.sysds.test.TestUtils;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Ignore;
+import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
-import org.junit.Test;
-
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
@RunWith(value = Parameterized.class)
@net.jcip.annotations.NotThreadSafe
-public class FederatedRowwiseTmplTest extends AutomatedTestBase
-{
+public class FederatedRowwiseTmplTest extends AutomatedTestBase {
+ // private static final Log LOG =
LogFactory.getLog(FederatedRowwiseTmplTest.class.getName());
private final static String TEST_NAME = "FederatedRowwiseTmplTest";
private final static String TEST_DIR = "functions/federated/codegen/";
@@ -50,7 +50,7 @@ public class FederatedRowwiseTmplTest extends
AutomatedTestBase
private final static String TEST_CONF = "SystemDS-config-codegen.xml";
private final static String OUTPUT_NAME = "Z";
- private final static double TOLERANCE = 1e-13;
+ private final static double TOLERANCE = 1e-9;
private final static int BLOCKSIZE = 1024;
@Parameterized.Parameter()
@@ -137,8 +137,8 @@ public class FederatedRowwiseTmplTest extends
AutomatedTestBase
// generate dataset
// matrix handled by two federated workers
- double[][] X1 = getRandomMatrix(fed_rows, fed_cols, 0, 1, 0.1,
3);
- double[][] X2 = getRandomMatrix(fed_rows, fed_cols, 0, 1, 0.1,
11);
+ double[][] X1 = TestUtils.generateTestMatrix(fed_rows,
fed_cols, 1, 10, 1.0, 3);
+ double[][] X2 = TestUtils.generateTestMatrix(fed_rows,
fed_cols, 1, 10, 1.0, 11);
writeInputMatrixWithMTD("X1", X1, false, new
MatrixCharacteristics(fed_rows, fed_cols, BLOCKSIZE, fed_rows * fed_cols));
writeInputMatrixWithMTD("X2", X2, false, new
MatrixCharacteristics(fed_rows, fed_cols, BLOCKSIZE, fed_rows * fed_cols));
@@ -159,7 +159,7 @@ public class FederatedRowwiseTmplTest extends
AutomatedTestBase
"in_rp=" +
Boolean.toString(row_partitioned).toUpperCase(),
"in_test_num=" + Integer.toString(test_num),
"out_Z=" + expected(OUTPUT_NAME)};
- runTest(true, false, null, -1);
+ runTest(null);
// Run actual dml script with federated matrix
fullDMLScriptName = HOME + TEST_NAME + ".dml";
@@ -170,11 +170,14 @@ public class FederatedRowwiseTmplTest extends
AutomatedTestBase
"in_test_num=" + Integer.toString(test_num),
"rows=" + rows, "cols=" + cols,
"out_Z=" + output(OUTPUT_NAME)};
- runTest(true, false, null, -1);
+ runTest(null);
// compare the results via files
- HashMap<CellIndex, Double> refResults =
readDMLMatrixFromExpectedDir(OUTPUT_NAME);
+ HashMap<CellIndex, Double> refResults =
readDMLMatrixFromExpectedDir(OUTPUT_NAME);
HashMap<CellIndex, Double> fedResults =
readDMLMatrixFromOutputDir(OUTPUT_NAME);
+
+ // LOG.error(refResults);
+ // LOG.error(fedResults);
TestUtils.compareMatrices(fedResults, refResults, TOLERANCE,
"Fed", "Ref");
TestUtils.shutdownThreads(thread1, thread2);