Skip to content

Commit

Permalink
Add check env sub command (#654)
Browse files Browse the repository at this point in the history
* add check env

* update issue template'

* remove some reqs from check env

* resolve comment
  • Loading branch information
RunningLeon authored Nov 8, 2023
1 parent 9febf61 commit 013000d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .github/ISSUE_TEMPLATE/1-bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,18 @@ body:
A placeholder for the command.
validations:
required: true
- type: textarea
attributes:
label: Environment
description: |
1. Please run `lmdeploy check_env` to collect necessary environment information and paste it here.
2. You may add addition that may be helpful for locating the problem, such as
- How you installed PyTorch \[e.g., pip, conda, source\]
- Other environment variables that may be related (such as `$PATH`, `$LD_LIBRARY_PATH`, `$PYTHONPATH`, etc.)
placeholder: Environment here.
render: Shell
validations:
required: true
- type: textarea
attributes:
label: Error traceback
Expand Down
46 changes: 46 additions & 0 deletions lmdeploy/cli/cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Copyright (c) OpenMMLab. All rights reserved.
import os

import fire

from .chat import SubCliChat
Expand Down Expand Up @@ -77,6 +79,50 @@ def list(self, engine: str = 'turbomind'):
print('Supported model names:')
print('\n'.join(model_names))

def check_env(self, dump_file: str = None):
"""Check env information.
Args:
dump_file (str): Output file to save env info.
"""

import importlib

import mmengine
from mmengine.utils import get_git_hash
from mmengine.utils.dl_utils import collect_env

from lmdeploy.version import __version__

env_info = collect_env()
env_info['LMDeploy'] = __version__ + '+' + get_git_hash()[:7]

# remove some unnecessary info
remove_reqs = ['MMEngine', 'OpenCV']
for req in remove_reqs:
if req in env_info:
env_info.pop(req)

# extra important dependencies
extra_reqs = ['transformers', 'gradio', 'fastapi', 'pydantic']

for req in extra_reqs:
try:
env_info[req] = importlib.import_module(req).__version__
except Exception:
env_info[req] = 'Not Found'

# print env info
for k, v in env_info.items():
print(f'{k}: {v}')

# dump to local file
if dump_file is not None:
work_dir, _ = os.path.split(dump_file)
if work_dir:
os.makedirs(work_dir, exist_ok=True)
mmengine.dump(env_info, dump_file)


def run():
"""The entry point of running LMDeploy CLI."""
Expand Down

0 comments on commit 013000d

Please sign in to comment.