Skip to content

Commit

Permalink
Tiny improvements to endpoint_model.py, base_model.py,... (#219)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Nathan Habib <[email protected]>
Co-authored-by: Clémentine Fourrier <[email protected]>
  • Loading branch information
3 people authored Jan 3, 2025
1 parent 5a28b22 commit 452e031
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
13 changes: 8 additions & 5 deletions src/lighteval/models/endpoints/endpoint_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def greedy_until(

for _, _ in tqdm(
dataset.splits_start_end_iterator(),
total=self.DATASET_SPLITS,
total=dataset.num_dataset_splits,
desc="Splits",
position=0,
disable=self.disable_tqdm,
Expand All @@ -532,12 +532,15 @@ def greedy_until(
responses = asyncio.run(self._async_process_batch_generate(batch))
else:
responses = self._process_batch_generate(batch)
for response in responses:
for i, response in enumerate(responses):
results.append(
GenerativeResponse(
result=response.generated_text,
logits=[item.logprob for item in response.details.prefill] if returns_logits else None,
truncated_tokens_count=-1,
generated_tokens=[token.id for token in response.details.tokens],
truncated_tokens_count=max(
len(self.tokenizer.encode(batch[i].context)) - self.max_length, 0
),
padded_tokens_count=-1,
)
)
Expand All @@ -556,7 +559,7 @@ def loglikelihood(

for _, _ in tqdm(
dataset.splits_start_end_iterator(),
total=self.DATASET_SPLITS,
total=dataset.num_dataset_splits,
desc="Splits",
position=0,
disable=self.disable_tqdm,
Expand Down Expand Up @@ -607,7 +610,7 @@ def loglikelihood_rolling(

for _, _ in tqdm(
dataset.splits_start_end_iterator(),
total=self.DATASET_SPLITS,
total=dataset.num_dataset_splits,
desc="Splits",
position=0,
disable=self.disable_tqdm,
Expand Down
4 changes: 3 additions & 1 deletion src/lighteval/models/model_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ def load_openai_model(config: OpenAIModelConfig, env_config: EnvConfig):
return model


def load_model_with_inference_endpoints(config: InferenceEndpointModelConfig, env_config: EnvConfig):
def load_model_with_inference_endpoints(
config: Union[InferenceEndpointModelConfig, ServerlessEndpointModelConfig], env_config: EnvConfig
):
logger.info("Spin up model using inference endpoint.")
model = InferenceEndpointModel(config=config, env_config=env_config)
return model
Expand Down
5 changes: 1 addition & 4 deletions src/lighteval/models/transformers/transformers_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -880,10 +880,7 @@ def greedy_until(
input_ids=tokenized["input_ids"],
input_lengths=[len(item == 1) for item in tokenized["attention_mask"]],
input_mask=tokenized["attention_mask"],
truncated=[
len(c) - tokenized["input_ids"].shape[1] if len(c) > tokenized["input_ids"].shape[1] else 0
for c in context
],
truncated=[max(len(c) - tokenized["input_ids"].shape[1], 0) for c in context],
padded=[sum(mask == 0) for mask in tokenized["attention_mask"]],
)

Expand Down

0 comments on commit 452e031

Please sign in to comment.