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

fix and change all logger using get_logger #1064

Merged
merged 8 commits into from
Jan 31, 2024
Merged

Conversation

yinfan98
Copy link
Contributor

Thanks for your contribution and we appreciate it a lot. The following instructions would make your pull request more healthy and more easily receiving feedbacks. If you do not understand some items, don't worry, just make the pull request and seek help from maintainers.

Motivation

1.The get_logger function use mmengine get_logger, It will initialize CUDA, causing TurboMind to fail the second CUDA initialization.
2.Standardize the logger for all lmdeploy.

Modification

  1. modify the get_logger at lmdeploy/utils.py
  2. change
from transformers import logging
logger = logging.get_logger("name")

### and

import logging
logger = logging.getLogger("name")

### to

from lmdeploy.utils import get_logger
logger = get_logger("name")

3.change get_logger implement

def get_logger(
    name: Optional[str] = None,
    log_file: Optional[str] = None,
    log_level: int = logging.INFO,
    file_mode: str = 'w',
    log_formatter: str = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
) -> Logger:

I add the log_formatter that it can easily change the format for the instance.

BC-breaking (Optional)

no

Use cases (Optional)

We can use the get_logger like

from lmdeploy.utils import get_logger
## just make a logger
logger = get_logger("name")
## change log level
logger = get_logger("name", log_level=xxx)
## save log
logger = get_logger("name", log_file="xx", file_mode="xx")
## change format
logger = get_logger("name", log_formatter="xxx")

Checklist

  1. Pre-commit or other linting tools are used to fix the potential lint issues.
  2. The modification is covered by complete unit tests. If not, please add more unit tests to ensure the correctness.
  3. If the modification has a dependency on downstream projects of a newer version, this PR should be tested with all supported versions of downstream projects.
  4. The documentation has been modified accordingly, like docstring or example tutorials.

@irexyc
Copy link
Collaborator

irexyc commented Jan 30, 2024

搜了一下,还有一些文件用到了import logging,不如索性都改成 get_logger

@yinfan98
Copy link
Contributor Author

yinfan98 commented Jan 30, 2024

@irexyc Sure, I will check that

@yinfan98
Copy link
Contributor Author

@irexyc Hi, I change the logging to get_logger in turbomind.py, and the reason some files require the use of import logging is because there is a need to set the level.

Copy link
Collaborator

@RunningLeon RunningLeon left a comment

Choose a reason for hiding this comment

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

LGTM

@lvhan028
Copy link
Collaborator

Today, we are going to release v0.2.2. Let's put this PR to next version v0.2.3

@yinfan98
Copy link
Contributor Author

@lvhan028 Sure

@lvhan028 lvhan028 merged commit 789dcce into InternLM:main Jan 31, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants