Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too many with lines in DQNTrainer and FusedGame #47

Open
honglu2875 opened this issue Aug 8, 2022 · 3 comments
Open

Too many with lines in DQNTrainer and FusedGame #47

honglu2875 opened this issue Aug 8, 2022 · 3 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@honglu2875
Copy link
Owner

To time each component (very important in tweaking parameters for large scale computing), the best way I am aware so far is the with context manager like in the code. But when there are too many to time, it becomes ugly. It really hurts the readability. Is there a way to simplify this? (e.g., can one define a special syntax in comments, and convert all those comments through a single context manager outside with options to activate or not? Or is there a good profiler that suits the purpose?)

@honglu2875 honglu2875 added help wanted Extra attention is needed good first issue Good for newcomers labels Aug 8, 2022
@LunaCodeDemon
Copy link

LunaCodeDemon commented Aug 12, 2022

You can write a spawner class for Timer, you could give it the attributes that are commonly reused and effectively make the lines shorter.

Another thing that could be done is writing a simple wrapper for the timer stuff.
Would mean tho that you then need to put everything in lamda functions.
A wrapper for that would look something like that.

def time_that(name: str, log_dict: dict, active=True, use_cuda=False, callback, *args, **kwargs):
    with Timer(name, log_dict, active, use_cuda):
          return callback(*args, **kwargs);

So the answer is that you can remove a lot of with statements but it would make it more complicated.

@honglu2875
Copy link
Owner Author

Awesome! Thanks for the tips. Need to think about it.

Is it generally a bad idea to modify codes when using context manager? Ideally I would like to mark the lines I want to time in comments and only time it during profiling/debugging. In actual deployment/experiment I don't really care about those timer records.

@LunaCodeDemon
Copy link

So far i know you can remove it.
Right now i do not really know tho how to remove it via variable.
Using the spawner method you could make passthrough objects if an attribute is set, but i don't know if it's recommendable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants