"official/legacy/image_classification/classifier_trainer.py" did not exist on "b3ab207490151472ff7be056445c361a516c51b8"
model_guide.md 3.76 KB
Newer Older
haileyschoelkopf's avatar
haileyschoelkopf committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# New Model Guide

The `lm-evaluation-harness` is intended to be a model-agnostic framework for evaluating . We provide first-class support for HuggingFace `AutoModelForCausalLM` and `AutoModelForSeq2SeqLM` type models, but

This guide may be of special interest to users who are using the library outside of the repository, via installing the library via pypi and calling `lm_eval.evaluator.evaluate()` to evaluate an existing model.

In order to properly evaluate a given LM, we require implementation of a wrapper class subclassing the `lm_eval.api.model.LM` class, that defines how the Evaluation Harness should interface with your model. This guide walks through how to write this `LM` subclass via adding it to the library!

## Setup

To get started contributing, go ahead and fork the main repo, clone it, create a branch with the name of your task, and install the project requirements in your environment:

```sh
# After forking...
git clone https://github.com/<YOUR-USERNAME>/lm-evaluation-harness.git
cd lm-evaluation-harness
git checkout big-refactor
git checkout -b <model-type>
pip install -e ".[dev]"
```

Now, we'll create a new file where we'll be adding our model:

```sh
touch lm_eval/models/<my_model_filename>.py
```

**Tip: this filename should not shadow package names! For example, naming your file `anthropic.py` is disallowed since the API's name on pypi is `anthropic`, but naming it `anthropic_llms.py` works with no problems.**

## Interface

All models must subclass the `lm_eval.api.model.LM` class.

The LM class enforces a common interface via which we can extract responses from a model:

```python
class MyCustomLM(LM):
    #...
baberabb's avatar
baberabb committed
39
40
    def loglikelihood(self, requests: list[Instance]) -> list[tuple[float, bool]]:
        #...
haileyschoelkopf's avatar
haileyschoelkopf committed
41
42


baberabb's avatar
baberabb committed
43
44
    def loglikelihood_rolling(self, requests: list[Instance]) -> list[tuple[float, bool]]:
        #...
haileyschoelkopf's avatar
haileyschoelkopf committed
45
46


baberabb's avatar
baberabb committed
47
48
    def greedy_until(self, requests: list[Instance]) -> list[str]:
        #...
haileyschoelkopf's avatar
haileyschoelkopf committed
49
50
    #...
```
baberabb's avatar
baberabb committed
51
Where `Instance` is a dataclass defined in [`lm_eval.api.instance`](https://github.com/EleutherAI/lm-evaluation-harness/blob/big-refactor/lm_eval/api/instance.py) with property `args` which returns a tuple of (context, continuation).
haileyschoelkopf's avatar
haileyschoelkopf committed
52

lintangsutawika's avatar
lintangsutawika committed
53
We support
haileyschoelkopf's avatar
haileyschoelkopf committed
54

lintangsutawika's avatar
lintangsutawika committed
55
The three types of
haileyschoelkopf's avatar
haileyschoelkopf committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70



smth smth tokenizer-agnostic

3 reqtypes
- greedy_until, and the arguments passed to it

- loglikelihood, and args passed to it

- loglikelihood_rolling, and args passed to it


## Registration

lintangsutawika's avatar
lintangsutawika committed
71
Congrats on implementing your model! Now it's time to test it out.
haileyschoelkopf's avatar
haileyschoelkopf committed
72

lintangsutawika's avatar
lintangsutawika committed
73
To make your model usable via the command line interface to `lm-eval` using `main.py`, you'll need to tell `lm-eval` what your model's name is.
haileyschoelkopf's avatar
haileyschoelkopf committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93

This is done via a *decorator*, `lm_eval.api.registry.register_model`. Using `register_model()`, one can both tell the package what the model's name(s) to be used are when invoking it with `python main.py --model <name>` and alert `lm-eval` to the model's existence.

```python
from lm_eval.api.registry import register_model

@register_model("<name1>", "<name2>")
class MyCustomLM(LM):
```

Using this decorator results in the class being added to an accounting of the usable LM types maintained internally to the library at `lm_eval.api.registry.MODEL_REGISTRY`. See `lm_eval.api.registry` for more detail on what sorts of registries and decorators exist in the library!



## Other

**Pro tip**: In order to make the Evaluation Harness overestimate total runtimes rather than underestimate it, HuggingFace models come in-built with the ability to provide responses on data points in *descending order by total input length* via `lm_eval.utils.Reorderer`. Take a look at `lm_eval.models.hf_causal.HFLM` to see how this is done, and see if you can implement it in your own model!

## Conclusion

lintangsutawika's avatar
lintangsutawika committed
94
After reading this guide, you should be able to add new model APIs or implementations to the Eval Harness library!