EleutherAI / lm-evaluation-harness

A framework for few-shot evaluation of language models.
https://www.eleuther.ai
MIT License
6.99k stars 1.87k forks source link

Add a way to instantiate from HF.AutoModel (again) #1978

Closed dmitrii-palisaderesearch closed 5 months ago

dmitrii-palisaderesearch commented 5 months ago

Hi,

I was looking to run simple_evaluate with my own transformers model and found #521 / #601, but it looks like they're only merged to master. Was this feature lost in the 0.4.0 migration? Should I port it?

haileyschoelkopf commented 5 months ago

Hi! This should be supported via the HF model type in main as well -- https://github.com/EleutherAI/lm-evaluation-harness/blob/f257d38b66f00f544aab5817fe66eb9fe78a8b0f/lm_eval/models/huggingface.py#L81 and we have people who use this feature. Does using this work for you?

dmitrii-palisaderesearch commented 5 months ago

Ohh, thank you, I was confused by the API there.

For anyone who was confused like me, it's

model = transformers.AutoModelForCausalLM.from_pretrained(...)
lm_eval.simple_evaluate(
    model=lm_eval.models.huggingface.HFLM(model)
)

And here's what you would do to run inference with unsloth:

from unsloth import FastLanguageModel
import lm_eval

model, tokenizer = FastLanguageModel.from_pretrained(
    model_name = "unsloth/llama-3-8b-Instruct-bnb-4bit",
    max_seq_length = 8192,
    load_in_4bit = True,
)

results = lm_eval.simple_evaluate(
    model=lm_eval.models.huggingface.HFLM(
        pretrained=model,
        tokenizer=tokenizer,
    ),
)
abdalgader-a commented 4 months ago

@dmitrii-palisaderesearch - have you run the script via accelerate ?

dmitrii-palisaderesearch commented 4 months ago

Nope, the above was plain Colab. I believe you can leverage accelerate by passing FastLanguageModel.from_pretrained(device_map=XXX) though.