Skip to content

added hf adapter classes and llama hf implementation; added model testing suite#2

Closed
JRosenkranz wants to merge 17 commits into
mainfrom
add_hf_and_model_tests
Closed

added hf adapter classes and llama hf implementation; added model testing suite#2
JRosenkranz wants to merge 17 commits into
mainfrom
add_hf_and_model_tests

Conversation

@JRosenkranz
Copy link
Copy Markdown
Collaborator

Added the huggingface adapters along with model testing.

@JRosenkranz JRosenkranz added the enhancement New feature or request label Aug 31, 2023
@JRosenkranz JRosenkranz requested a review from nairbv August 31, 2023 18:01
@JRosenkranz JRosenkranz self-assigned this Aug 31, 2023
Comment thread fms/models/llama.py Outdated
**kwargs,
) -> BaseModelOutputWithPastAndCrossAttentions:
output = self.model(
output = self.model._helper(
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.

ah, clearer seeing your motive in context.

Comment thread fms/models/llama.py
Comment thread fms/models/llama.py Outdated

import torch
import torch.nn as nn
from transformers import LlamaForCausalLM
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.

I think it's cleaner if the model code is independent, without first needing to import HF. maybe convert_hf_llama should be in a different file?

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.

ya that is an option, not sure where we want to put it, maybe we create a separate file called model_utils that has this for multiple different models?

Comment thread fms/models/llama.py Outdated
"""

if not _has_hf:
raise ImportError("in order to convert huggingface weights, you need to have transformers installed")
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.

I think it's worth separating the HF code from the main code, i.e. putting this function in a separate file from the model code.

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 this has a place here, its providing a utility to load an FMS model from a huggingface model (not related to FMS Huggingface). If we move this, we maybe should move the meta load as well. One possibility is we add some form of FMS model creation utility.

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.

moving both is fine too

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I can make the PR for moving both to different files

Comment thread tests/models/base.py Outdated

import pytest


Copy link
Copy Markdown
Contributor

@nairbv nairbv Sep 7, 2023

Choose a reason for hiding this comment

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

is this code related to HF equivalence? if so we should put it in that dir. otherwise it could be confusing if we add any other kind of model tests in this dir.
(and if it's not HF code, maybe should be a separate PR?)
I think I've already reviewed all of the actual code in an internal copy, but I'd like to keep it mostly consolidated in a directory. I think it'll be confusing if it's interspersed with other tests and code.

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.

this base is related to model consistency as well, it can be used with both. Note this PR: #9

This has no HF related code in it, just the non-hf and it uses the same classes.

Comment thread tests/models/test_config.py Outdated
from fms.utils.config import ModelConfig
from tests.models.base import ModelBase


Copy link
Copy Markdown
Contributor

@nairbv nairbv Sep 7, 2023

Choose a reason for hiding this comment

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

Same idea here as above, I think we should use a directory to make it clear that there's a suite of tests specifically testing equivalence to HF (and include that and only that in this PR).

Just looking at the file names/paths one might assume we have "test_config.py" for testing utils/config.py independently, and then separately there's a test_hf_config for testing hf config equivalence. but they're both added as part of this HF PR and I think are actually both related to HF.

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.

test_config is only related to our fms model config, test_hf_config includes our model config as well as hf config tests i believe

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I agree that HF tests in general should be in an HF folder, with things like hf_equivalence, hf_config, hf_model becoming subfolders of this hf folder, and becoming hf/equivalence, etc.

@JRosenkranz
Copy link
Copy Markdown
Collaborator Author

This is being replaced by #39

ani300 pushed a commit that referenced this pull request Jul 1, 2025
Signed-off-by: Sahil Suneja <suneja@us.ibm.com>
JRosenkranz pushed a commit that referenced this pull request Jul 23, 2025
* adding siglip vision support

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* import fix

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* update attn_kwargs

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* ruff

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding tests

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* ruff format

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* test update

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* addressing review comments

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* siglip updates post  review #2

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding fms/models/llava_next

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding fms/models/llava_next

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* update attn_kwargs

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* ruff

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding tests for llava_next

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* rebasing on siglip branch + addressing review comments

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* rebse atop siglip #2

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding hf bs fms output equivalence test

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* moving imports to make build framework happy during testing

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* pytest.mark.slow

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* addressing review comments

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* mypy

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding HF config loading via hf_pretrained

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* percolate unfuse_weights to constituents

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* hf config loading check

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* recursive model config mapping

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* removing loops

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* fix graph break

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* combining input_ids and inputs_embeds args

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

---------

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>
Co-authored-by: Antoni Viros <aviros@ibm.com>
nirajkamal pushed a commit to nirajkamal/foundation-model-stack that referenced this pull request Sep 15, 2025
* adding siglip vision support

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* import fix

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* update attn_kwargs

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* ruff

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding tests

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* ruff format

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* test update

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* addressing review comments

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* siglip updates post  review foundation-model-stack#2

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding fms/models/llava_next

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding fms/models/llava_next

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* update attn_kwargs

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* ruff

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding tests for llava_next

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* rebasing on siglip branch + addressing review comments

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* rebse atop siglip foundation-model-stack#2

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding hf bs fms output equivalence test

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* moving imports to make build framework happy during testing

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* pytest.mark.slow

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* addressing review comments

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* mypy

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* adding HF config loading via hf_pretrained

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* percolate unfuse_weights to constituents

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* hf config loading check

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* recursive model config mapping

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* removing loops

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* fix graph break

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

* combining input_ids and inputs_embeds args

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>

---------

Signed-off-by: Sahil Suneja <suneja@us.ibm.com>
Co-authored-by: Antoni Viros <aviros@ibm.com>
Signed-off-by: Niraj Kamal Karunanidhi <nirajkkamal@gmail.com>
Lucas-Qian6 pushed a commit to Lucas-Qian6/Heterogeneous-setup-in-foundation-model-stack that referenced this pull request Dec 17, 2025
maxdebayser pushed a commit to maxdebayser/foundation-model-stack that referenced this pull request Mar 23, 2026
…beddings

Fix weight loading to be compatible with FMS RoPE
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.

3 participants