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

Litgpt serve API #1299

Merged
merged 21 commits into from
Apr 17, 2024
Merged

Litgpt serve API #1299

merged 21 commits into from
Apr 17, 2024

Conversation

rasbt
Copy link
Collaborator

@rasbt rasbt commented Apr 15, 2024

The LitGPT serve API. E.g., use as

litgpt serve --checkpoint_dir checkpoints/microsoft/phi-2

and then send requests via

In [1]:  import requests, json

In [2]:  response = requests.post(
   ...:      "http://127.0.0.1:8000/predict",
   ...:          json={"prompt": "Fix typos in the following sentence: Exampel input"}
   ...:          )

@rasbt rasbt marked this pull request as draft April 15, 2024 21:15
@rasbt rasbt mentioned this pull request Apr 15, 2024
@rasbt rasbt marked this pull request as ready for review April 15, 2024 21:48
@rasbt rasbt requested a review from williamFalcon as a code owner April 15, 2024 21:48
Copy link
Contributor

@lantiga lantiga 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, added a few comments. We also need a test for this, feel free to inherit test code from litserve since it's using clients etc

@aniketmaurya will be able to advise here

litgpt/deploy/serve.py Outdated Show resolved Hide resolved
litgpt/deploy/serve.py Outdated Show resolved Hide resolved
litgpt/deploy/serve.py Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
litgpt/deploy/serve.py Show resolved Hide resolved
litgpt/deploy/serve.py Show resolved Hide resolved
Copy link
Contributor

@williamFalcon williamFalcon left a comment

Choose a reason for hiding this comment

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

this is sick. super excited about this landing. nice job.

@rasbt
Copy link
Collaborator Author

rasbt commented Apr 16, 2024

It would be nice of you could review @lantiga and @aniketmaurya . Btw I am currently having problems with getting quantize (e.g., --quantize bnb.nf4) etc to work. Somehow it's a None type even if I pass it via the CLI. It's been a long day and maybe I'm overlooking something here ...

@rasbt rasbt merged commit c67de02 into main Apr 17, 2024
9 checks passed
@rasbt rasbt deleted the litgpt-serve branch April 17, 2024 19:29
@rasbt rasbt mentioned this pull request Apr 18, 2024
@@ -12,6 +12,7 @@ dependencies = [
"torch>=2.2.0",
"lightning==2.3.0.dev20240328",
"jsonargparse[signatures]>=4.27.6",
"litserve==0.0.0.dev2", # imported by litgpt.deploy
Copy link
Contributor

Choose a reason for hiding this comment

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

@rasbt Did you make this a required dependency (instead of an "all") purposefully?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When I remember correctly, I had problems with tugging the import so that it doesn't always gets called. I think that was due to how we use inheritance in

class SimpleLitAPI(LitAPI):

But I suppose one can define the class in a function to avoid the import at the top. But that would be ugly. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

You can follow this pattern:

from lightning_utilities.core.imports import RequirementCache
from litgpt import Tokenizer
from litgpt.utils import CLI
_LITDATA_AVAILABLE = RequirementCache("litdata")
if _LITDATA_AVAILABLE:
from litdata.processing.data_processor import DataChunkRecipe
else:
DataChunkRecipe = object
class StarcoderDataRecipe(DataChunkRecipe):

And then inside the __init__(), before calling super().__init__() check that _LITSERVE_AVAILABLE is True (this part is missing from the code I linked)

import shutil

from lightning.fabric import seed_everything
from fastapi.testclient import TestClient
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should specify this as a test dependency too

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