huggingface / knockknock

🚪✊Knock Knock: Get notified when your training ends with only two additional lines of code
MIT License
2.78k stars 233 forks source link

New Feature: Add a config enable general decorator. #74

Closed jhliu17 closed 2 years ago

jhliu17 commented 2 years ago

Hey all,

I just used knockknock frequently in my previous research experiment. And I found it is inconvenient at this time if I want to use knockknock multiple times in my codebase. Because I need to maintain consistent sender function parameters in my code everywhere. And it is easy to leakage my personal security token (such as slack webhook_url). As a result, I propose to add a general decorator to handle these tricky things.

Property:

  1. This general decorator can parse a config file to handle different sender function parameters.
  2. The decorator can be silent when we are debugging our codebase. Since at the debug stage, we don't need verbose notification.
  3. Separate the sender config in an independent config file can mitigate the risk of information leakage. (Just adding the config file into your .gitignore file.)

I finished the above properties. And I tested it on my personal desktop (Mac).

Below are some code examples:

@knockknock(config_path='./', config_name='test.ini') # directly set your config path def train_your_model(your_nicest_parameters): import time time.sleep(10) return {'loss': 0.9} # Optional return value

@knockknock(config_path='./', config_name='test.ini') # convenient to use it multiple times in your codebase def eval_your_model(your_nicest_parameters): import time time.sleep(10) return {'acc': 0.9} # Optional return value

train_your_model(None) eval_your_model(None)


- Config file `test.ini`

[knockknock] sender=your_sender_type notification=True webhook_url=your_webhook_url channel=your_channel


If `notification` is not set, it will be `True` by default.  The config file must be started with the `knockknock` tag. And the `sender` determines the sender type. Other parameters are related to according sender function.
jhliu17 commented 2 years ago

And I will update the readme file in the next few days.

jhliu17 commented 2 years ago

It seems the repository has stopped being maintained. I close my request.