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

Emnlp #7

Open
wants to merge 93 commits into
base: main
Choose a base branch
from
Open

Emnlp #7

wants to merge 93 commits into from

Conversation

chrisrytting
Copy link
Collaborator

No description provided.

@vinhowe vinhowe requested a review from alexgshaw May 20, 2023 00:09
@vinhowe
Copy link
Member

vinhowe commented May 20, 2023

@chrisrytting @alexgshaw I think I've removed everything we wanted gone.

@alexgshaw
Copy link
Contributor

alexgshaw commented May 20, 2023 via email

# TODO: This is not a good way to do logging; we should actually use
# the logging module or something similar.
if self.logger:
self.logger.exception("Rate limited, retrying...")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.exception is only used to add context to caught exceptions—almost always in an except block. This isn't even really an error. logger.warning would probably be more appropriate here.

https://docs.python.org/3/library/logging.html#logging.Logger.exception

# the logging module or something similar.
if self.logger:
self.logger.exception("Rate limited, retrying...")
print("Rate limited, retrying...", file=sys.stderr)
Copy link
Member

@vinhowe vinhowe May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everywhere I've seen, logging libraries replace regular print statements. Assuming that there is a logger available isn't an antipattern. Additionally, you could consider doing what projects like FastAPI do and define a global logger instead.

Comment on lines +86 to +88
print(e)
if self.logger:
self.logger.exception(e)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

):
self.model_name = model_name
self.state_dict_path = state_dict_path
self.config_path = config_path
self.logger = logger
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +84 to +85
if self.logger:
self.logger.exception(e)
Copy link
Member

@vinhowe vinhowe May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +145 to +153
logger = logging.getLogger(__name__)
logger.setLevel(logging.ERROR)
handler = logging.FileHandler(Path(experiment_dir) / "errors.log")
handler.setLevel(logging.ERROR)
formatter = logging.Formatter("%(asctime)s %(message)s")
handler.setFormatter(formatter)
logger.addHandler(handler)
else:
logger = None
Copy link
Member

@vinhowe vinhowe May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can configure the global logger instead of passing a logger to every class. Passing a logger to every class feels a little bit like an antipattern.


self._async_limiter = AsyncLimiter(OPENAI_RPM)

print(f"Using async {self.engine} engine.")
Copy link
Member

@vinhowe vinhowe May 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logger.info would be appropriate here

@@ -50,24 +77,52 @@ def send_prompt(self, prompt, n_probs=100, **kwargs):
sorted_logprobs = dict(
sorted(logprobs.items(), key=lambda x: x[1], reverse=True)
)
return sorted_logprobs
raise Exception("testing logging")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrisrytting this should definitely be removed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants