facebookresearch / CompilerGym

Reinforcement learning environments for compiler and program optimization tasks
https://compilergym.ai/
MIT License
906 stars 127 forks source link

Running rllib example with custom environment #639

Closed dejangrubisic closed 2 years ago

dejangrubisic commented 2 years ago

❓ Questions and Help

I am trying to run custom environment with rllib example. I have registered my Dataset, and environment, and everything works well until training part with ray

tune.register_env("compiler_gym", make_training_env)

The error is: (RolloutWorker pid=509716) gym.error.UnregisteredEnv: No registered env with id: perf-v0

https://github.com/Compiler2/compiler2/blob/rllib-prof/training_scripts/rllib.ipynb

Additional Context

Here is the reproducer: https://github.com/Compiler2/compiler2/blob/rllib-prof/training_scripts/rllib.ipynb

How you installed CompilerGym (conda, pip, source): conda compiler_gym version: 0.2.3 OS: rhel 8.4 Python version: Python 3.8.10 GCC/clang version (if compiling from source): gcc 8.5.0

Do you know what could be a problem here? Thanks!

ChrisCummins commented 2 years ago

Hi @dejangrubisic,

I am seeing error /lib64/libtinfo.so.5: no version information available (required by ./compiler_gym-llvm-service) in your output. This might be a problem.

Does calling make_env() directly work for you?

BTW, we are running a tutorial at CGO 22 this Saturday. We'll be around live if you wanna hang out and ask questions there. Everyone welcome! 🙂

https://conf.researchr.org/program/cgo-2022/program-cgo-2022/?date=Sat%202%20Apr%202022

Cheers, Chris

dejangrubisic commented 2 years ago

Thanks @ChrisCummins, looking forward to your workshop on Saturday!

with make_env() as env:
    print("Action space:", env.action_space)
    print("Observation space:", env.observation_space)
    print("Reward space:", env.reward_space)

Returns Action space: NamedDiscrete([-add-discriminators, -adce, -aggressive-instcombine, -alignment-from-assumptions, -always-inline, -argpromotion, -attributor, -barrier, -bdce, -break-crit-edges, ...]) Observation space: int8_list<>[0,9223372036854775807]) Reward space: perf

with make_training_env() as env:
  env.reset()
  print(env.benchmark)    

Also works and builds benchmarks

Finding I found that if I register my environment with compiler_gym and use compiler_gym.make it fails, while if I do that from init.py of the service module it somehow works.

from compiler_gym.util.registration import register 

register(
        id="perf-v0",
        entry_point="compiler_gym.envs:CompilerEnv",
        kwargs={
            "service": compiler2_service.paths.COMPILER2_SERVICE_PY,
            "rewards": [ perf_reward.Reward(),
                         runtime_reward.Reward()
            ],
            "datasets": [
                hpctoolkit_dataset.Dataset(),
                CBenchDataset(site_data_path("llvm-v0")),
            ],
        },
    )

env = compiler_gym.make(
        "perf-v0",
        observation_space="runtime",
        reward_space="runtime"
    )

This works

env = compiler2_service.make(
        "perf-v0",
        observation_space="runtime",
        reward_space="runtime"
    )

I will investigate it further, and clean it up for Saturday, so we can discuss it.

Thanks!

ChrisCummins commented 2 years ago

Okay yeah, sounds like something interesting and strange going on 🙂

Cheers, Chris