Skip to content

Commit c94a01e

Browse files
authored
fix: fix odps table raise device error (#15)
1 parent 4190fb1 commit c94a01e

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

epl/cluster.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ def get_device(self, replica_idx, device_idx):
8080
"""
8181
return self._slice_devices[replica_idx][device_idx]
8282

83+
@property
84+
def slice_devices(self):
85+
"""Get device slices"""
86+
return self._slice_devices
87+
8388
def _device_in_local_worker(self, device):
8489
return common.get_task_index_from_device_str(device) == self._worker_index
8590

epl/ir/graph.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ def check_and_set_cloned_dataset_need_clone(self):
280280
self.clone_dataset_related_ops = True
281281
return
282282
constructor_num_device = dict()
283-
for devices in self._env.cluster.virtual_devices[0]:
283+
for devices in self._env.cluster.virtual_devices[0].slice_devices:
284284
for device in devices:
285285
constructor_task_index = \
286286
common.get_task_index_from_device_str(device)
@@ -536,8 +536,6 @@ def add_operation(self, primitive_op):
536536
# Specific dataset api op.
537537
if op.type in constant.DATASET_API_OPS:
538538
self._dataset_api_op.append(op)
539-
if op.type in constant.ODPS_TABLE_API_OPS:
540-
self.check_and_set_cloned_dataset_need_clone()
541539

542540
if current_model_phase == ModelPhase.ADD_FUNCTION:
543541
if not self._current_function_name:

epl/parallel/parallel.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ def do_parallelism(self):
212212
"""Tranform original graph to parallel graph."""
213213
if self._graph.is_constructor:
214214
with ops.name_scope(constant.PARALLEL_STRATEGY):
215+
for op in self._graph.dataset_api_op:
216+
if op.type in constant.ODPS_TABLE_API_OPS:
217+
self._graph.check_and_set_cloned_dataset_need_clone()
215218
self._fix_map_operations_to_taskgraph()
216219
if Env.get().config.offload.level == "v0":
217220
tf_logging.info("enable weight offload")

tests/graph_test.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,27 @@ def test_multithread_prefetch(self):
774774
steps.append(step)
775775
self.assertEqual(steps, [0, 1, 2])
776776

777+
def test_check_and_set_cloned_dataset_need_clone(self):
778+
epl.init()
779+
epl.set_default_strategy(epl.replicate(1))
780+
num_x = np.random.randint(0, 10, (500, 10)).astype(dtype=np.float32)
781+
num_y = np.random.randint(0, 10, 500).astype(dtype=np.int32)
782+
dataset = tf.data.Dataset.from_tensor_slices((num_x, num_y)) \
783+
.batch(2).repeat(1)
784+
iterator = dataset.make_initializable_iterator()
785+
tf.add_to_collection(tf.GraphKeys.TABLE_INITIALIZERS, iterator.initializer)
786+
source, target = iterator.get_next()
787+
x = tf.layers.dense(inputs=source, units=16, activation=None)
788+
x = tf.layers.dense(inputs=x, units=16, activation=None)
789+
dense1 = tf.layers.dense(inputs=x, units=16, activation=None)
790+
logits = tf.layers.dense(inputs=dense1, units=10, activation=None)
791+
loss = tf.reduce_mean(logits)
792+
global_step = tf.train.get_or_create_global_step()
793+
optimizer = tf.train.MomentumOptimizer(learning_rate=0.001, momentum=0.9)
794+
train_op = optimizer.minimize(loss, global_step=global_step)
795+
epl.Graph.get().check_and_set_cloned_dataset_need_clone()
796+
797+
777798

778799
# pylint: enable=missing-docstring,protected-access,unused-argument,
779800
# pylint: enable=line-too-long,bad-continuation,unused-variable

0 commit comments

Comments
 (0)