forked from mlc-ai/mlc-llm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Build] Added --pdb flag to build.py, drop into pdb on error (mlc-ai#…
…1017) This commit adds an optional `--pdb` flag to the `build.py` script. If passed, any exception raised that would otherwise terminate the script will first enter a pdb post-mortem, allowing the error to be inspected.
- Loading branch information
1 parent
ad3a6b9
commit 6e40c21
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,46 @@ | ||
"""Script for building/compiling models.""" | ||
import contextlib | ||
import sys | ||
|
||
from mlc_llm import core | ||
|
||
|
||
@contextlib.contextmanager | ||
def debug_on_except(): | ||
try: | ||
yield | ||
finally: | ||
if sys.exc_info() == (None, None, None): | ||
return | ||
|
||
import traceback | ||
|
||
try: | ||
import ipdb as pdb | ||
except ImportError: | ||
import pdb | ||
|
||
traceback.print_exc() | ||
pdb.post_mortem() | ||
|
||
|
||
def main(): | ||
"""Main method for building model from command line.""" | ||
empty_args = core.convert_build_args_to_argparser() # Create new ArgumentParser | ||
parsed_args = empty_args.parse_args() # Parse through command line | ||
# Post processing of arguments | ||
parsed_args = core._parse_args(parsed_args) # pylint: disable=protected-access | ||
core.build_model_from_args(parsed_args) | ||
|
||
with contextlib.ExitStack() as stack: | ||
# Enter an exception-catching context before post-processing | ||
# the arguments, in case the post-processing itself raises an | ||
# exception. | ||
if parsed_args.pdb: | ||
stack.enter_context(debug_on_except()) | ||
|
||
# Post processing of arguments | ||
parsed_args = core._parse_args(parsed_args) # pylint: disable=protected-access | ||
|
||
core.build_model_from_args(parsed_args) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters