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

TypeError of scrolls_narrativeqa #1891

Open
hicleo opened this issue May 27, 2024 · 0 comments
Open

TypeError of scrolls_narrativeqa #1891

hicleo opened this issue May 27, 2024 · 0 comments
Assignees

Comments

@hicleo
Copy link

hicleo commented May 27, 2024

The error occurred when I tried to test with --tasks scrolls_narrativeqa. My command was as follows:

lm_eval --model hf     --model_args pretrained=princeton-nlp/Sheared-LLaMA-2.7B,parallelize=True  --tasks scrolls_narrativeqa    --batch_size auto     --output_path /lm_eval_out/Sheared-LLaMA-2.7B    --use_cache /lm_eval_out/Sheared-LLaMA-2.7B/eval_cache    --num_fewshot 0
"/lm-evaluation-harness/lm_eval/evaluator.py", line 596, in <dictcomp>
"original": len(task_output.task.eval_docs),
TypeError: object of type 'generator' has no len()

I do some changes in evaluator.py then the evaluator can work smoothly
I want to make sure if these changes are allowed here

from collections.abc import Generator
...
# "n-samples": {
#     task_output.task_name: {
#         "original": len(task_output.task.eval_docs),
#         "effective": min(
#             limit if limit else len(task_output.task.eval_docs),
#             len(task_output.task.eval_docs),
#         ),
#     }
#     for task_output in eval_tasks
# },

"n_samples": {
        task_output.task_name: {
            "original": len(list(task_output.task.eval_docs)) if isinstance(task_output.task.eval_docs, Generator) else len(task_output.task.eval_docs),
            "effective": min(
                limit if limit else (len(list(task_output.task.eval_docs)) if isinstance(task_output.task.eval_docs, Generator) else len(task_output.task.eval_docs)),
                len(list(task_output.task.eval_docs)) if isinstance(task_output.task.eval_docs, Generator) else len(task_output.task.eval_docs),
            ),
        }
        for task_output in eval_tasks
    },

also some changes in evaluator_utils.py

# def get_sample_size(task, limit: Optional[int]) -> Union[int, None]:
#     if limit is not None:
#         limit = (
#             int(math.ceil(len(task.eval_docs) * limit)) if limit < 1.0 else int(limit)
#         )
#     return limit

def get_sample_size(task, limit: Optional[int]) -> Union[int, None]:
    if limit is not None:
        eval_docs_length = len(list(task.eval_docs)) if isinstance(task.eval_docs, Generator) else len(task.eval_docs)
        limit = int(math.ceil(eval_docs_length * limit)) if limit < 1.0 else int(limit)
    return limit
@lintangsutawika lintangsutawika self-assigned this Jun 19, 2024
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

No branches or pull requests

2 participants