Skip to content

Commit 2f39624

Browse files
hekaishengqinxuye
authored andcommitted
Fix executor's behavior of deletes & bump version (#249)
1 parent bfc41a2 commit 2f39624

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

mars/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717
import sys
1818

19-
version_info = (0, 2, 0, 'a1')
19+
version_info = (0, 2, 0, 'a2')
2020
_num_index = max(idx if isinstance(v, int) else 0
2121
for idx, v in enumerate(version_info))
2222
__version__ = '.'.join(map(str, version_info[:_num_index + 1])) + \

mars/executor.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ def _execute_operand(self, op):
219219
results = self._chunk_results
220220
ref_counts = self._chunk_key_ref_counts
221221
op_keys = self._executed_op_keys
222+
executed_chunk_keys = set()
223+
deleted_chunk_keys = set()
222224
try:
223225
ops = list(self._op_key_to_ops[op.key])
224226
if not self._mock:
@@ -227,11 +229,15 @@ def _execute_operand(self, op):
227229
# so we pass the first operand's first output to Executor.handle
228230
first_op = ops[0]
229231
Executor.handle(first_op.outputs[0], results)
232+
executed_chunk_keys.update([c.key for c in first_op.outputs])
230233
op_keys.add(first_op.key)
231234
# handle other operands
232235
for rest_op in ops[1:]:
233236
for op_output, rest_op_output in zip(first_op.outputs, rest_op.outputs):
234-
results[rest_op_output.key] = results[op_output.key]
237+
# if the op's outputs have been stored,
238+
# other same key ops' results will be the same
239+
if rest_op_output.key not in executed_chunk_keys:
240+
results[rest_op_output.key] = results[op_output.key]
235241
else:
236242
sparse_percent = self._sparse_mock_percent if op.sparse else 1.0
237243
for output in op.outputs:
@@ -245,7 +251,10 @@ def _execute_operand(self, op):
245251
# in case that operand has multiple outputs
246252
# and some of the output not in result keys, delete them
247253
if ref_counts.get(output.key) == 0:
248-
del results[output.key]
254+
# if the result has been deleted, it should be skipped
255+
if output.key not in deleted_chunk_keys:
256+
deleted_chunk_keys.add(output.key)
257+
del results[output.key]
249258

250259
# clean the predecessors' results if ref counts equals 0
251260
for pred_chunk in self._graph.iter_predecessors(output):

mars/tensor/execution/tests/test_linalg_execute.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,15 @@ def testSVDExecution(self):
112112
res = self.executor.execute_tensor(t, concat=True)[0]
113113
self.assertTrue(np.allclose(res, data))
114114

115+
# test for matrix of ones
116+
data = np.ones((20, 10))
117+
118+
a = tensor(data, chunk_size=10)
119+
s = svd(a)[1]
120+
res = self.executor.execute_tensor(s, concat=True)[0]
121+
expected = np.linalg.svd(a)[1]
122+
np.testing.assert_array_almost_equal(res, expected)
123+
115124
def testCholeskyExecution(self):
116125
data = np.array([[1, -2j], [2j, 5]])
117126

0 commit comments

Comments
 (0)