Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

One shot user flow tweaks #2195

Closed
wants to merge 3 commits into from
Closed

Conversation

robertgshaw2-redhat
Copy link
Contributor

@robertgshaw2-redhat robertgshaw2-redhat commented Mar 23, 2024

Enables:

  • applying one shot to BERT (previously would fail b/c labels are not allowed to be passed to BERT)
  • calling export on a model rather than on a file path (previously would fail during helper_functions.create_data_loader b/c sequence_length is calculated during helper_functions.create_model, which does not run if a model is passed to export

Also, there seems to be a stray import from sparsezoo which is failing

  • Note: need to check whether the labels change impacts the LLMs (though I don't think the labels are used here)

@robertgshaw2-redhat
Copy link
Contributor Author

  • Recipe:
test_stage:
  obcq_modifiers:
    QuantizationModifier:
      ignore:
        - Tanh
        - GELUActivation
      post_oneshot_calibration: true
      scheme_overrides:
        # For the embeddings, only weight-quantization makes sense
        Embedding:
          input_activations: null
          weights:
            num_bits: 8
            symmetric: false
    SparseGPTModifier:
      sparsity: 0.0
      quantize: true
      targets: ["re:encoder.layer.\\d+$"]
  • Script
from sparseml.transformers import oneshot
from sparseml import export

from transformers import AutoModel, AutoTokenizer
from datasets import load_dataset

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("--recipe-path", type=str)

MODEL_ID = "sentence-transformers/all-MiniLM-L6-v2"
DATASET_ID = "neural-bridge/rag-dataset-12000"
NUM_SAMPLES = 512

if __name__ == "__main__":
    args = parser.parse_args()

    model = AutoModel.from_pretrained(MODEL_ID)
    tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)

    ds = load_dataset(DATASET_ID, split="train")
    ds = ds.shuffle(seed=42).select(range(NUM_SAMPLES))
    ds = ds.rename_column("context", "text")

    oneshot(
        model=model,
        tokenizer=tokenizer,
        dataset=ds,
        recipe=args.recipe_path,
        output_dir="./minilm-int8-pt",
        max_seq_length=model.config.max_position_embeddings,
        concatenate_data=False,
    )

    export(model=model, integration="transformers", task="mlm", target_path="example_export")
  • To run:
python3 example.py --recipe-path recipe.yaml

"Provide it manually using sequence_length argument"
)
if hasattr(model.config, "max_position_embeddings"):
sequence_length = model.config.max_position_embeddings
Copy link
Member

Choose a reason for hiding this comment

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

Add a _LOGGER.info here that you are using the default and what the value is

Comment on lines +154 to +156
tokenized_dataset = self.get_dataset_split("calibration")
if "labels" in tokenized_dataset.column_names:
tokenized_dataset = tokenized_dataset.remove_columns("labels")
Copy link
Member

Choose a reason for hiding this comment

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

what is the issue here? if this is relatively safe to keep, then leave a comment on why this specific column needs to be removed

@@ -20,7 +20,7 @@
from sparseml.transformers.utils.preprocessing_functions import (
PreprocessingFunctionRegistry,
)
from sparsezoo.utils.helpers import import_from_path
# from sparsezoo.utils.helpers import import_from_path
Copy link
Member

Choose a reason for hiding this comment

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

what is the issue here?

Copy link

Choose a reason for hiding this comment

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

If this was giving you issue might be a sparsezoo version issue

@robertgshaw2-redhat
Copy link
Contributor Author

Sorry - I didn't mean to put a PR on this ... I was just trying to hack something together. Will close

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.

3 participants