Skip to content

HF Adapters#39

Merged
JRosenkranz merged 35 commits into
mainfrom
add_hf_and_model_tests_with_rope_fix
Oct 2, 2023
Merged

HF Adapters#39
JRosenkranz merged 35 commits into
mainfrom
add_hf_and_model_tests_with_rope_fix

Conversation

@JRosenkranz
Copy link
Copy Markdown
Collaborator

@JRosenkranz JRosenkranz commented Sep 29, 2023

Add Huggingface Adapters along with model testing for huggingface

This PR includes:

  • HF adapter classes for encoder, decoder, encoder-decoder model architectures
  • Llama implementation of HFDecoderModelArchitecture
  • Different LM Head implementations
  • model_test_suite for huggingface configuration tests, equivalence tests, generation/batch generation tests

… is what meta uses; added readme example for hf
…sed for a type hint in llama model; now using _has_hf in conversion
…the new version of transformers which returns a different vocab size
@JRosenkranz JRosenkranz added the enhancement New feature or request label Sep 29, 2023
@JRosenkranz JRosenkranz self-assigned this Sep 29, 2023
@JRosenkranz JRosenkranz changed the title Add hf and model tests with rope fix HF Adapters Sep 29, 2023
Comment thread tests/models/hf/test_llama_hf.py Outdated
Comment thread fms/testing/_internal/hf/model_test_suite.py Outdated
Comment thread tests/models/hf/test_llama_hf.py
Comment thread fms/models/llama.py
return ibm_model, tokenizer


def convert_hf_llama(hf_model: "LlamaForCausalLM") -> LLaMA:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is fine for now but we'll want to revisit with #5

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

it could also go in llama/utils.py though? not sure if that would be preferable

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We don't have a llama folder for fms, only for hf/llama. This function is not for LLaMAHF (FMS), really it is for FMS (non-HF) LLaMA. I wonder if we should address the packaging structure for this (maybe not part of this PR), but in general.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

oh I meant hf/utils.py, looking at the left margin I thought that was in the llama folder. Does somewhere else in hf/llama not make sense? I guess just for keeping the initialization functions near each other? not a big deal, especially since we'll be changing that code later anyway.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I think if there was a general initializations utility for llama, that would be best. Not sure where to put it as we do not have an fms llama folder

Comment thread tests/models/test_llama.py
Comment thread tests/models/conftest.py Outdated
Comment thread fms/modules/positions.py Outdated
Comment thread fms/modules/positions.py Outdated
…perties for hf model_test_suite; _hf_specific_params does not have a default now (requires overriding); fixed an issue where if you run tests with --capture_expectation, runslow tests would be run
@JRosenkranz JRosenkranz requested a review from nairbv October 2, 2023 15:31
Comment thread README.md
llama: LLaMA = LLaMA(config)

# huggingface model backed by fms internals
llama_hf = LLaMAHFForCausalLM.from_fms_model(llama)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

question: is there any generic way to do this? i.e. if we write adapters for a few models, is there some way to from_fms_model(model) without first having to check which model architecture it is?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

If they conform to similar underlying api, then most likely yes. For instance, if the _helper function that is being called in _adapt had same input/output params (not necessarily the same names, but just same purpose). If they all have the same purpose and usage, we could add an implementation that can do this. It would require taking a map where it would map specific model parameters to their common parameter name. For instance, if one model uses the name x and another uses the name x_in, we can make the common name input_ids.

model = HFModel.from_fms_model(fms_model, mapper={'x': 'input_ids'})
model2 = HFModel.from_fms_model(fms_model2, mapper={'x_in': 'input_ids'})

Copy link
Copy Markdown
Contributor

@nairbv nairbv left a comment

Choose a reason for hiding this comment

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

lgtm

@JRosenkranz JRosenkranz merged commit 1a53e4e into main Oct 2, 2023
@JRosenkranz JRosenkranz deleted the add_hf_and_model_tests_with_rope_fix branch October 2, 2023 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants