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

Shortfin LLM Debug Ergonomics: one flag to dump them all #668

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

Conversation

renxida
Copy link
Contributor

@renxida renxida commented Dec 9, 2024

Thanks @stbaione for originally writing a lot of the debug code in here. I organized his debug logging & dumping into a separate file & made the output easier to deal with.

@renxida renxida changed the title Use an environment variable to toggle a bunch of dumps at each Shortfin LLM invocation Shortfin LLM Debug Ergonomics: one flag to dump them all Dec 9, 2024
… interface a little; remove catch-all try statement because if we're not debugging we won't need it and if we're debugging we don't want the debugging code to fail silently when loglevel doesn't output info messages
Comment on lines -441 to 455
# Invoke. Logits are of shape [bs, bsl, d].

# pre-invocation args dump
if SHORTFIN_DEBUG_LLM_SERVICE:
await pre_invocation_debug_dump(executor=self, local_vars=locals())

# invoke VMFB
(logits,) = await fn(*args, fiber=self.fiber)
Copy link
Member

Choose a reason for hiding this comment

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

Keep the full # Invoke. Logits are of shape [bs, bsl, d]. comment?

Comment on lines +25 to +40
# Get environment variable, default to False if not set
SHORTFIN_DEBUG_LLM_SERVICE = os.getenv(
"SHORTFIN_DEBUG_LLM_SERVICE", "False"
).lower() in ("true", "yes", "1", "y")
if SHORTFIN_DEBUG_LLM_SERVICE:
logger.info("DEBUG_LLM_SERVICE=True")
dump_id = 0
boot_timestamp = datetime.now().isoformat()
DEBUG_DATA_DIR = Path.home() / ".shortfin/debug/"
DUMP_DIR_THIS_SESSION = (
DEBUG_DATA_DIR / "llm_service_invocation_dumps" / "{boot_timestamp}"
)
DUMP_DIR_THIS_SESSION.mkdir(parents=True, exist_ok=False)
logger.info(
f"[debug_service.py] Please find debug dumps for service.py in {DUMP_DIR_THIS_SESSION}"
)
Copy link
Member

Choose a reason for hiding this comment

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

Can you move this to an init() function so it doesn't always run at import time? This debug file could provide a class instead of a loose function that uses global variables. Then there would be no need to duplicate this os.getenv code across both files or add the Importing this should do nothing comment

# debug_service.py

class ShortfinLLMDebugService:
  def __init__(self):
    dump_id = 0
    dump_dir = ""
    dump_dir.mkdir(...)

  async def pre_invocation_debug_dump(...):
    is_decode = ...

# service.py

class GenerateService:
    def __init__(self, ...):
      ...

      SHORTFIN_DEBUG_LLM_SERVICE = os.getenv(
          "SHORTFIN_DEBUG_LLM_SERVICE", "False"
      ).lower() in ("true", "yes", "1", "y")
      if SHORTFIN_DEBUG_LLM_SERVICE:
        from .debug_service import ShortfinLLMDebugService
        llm_debug_service = ShortfinLLMDebugService

...

    async def run(self):
      ...
      if self.llm_debug_service:
        llm_debug_service.pre_invocation_debug_dump(...)

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