Skip to content

Instantly share code, notes, and snippets.

@Jiayi-Pan
Last active July 28, 2023 12:55
Show Gist options
  • Save Jiayi-Pan/57595821f65daf0126f59cb817a98a9e to your computer and use it in GitHub Desktop.
Save Jiayi-Pan/57595821f65daf0126f59cb817a98a9e to your computer and use it in GitHub Desktop.
Nice ML Debugging Tools

Interactive Stop Point

from IPython import embed
embed()

Type Ctrl-D to proceed

import lovely_tensors as lt
lt.monkey_patch()
from loguru import logger
logger.debug("That's it, beautiful and simple logging!")

Show exception location

Please note that accepting exceptions blindlessly is usually not a good practice.

import sys, os

try:
    # Your code here
except Exception as e:
    exc_type, exc_obj, exc_tb = sys.exc_info()
    fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
    line_number = exc_tb.tb_lineno
    print(f"Error executing function: {str(e)}. Error at line: {line_number} in file: {fname}. Please try again.")

Better Exceptions

import better_exceptions

better_exceptions.hook()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment