Skip to content

test: Add tests for save_for_aiu functionality w/ tiny models#126

Merged
BrandonGroth merged 16 commits into
foundation-model-stack:mainfrom
BrandonGroth:tiny_models
Jun 9, 2025
Merged

test: Add tests for save_for_aiu functionality w/ tiny models#126
BrandonGroth merged 16 commits into
foundation-model-stack:mainfrom
BrandonGroth:tiny_models

Conversation

@BrandonGroth

@BrandonGroth BrandonGroth commented May 20, 2025

Copy link
Copy Markdown
Collaborator

Description of the change

Added a new tests/models named test_save_aiu.py. This includes implementing new "tiny" models for BERT, Llama, and Granite from custom configs that are trimmed down.

Also, several test files have been cleaned up with the new autouse=True fixture for file deletion before a test starts.

How to verify the PR

Change to tests/models and run pytest test_save_aiu.py

Was the PR tested

  • I have ensured all unit tests pass

Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
…g, and changed qconfig_save warning to logger.info

Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
…tting

Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
else:
self.register_buffer(
"clip_val", torch.zeros(perCh) if perCh else torch.Tensor([1.0])
"clip_val", torch.zeros(perCh) if perCh else torch.Tensor([0.0])

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.

Uninitialized clip_vals are supposed to be zero tensors, but for some reason this one was set to 1.0. This is consistent for other quantizers currently.

Comment thread tests/models/conftest.py
dataset,
batch_size=batch_size,
shuffle=False,
collate_fn=lambda batch: tuple(torch.stack(samples) for samples in zip(*batch)),

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 collate_fn was needed to return a tuple(tensor, tensor) as stated in the comment above.

Comment thread tests/models/test_model_utils.py Outdated
Comment thread tests/models/test_save_aiu.py Outdated
Comment thread tests/models/test_save_aiu.py Outdated
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>
Comment thread tests/models/test_save_aiu.py Outdated
Signed-off-by: Brandon Groth <brandon.m.groth@gmail.com>

@andrea-fasoli andrea-fasoli left a comment

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.

these unit tests for save_for_aiu look good to me now!

Returns:
dict: Model state dictionary
"""
return torch.load(fname, weights_only=True)

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.

do we need a func for a one-liners?

Comment thread tests/models/test_mx.py
"""
Delete any known files lingering before starting test
"""
delete_file("qcfg.json")

@chichun-charlie-liu chichun-charlie-liu Jun 9, 2025

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.

seems like the purpose is to auto-apply this init-like func before every tests? maybe the we can rename it to something more generic, so we could do more than just delete files if needed?

"""
Delete any known files lingering before starting test
"""
delete_file("qcfg.json")

@chichun-charlie-liu chichun-charlie-liu Jun 9, 2025

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.

same as above



@pytest.fixture(autouse=True)
def delete_files():

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.

same as above

@BrandonGroth BrandonGroth merged commit 957173c into foundation-model-stack:main Jun 9, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants