Skip to content

Conversation

@quic-swatia
Copy link
Contributor

@quic-swatia quic-swatia commented Dec 9, 2025

  • Added Base Model class and HF model class.
  • Base Model class will support FT for any custom model and will be a common skeleton for any model, including HF.
  • Added unit tests for these.

Signed-off-by: Swati Allabadi <[email protected]>
Signed-off-by: Swati Allabadi <[email protected]>
Copy link
Contributor

@quic-meetkuma quic-meetkuma left a comment

Choose a reason for hiding this comment

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

Please use your reference code wisely. The implementation lacks main functionalities. The tests are not extensive and implemented in naive manner. Please correct them as well.

Reference code: https://github.com/quic-meetkuma/LightningLLMs/blob/hf_trainer/LightningLLM/components/model.py

return self._model

@property
def tokenizer(self) -> Any:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is applicable for NLP models. We can't put it in BaseClass. Better to create an abstract method called "preprocessor" which defines generic preprocessing function applicable for the model. There wont be any implementation here but the children class should implement that. In case of LLMs, this method should return tokenizer.

@abstractmethod
def load_model(self) -> nn.Module:
"""Create and return the underlying torch.nn.Module."""
...
Copy link
Contributor

Choose a reason for hiding this comment

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

use "pass" as it is explicit.

Copy link
Contributor Author

@quic-swatia quic-swatia Dec 19, 2025

Choose a reason for hiding this comment

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

Updated in latest, doesn't make any difference though. Both syntax are valid.


# get_input_embeddings: underlying model lacks method, should warn and return None
with mock.patch("QEfficient.finetune.experimental.core.model.logger.info") as mocked_log:
assert m.get_input_embeddings() is None
Copy link
Contributor

Choose a reason for hiding this comment

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

create a proper dummy model which returns some embeddings rather than None. Your test should use HFModel class instead of some dummy class.

raising=False,
)

m = HFModel.create("hf-name")
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to call individual class's create method. There is a reason to use a registry functionality.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Purpose of create is different than component_registry. Explained in another comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

Move it to ComponentFactory and then instantiate from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Replied above.

tok = m.load_tokenizer()

# tokenizer was loaded and pad token inserted
model.AutoTokenizer.from_pretrained.assert_called_once_with("hf-name")
Copy link
Contributor

Choose a reason for hiding this comment

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

Dont write such tests filled with assert_called_once etc.. We have written such tests in past but that was not an appropriate thing. It was a makeshift arrangement because of monolith structure of code. Write extensive and proper tests. If a function has made some changes to the model's structure then use that to test rather then counting how many times the function gets called.



@registry.model("hf")
class HFModel(BaseModel):
Copy link
Contributor

Choose a reason for hiding this comment

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

We need to load the model based on configuration as well. That is mainly for testing purpose. In integration tests we will not load an entire model consists of 32 layers. But we will only load the same model with 2 or 4 layers and do further testing. For that purpose config should be used to load the model. Check huggingface documentation on how to do that.

Signed-off-by: Swati Allabadi <[email protected]>
@quic-swatia quic-swatia marked this pull request as draft December 19, 2025 10:43
@quic-swatia quic-swatia force-pushed the model_classes_exp branch 3 times, most recently from dddb4e7 to a963119 Compare December 25, 2025 01:01
Signed-off-by: Swati Allabadi <[email protected]>
@quic-swatia quic-swatia marked this pull request as ready for review December 25, 2025 01:07
@quic-swatia quic-swatia merged commit 866a140 into quic:ft_experimental Dec 25, 2025
3 checks passed
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.

2 participants