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

Fix TGI (Text Generation Inference) Endpoint Inference and TGI JSON Grammar Generation #502

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ dependencies = [

[project.optional-dependencies]
litellm = ["litellm", "diskcache"]
tgi = ["text-generation==0.6.0"]
tgi = ["text-generation==0.7.0"]
optimum = ["optimum==1.12.0"]
quantization = ["bitsandbytes>=0.41.0", "auto-gptq>=0.4.2"]
adapters = ["peft==0.3.0"]
Expand Down
2 changes: 2 additions & 0 deletions src/lighteval/models/endpoints/endpoint_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ async def _async_process_batch_logprob(
context=request.context if rolling else request.context + request.choice,
stop_tokens=[],
max_tokens=1,
grammar=request.generation_grammar,
)
for request in requests
]
Expand All @@ -491,6 +492,7 @@ def _process_batch_logprob(
context=request.context if rolling else request.context + request.choice,
stop_tokens=[],
max_tokens=1,
grammar=request.generation_grammar,
Copy link
Member

Choose a reason for hiding this comment

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

why is the grammar in the request here while it is defined in the generation config ?

Copy link
Author

Choose a reason for hiding this comment

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

Thank you for the feedback @NathanHB 🙏🏻

I did it similarly to how I've seen it done in the same file. See here for an example.
Potentially the usage could be improved in a follow-up PR.

Lmk if I'm also missing something on my end

)
for request in requests
]
Expand Down
21 changes: 19 additions & 2 deletions src/lighteval/models/endpoints/tgi_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(self, config: TGIModelConfig) -> None:

model_name = str(self.model_info["model_id"])
model_sha = self.model_info["model_sha"]
model_precision = self.model_info["model_dtype"]
model_precision = self.model_info.get("model_dtype")
self.model_info = ModelInfo(
model_name=model_name,
model_sha=model_sha,
Expand All @@ -127,7 +127,24 @@ def _async_process_request(
grammar=grammar,
)

generated_text = self.client.generate(prompt=context, generation_config=generation_config)
generated_text = self.client.generate(
prompt=context,
do_sample=generation_config.do_sample or False,
max_new_tokens=generation_config.max_new_tokens,
best_of=generation_config.best_of,
repetition_penalty=generation_config.repetition_penalty,
return_full_text=generation_config.return_full_text or False,
seed=generation_config.seed,
stop_sequences=generation_config.stop,
temperature=generation_config.temperature,
top_k=generation_config.top_k,
top_p=generation_config.top_p,
truncate=generation_config.truncate,
typical_p=generation_config.typical_p,
watermark=generation_config.watermark or False,
decoder_input_details=generation_config.decoder_input_details,
grammar=generation_config.grammar,
)
Comment on lines +130 to +147
Copy link
Member

Choose a reason for hiding this comment

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

is this needed ?

Copy link
Author

@cpcdoy cpcdoy Feb 7, 2025

Choose a reason for hiding this comment

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

IIRC, this is the interface text-generation==0.7.0 is exposing now which is different since I have upgraded it from 0.6.0 in this PR.

Did you mean, is there a cleaner way to do this?


return generated_text

Expand Down
2 changes: 2 additions & 0 deletions src/lighteval/models/model_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class GenerationParameters:
min_p: Optional[float] = None # vllm, transformers
top_p: Optional[int] = None # vllm, transformers, tgi
truncate_prompt: Optional[bool] = None # vllm, tgi
grammar: Optional[str] = None # tgi

@classmethod
def from_dict(cls, config_dict: dict):
Expand Down Expand Up @@ -117,5 +118,6 @@ def to_tgi_ie_dict(self) -> dict:
"top_k": self.top_k,
"top_p": self.top_p,
"truncate": self.truncate_prompt,
"grammar": self.grammar,
}
return {k: v for k, v in args.items() if v is not None}
4 changes: 1 addition & 3 deletions src/lighteval/models/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ def load_model_with_tgi(config: TGIModelConfig):
raise ImportError(NO_TGI_ERROR_MSG)

logger.info(f"Load model from inference server: {config.inference_server_address}")
model = ModelClient(
address=config.inference_server_address, auth_token=config.inference_server_auth, model_id=config.model_id
)
model = ModelClient(config=config)
return model


Expand Down