Skip to content

Commit

Permalink
add the namescope for monitor
Browse files Browse the repository at this point in the history
  • Loading branch information
Yundi Qian committed Jul 26, 2021
1 parent a4860ca commit 9bada5d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
5 changes: 3 additions & 2 deletions compiler_opt/rl/local_data_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def _schedule_jobs(self, policy_path, sampled_file_paths):

def collect_data(
self, policy_path: str
) -> Tuple[Iterator[trajectory.Trajectory], Dict[str, float]]:
) -> Tuple[Iterator[trajectory.Trajectory], Dict[str, Dict[str, float]]]:
"""Collect data for a given policy.
Args:
Expand Down Expand Up @@ -166,7 +166,8 @@ def wait_for_termination():
self._default_policy_size_map.update(
{file_paths: res.get()[1] for (file_paths, res) in successful_work})

monitor_dict = {'success_modules': len(finished_work)}
monitor_dict = {}
monitor_dict['default'] = {'success_modules': len(finished_work)}

return self._parser(sequence_examples), monitor_dict

Expand Down
4 changes: 2 additions & 2 deletions compiler_opt/rl/local_data_collector_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,13 @@ def _test_iterator_fn(data_list):
data_iterator, monitor_dict = collector.collect_data(policy_path='policy')
data = list(data_iterator)
self.assertEqual([1, 2, 3], data)
expected_monitor_dict = {'success_modules': 10}
expected_monitor_dict = {'default': {'success_modules': 10}}
self.assertEqual(expected_monitor_dict, monitor_dict)

data_iterator, monitor_dict = collector.collect_data(policy_path='policy')
data = list(data_iterator)
self.assertEqual([4, 5, 6], data)
expected_monitor_dict = {'success_modules': 10}
expected_monitor_dict = {'default': {'success_modules': 10}}
self.assertEqual(expected_monitor_dict, monitor_dict)

collector.close_pool()
Expand Down
9 changes: 6 additions & 3 deletions compiler_opt/rl/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _update_metrics(self, experience, monitor_dict):
experience.reward, sample_weight=is_action)
self._num_trajectories.update_state(experience.is_first())

with tf.name_scope('Monitor/'):
with tf.name_scope('default/'):
tf.summary.scalar(
name='data_action_mean',
data=self._data_action_mean.result(),
Expand All @@ -133,8 +133,11 @@ def _update_metrics(self, experience, monitor_dict):
name='num_trajectories',
data=self._num_trajectories.result(),
step=self._global_step)
for key, value in monitor_dict.items():
tf.summary.scalar(name=key, data=value, step=self._global_step)

for name_scope, d in monitor_dict.items():
with tf.name_scope(name_scope + '/'):
for key, value in d.items():
tf.summary.scalar(name=key, data=value, step=self._global_step)

tf.summary.histogram(
name='reward', data=experience.reward, step=self._global_step)
Expand Down
4 changes: 2 additions & 2 deletions compiler_opt/rl/trainer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def test_training(self):
self.assertEqual(0, test_trainer._global_step.numpy())

dataset_iter = _create_test_data(batch_size=3, sequence_length=3)
monitor_dict = {'test': 1}
monitor_dict = {'default': {'test': 1}}

with mock.patch.object(
tf.summary, 'scalar', autospec=True) as mock_scalar_summary:
Expand All @@ -117,7 +117,7 @@ def test_training_with_multiple_times(self):
self.assertEqual(0, test_trainer._global_step.numpy())

dataset_iter = _create_test_data(batch_size=3, sequence_length=3)
monitor_dict = {'test': 1}
monitor_dict = {'default': {'test': 1}}
test_trainer.train(dataset_iter, monitor_dict, num_iterations=10)
self.assertEqual(10, test_trainer._global_step.numpy())

Expand Down

0 comments on commit 9bada5d

Please sign in to comment.