Skip to content

Commit

Permalink
[Oneshot Refactor] Rename get_shared_processor_src to get_processor_n…
Browse files Browse the repository at this point in the history
…ame_from_model (#1108)

ORDER OF REVIEWS:
1. #1108 <- current
PR
2. #1103
3. #1109
4. #1110

SUMMARY:
* Rename `get_shared_processor_src` to `get_processor_from_model`
* Appropriate signature on `initialize_processor_from_path`, where
`teacher` should be optinal


TEST PLAN:
* Pass all existing tests
* Search `get_shared_processor_src` using pygrep
```bash
  3 function pygrep() {
  2     local search_term="$1"
  1     shift
126     local search_dirs="${*:-src examples tests}"                           
  1     grep -rn --include="*.py" -E "$search_term" $search_dirs
  2 }
```

---------

Co-authored-by: Dipika Sikka <dipikasikka1@gmail.com>
  • Loading branch information
horheynm and dsikka authored Feb 5, 2025
1 parent f807a2a commit caee1c8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/llmcompressor/transformers/finetune/text_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import os
import warnings
from pathlib import PosixPath
from typing import Optional

from loguru import logger
from transformers import (
Expand Down Expand Up @@ -51,7 +52,7 @@
patch_tied_tensors_bug,
)
from llmcompressor.transformers.sparsification.sparse_model import (
get_shared_processor_src,
get_processor_name_from_model,
)
from llmcompressor.transformers.utils.helpers import (
detect_last_checkpoint,
Expand Down Expand Up @@ -257,10 +258,13 @@ def initialize_model_from_path(


def initialize_processor_from_path(
model_args: ModelArguments, model: PreTrainedModel, teacher: PreTrainedModel
model_args: ModelArguments,
model: PreTrainedModel,
teacher: Optional[PreTrainedModel] = None,
) -> Processor:
processor_src = model_args.processor
processor_src = processor_src or get_shared_processor_src(model, teacher)
processor_src = model_args.processor or get_processor_name_from_model(
model, teacher
)
# The use_fast=True option is not currently supported safely in Transformers
# See: https://github.com/huggingface/transformers/pull/34836#issuecomment-2491809727 # noqa: E501
try:
Expand Down
4 changes: 2 additions & 2 deletions src/llmcompressor/transformers/sparsification/sparse_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

__all__ = [
"SparseAutoModelForCausalLM",
"get_shared_processor_src",
"get_processor_name_from_model",
]


Expand All @@ -20,7 +20,7 @@ def from_pretrained(*args, **kwargs):
return AutoModelForCausalLM.from_pretrained(*args, **kwargs)


def get_shared_processor_src(student: Module, teacher: Optional[Module]) -> str:
def get_processor_name_from_model(student: Module, teacher: Optional[Module]) -> str:
"""
Get a processor/tokenizer source used for both student and teacher, assuming
that they could be shared
Expand Down

0 comments on commit caee1c8

Please sign in to comment.