Git Product home page Git Product logo

Comments (6)

MischaPanch avatar MischaPanch commented on July 16, 2024

Do you mean adding exploration noise during training rollouts? It's a bit tricky and one of the heftier technical debts of tianshou. If that's what you mean, I'll write a short explanation of the current status here

from tianshou.

DLoveS1314 avatar DLoveS1314 commented on July 16, 2024

Thank you for your prompt and professional reply!
According to my understanding, tianshou.trainer.BaseTrainer.train_step() implements the use of train_collector.collect() to collect training data from the environment ,
The usage is as shown in the code below(tianshou/trainer/base.py line 436):

result = self.train_collector.collect(

          n_step=self.step_per_collect,

          n_episode=self.episode_per_collect,

      )

in collect() There is a piece of code as follows(tianshou/data/collector.py line 285)

if random:

              try:

                  act_sample = [self._action_space[i].sample() for i in ready_env_ids]

              except TypeError:  # envpool's action space is not for per-env

                  act_sample = [self._action_space.sample() for _ in ready_env_ids]

              act_sample = self.policy.map_action_inverse(act_sample)  # type: ignore

              self.data.update(act=act_sample)

My question is how to pass random parameters to collect() function in train_step when using BaseTrainer Class
The method of using trainer in the outermost layer is as follows I can't find how to pass in a random tag

result = OffpolicyTrainer(
      policy=policy,
      train_collector=train_collector,
      test_collector=test_collector,
      max_epoch=args.epoch,
      step_per_epoch=args.step_per_epoch,
      step_per_collect=args.step_per_collect,
      episode_per_test=args.test_num,
      batch_size=args.batch_size,
      update_per_step=args.update_per_step,
      stop_fn=stop_fn,
      train_fn=train_fn,
      test_fn=test_fn,
      save_best_fn=save_best_fn,
      logger=logger,
  ).run()

from tianshou.

MischaPanch avatar MischaPanch commented on July 16, 2024

I see, I'll check it and will write an explanation tomorrow in the morning. Thanks for the good question, we'll add some documentation (or maybe even a small refactoring, if possible) to make that clearer

from tianshou.

DLoveS1314 avatar DLoveS1314 commented on July 16, 2024

Thanks!

from tianshou.

maxhuettenrauch avatar maxhuettenrauch commented on July 16, 2024

May I ask what your intended use-case is? If it is collecting warm-up steps for OffPolicy algorithms, these are currently collected before the Collector is handed to the Trainer. Have a look at the examples for algorithms like TD3 or SAC.

from tianshou.

MischaPanch avatar MischaPanch commented on July 16, 2024

Sorry, the last days were very full, only got around to it now.

  1. When instantiating BaseTrainer directly, you will have to create a Collector and pass it as train_collector. Then you can pass random=True when instantiating the corresponding Colllector instance.
  2. Currently the train_step interface doesn't allow any additional controls. We might adjust it in the near future. If you want to hack your way through it, you could manually adjust the wrapped train_collector. So you could do
my_trainer.train_collector.random = True
# Do something that you want
my_trainer.train_step()
my_trainer.train_collector.random = False

While it's not pretty, it will work. If you want to use the high-level interfaces, such hacking would be more difficult, but probably still possible

To better understand how we can adjust the interfaces for improving user experience, it would be great to understand your use case, as @maxhuettenrauch has pointed out.

Hope this answer helps you :) @DLoveS1314

from tianshou.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.