Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
boomanaiden154 committed Jul 11, 2024
1 parent 8988eb4 commit 362ddae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions compiler_opt/es/blackbox_learner.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ def _log_tf_summary(self, rewards: List[float]) -> None:
with self._summary_writer.as_default():
tf.summary.scalar(
'reward/average_reward_train', np.mean(rewards), step=self._step)

tf.summary.scalar(
'reward/maximum_reward_train', np.max(rewards), step=self._step
)

tf.summary.histogram('reward/reward_train', rewards, step=self._step)

Expand Down
9 changes: 8 additions & 1 deletion compiler_opt/es/es_trainer_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import gin
import tensorflow as tf
import os
import shutil

from compiler_opt.distributed import worker
from compiler_opt.distributed.local import local_worker_manager
Expand Down Expand Up @@ -79,6 +80,7 @@ def __init__(self, *, all_gin):
self._clang_path = '/usr/local/google/home/aidengrossman/programming/test_traces/clang'
self._trace_path = '/usr/local/google/home/aidengrossman/programming/test_traces/execution_trace.pb'
self._bb_trace_model_path = '/usr/local/google/home/aidengrossman/programming/test_traces/basic_block_trace_model'
self._models_for_test_path = '/usr/local/google/home/aidengrossman/programming/output_traces/'

def es_compile(self, params: list[float], baseline_score: float) -> float:
with tempfile.TemporaryDirectory() as tempdir:
Expand All @@ -99,8 +101,13 @@ def es_compile(self, params: list[float], baseline_score: float) -> float:
self._clang_path, tflitedir)
score = trace_data_collector.evaluate_compiled_corpus(
tempdir, self._trace_path, self._bb_trace_model_path)
print(score)

reward = compilation_runner._calculate_reward(score, baseline_score)
print(reward)

output_path = os.path.join(self._models_for_test_path, "model" + str(reward))
if reward > 0.2 and not os.path.exists(output_path):
shutil.copytree(tflitedir, output_path)
return compilation_runner._calculate_reward(score, baseline_score)


Expand Down
4 changes: 2 additions & 2 deletions compiler_opt/es/gin_configs/blackbox_learner.gin
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import compiler_opt.rl.gin_external_configurables
import compiler_opt.es.blackbox_optimizers

# Blackbox learner config
BlackboxLearnerConfig.total_steps = 1
BlackboxLearnerConfig.total_num_perturbations = 5
BlackboxLearnerConfig.total_steps = 100
BlackboxLearnerConfig.total_num_perturbations = 100
BlackboxLearnerConfig.blackbox_optimizer = %blackbox_optimizers.Algorithm.MONTE_CARLO
BlackboxLearnerConfig.est_type = %blackbox_optimizers.EstimatorType.ANTITHETIC
# BlackboxLearnerConfig.est_type = %blackbox_optimizers.EstimatorType.FORWARD_FD
Expand Down

0 comments on commit 362ddae

Please sign in to comment.