Skip to content

Conversation

@DhruvaKashyap
Copy link

Summary

Adds HFLM_Accelerate class to support models that are already wrapped with accelerate, enabling the use of simple_evaluate() with distributed and memory-optimized model instances.

Problem

Currently, simple_evaluate() only accepts models as strings or base objects, making it incompatible with models wrapped using HuggingFace's accelerate library. This limits the library's utility for distributed evaluation scenarios. Addresses Issue #3312.

Solution

  • Added new HFLM_Accelerate class in lm_eval/models/huggingface.py
  • Accepts pre-initialized PreTrainedModel, PreTrainedTokenizerBase, and Accelerator instances
  • Inherits from HFLM but skips model loading since model is already initialized
  • Maintains full compatibility with existing evaluation workflows

Usage Example

from accelerate import Accelerator
from transformers import AutoModel, AutoTokenizer
from lm_eval.models.huggingface import HFLM_Accelerate

accelerator = Accelerator()
model = AutoModel.from_pretrained("model_name")
tokenizer = AutoTokenizer.from_pretrained("model_name")

# Prepare model with accelerate
model = accelerator.prepare(model)

# Use with lm-evaluation-harness
hf_model = HFLM_Accelerate(
    pretrained=model,
    tokenizer=tokenizer, 
    accelerator=accelerator
)

- Add HFLM_Accelerate class to support models already wrapped with accelerate
- Enables simple_evaluate() to work with distributed/accelerated model instances
- Inherits from HFLM but accepts pre-initialized PreTrainedModel and Accelerator
- Maintains compatibility with existing HFLM functionality
@CLAassistant
Copy link

CLAassistant commented Sep 26, 2025

CLA assistant check
All committers have signed the CLA.

@DhruvaKashyap
Copy link
Author

Hoping that this would be a useful commit to the repository and looking forward to hearing feedback.

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.

2 participants