Skip to content

Conversation

@aniketmaurya
Copy link
Collaborator

@aniketmaurya aniketmaurya commented May 23, 2025

What does this PR do?

Users will be able to set_trace for debugging.

image

Example

import litserve as ls

class SimpleLitAPI(ls.LitAPI):
    def setup(self, device):
        self.model1 = lambda x: x**2
        self.model2 = lambda x: x**3

    def decode_request(self, request):
        # get inputs to /predict
        return request["input"]

    def predict(self, x):
        # perform calculations using both models
        a = self.model1(x)
        ls.set_trace()
        b = self.model2(x)
        c = a + b
        return {"output": c}

    def encode_response(self, output):
        # package outputs from /predict
        return {"output": output}

if __name__ == "__main__":
    server = ls.LitServer(SimpleLitAPI(max_batch_size=1), accelerator="auto")
    server.run(port=8000)

  • Added set_trace and set_trace_if_debug functions to litserve/utils.py for debugging support.
  • Updated litserve/__init__.py to import new debugging utilities.
  • Added unit tests for set_trace_if_debug to ensure correct behavior based on the LITSERVE_DEBUG environment variable.
Before submitting
  • Was this discussed/agreed via a Github issue? (no need for typos and docs improvements)
  • Did you read the contributor guideline, Pull Request section?
  • Did you make sure to update the docs?
  • Did you write any new necessary tests?

PR review

Anyone in the community is free to review the PR once the tests have passed.
If we didn't discuss your PR in GitHub issues there's a high chance it will not be merged.

Did you have fun?

Make sure you had fun coding 🙃

- Added `set_trace` and `set_trace_if_debug` functions to `litserve/utils.py` for debugging support.
- Updated `litserve/__init__.py` to import new debugging utilities.
- Added unit tests for `set_trace_if_debug` to ensure correct behavior based on the `LITSERVE_DEBUG` environment variable.
@codecov
Copy link

codecov bot commented May 23, 2025

Codecov Report

Attention: Patch coverage is 60.00000% with 6 lines in your changes missing coverage. Please review.

Project coverage is 86%. Comparing base (7fcbdfb) to head (a192436).
Report is 2 commits behind head on main.

Additional details and impacted files
@@         Coverage Diff         @@
##           main   #508   +/-   ##
===================================
- Coverage    86%    86%   -0%     
===================================
  Files        37     37           
  Lines      2373   2386   +13     
===================================
+ Hits       2046   2054    +8     
- Misses      327    332    +5     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@lianakoleva lianakoleva left a comment

Choose a reason for hiding this comment

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

looks great! will be useful, just one small ask

@aniketmaurya aniketmaurya requested a review from lianakoleva May 23, 2025 18:17
@aniketmaurya aniketmaurya merged commit fb96478 into main May 23, 2025
21 checks passed
@aniketmaurya aniketmaurya deleted the integrate-fpdb branch May 23, 2025 20:54
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.

5 participants