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

Eval local HF models with flag, add LLaMA and Alpaca #1505

Merged
merged 55 commits into from
Jun 30, 2023
Merged

Conversation

julian-q
Copy link
Contributor

@julian-q julian-q commented Apr 24, 2023

Addresses #1486 and adds LLaMA and Alpaca

This PR allows you to evaluate any HuggingFace model you have stored on the machine which you are running HELM.

Instructions

You have two options for telling HELM where your model is stored:

  1. specify the path(s) of your local model(s) via the command-line flag --enable-local-huggingface-models <path 1> [<path 2> ...]
  2. place the model (or a symlink to it) in the default directory. Currently, this is ./huggingface_models, which is set by the constant LOCAL_HUGGINGFACE_MODEL_DIR in huggingface_model_registry.py. This only works for the local models that are already listed in models.py since they need to be in ALL_MODELS in order to create RunSpecs. Currently I've listed huggingface/llama-7b, huggingface/alpaca-7b.

Then, you can refer to your model in any run specs as huggingface/<model_name>, where <model_name> either comes from models.py or is the name of the directly containing directory in the path specified with --enable-local-huggingface-models . For example, if I pass --enable-local-huggingface-models /home/quevedo/llama-13b, I can refer to this model in a run spec as huggingface/llama-13b.

Feedback request

Making the command line option optional led to some messy code, Is there any way we can avoid having to recreate the HuggingFaceModelConfig multiple times throughout the code? Maybe I can register the model beforehand, as if the user registered it with the flag. Now we pre-register local models from models.py in the _huggingface_model_registry dict.

DavdGao added a commit to DavdGao/helm that referenced this pull request Apr 27, 2023
@julian-q julian-q marked this pull request as ready for review May 9, 2023 18:57
Copy link
Collaborator

@yifanmai yifanmai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks promising!

src/helm/proxy/retry.py Outdated Show resolved Hide resolved
@@ -10,6 +10,8 @@
FULL_FUNCTIONALITY_TEXT_MODEL_TAG,
)

# The path where local HuggingFace models should be downloaded or symlinked, e.g. ./helm-models/llama-7b
LOCAL_MODEL_DIR = "./helm-models"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"./huggingface_models"?

Reasoning:

  • _ for consistency with prod_env and benchmark_output
  • huggingface for clarity that this only supports huggingface format
  • Don't need helm because we are already in a HELM working directory

Model(
group="local",
creator_organization="Meta",
name="local/llama-7b",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these should all be group="huggingface" and name="huggingface/llama-7b" for consistency.

I would like this to be meta/llama-7b but unfortunately the pre-existing code base ties the group to the "client" used to serve the model, which is why we have huggingface/gpt2 instead of openai/gpt2 or together/t5-11b instead of google/t5-11b. I would like to make everything be the correct group eventually, but for now we should be consistent with existing conventions. It's also not obvious to me that "local" means "local Hugging Face" as opposed to "local some other framework".

Also unfortunately these model names are annoying to change because we have to do a MongoDB migration every time we change one of these.

cc @percyliang for opinions about naming

src/helm/proxy/models.py Outdated Show resolved Hide resolved
src/helm/proxy/models.py Outdated Show resolved Hide resolved
src/helm/proxy/clients/huggingface_client.py Show resolved Hide resolved
src/helm/proxy/clients/huggingface_model_registry.py Outdated Show resolved Hide resolved
src/helm/proxy/models.py Outdated Show resolved Hide resolved
src/helm/proxy/models.py Outdated Show resolved Hide resolved
src/helm/proxy/models.py Outdated Show resolved Hide resolved
@DavdGao
Copy link

DavdGao commented May 10, 2023

I notice that in huggingfaceserver, all the models are loaded in "cuda:0". Since we will run the model locally (maybe with --num-threads > 1), maybe it's better to load the mode into different gpus?

Copy link
Contributor

@JosselinSomervilleRoberts JosselinSomervilleRoberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the status of this?
I know we said we wanted to move fast on adding new models but maybe I should wait for the changes to be made and the PR to be merged before diving deep into this?
@yifanmai what do you think?

Comment on lines 71 to 73
elif organization == "local":
# HACK since we want to use the huggingface sqlite file. TODO avoid this
client = HuggingFaceClient(cache_config=cache_config)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we not planning to have other local models than HuggingFace btw?

src/helm/proxy/clients/auto_client.py Outdated Show resolved Hide resolved
src/helm/proxy/clients/huggingface_client.py Outdated Show resolved Hide resolved
src/helm/proxy/clients/huggingface_client.py Outdated Show resolved Hide resolved
src/helm/proxy/clients/huggingface_client.py Outdated Show resolved Hide resolved
@@ -28,6 +30,9 @@ class HuggingFaceModelConfig:

If None, use the default revision."""

path: Optional[str] = None
"""Local path to the Hugging Face model weights"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the default path here: ./huggingface_models

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I added a comment explaining how this parameter is set and what it means:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't set it directly to the local path by default (like path: str = ./huggingface_models) because None means to load it from the hub instead.

src/helm/proxy/clients/huggingface_model_registry.py Outdated Show resolved Hide resolved
model_name = match.group("model_name")
assert model_name
return HuggingFaceModelConfig(
namespace="local",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we put something more explicit? I personally feel like "None" is not super clear. Could we maybe put something like "internal"? "local-model"?

src/helm/proxy/retry.py Outdated Show resolved Hide resolved
Copy link
Contributor

@JosselinSomervilleRoberts JosselinSomervilleRoberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the status of this?
I know we said we wanted to move fast on adding new models but maybe I should wait for the changes to be made and the PR to be merged before diving deep into this?
@yifanmai what do you think?



def _get_singleton_server(model_config: HuggingFaceModelConfig) -> HuggingFaceServer:
global _servers_lock
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: docstring should go after the method definition. See PEP 257

def _get_singleton_server(model_config: HuggingFaceModelConfig) -> HuggingFaceServer:
    """Lookup or create a new HuggingFaceServer that will be shared among all threads.

    When --num-threads > 1, multiple threads will attempt to instantiate etc."""

)
else:
raise Exception(f"Unknown HuggingFace model: {model}")

return self.model_server_instances[model]
else:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The else is still here...

@yifanmai yifanmai merged commit 3cd8573 into main Jun 30, 2023
@yifanmai yifanmai deleted the local-hf-models branch June 30, 2023 17:15
@julian-q
Copy link
Contributor Author

julian-q commented Jul 3, 2023

Thank you for helping get this merged @yifanmai !

@patrickc3000
Copy link

Is --enable-local-huggingface-models still available in the latest version of Helm?

@yifanmai
Copy link
Collaborator

Hi, it will be included in v0.2.3, which should be released later this week.

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.

6 participants