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

Adding Llama Guard notebooks #400

Draft
wants to merge 29 commits into
base: main
Choose a base branch
from

Conversation

albertodepaola
Copy link
Contributor

What does this PR do?

Adds notebooks to run Llama Guard from HF or local weights. Adds validation notebook to test Llama Guard performance on a custom dataset. The dataset is not provided, example datasets to come in future versions

Feature/Issue validation/testing

Tested running both notebooks and checking the results are as expected.
For Inference, the sample prompts are run through the downloaded HF model and the results printed.
For Validation, a sample dataset is run through the model and average presicion printed as well.

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes?
  • Did you write any new necessary tests?

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the new naming convention for the files? Is it lowercase or capitalcase?

**Note on Llama Guard**
Use this command for testing with a quantized Llama model, modifying the values accordingly:

`python inference.py --model_name <path_to_regular_llama_model> --prompt_file <path_to_prompt_file> --quantization --enable_llamaguard_content_safety`
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like inference.py seems to be deleted? Where should this command be run from? Should we provide a cd instruction before python command?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the inference.py script I'm referencing here, not the one in the llama_guard directory.

@@ -2,14 +2,14 @@
<!-- markdown-link-check-disable -->
Llama Guard is a language model that provides input and output guardrails for LLM deployments. For more details, please visit the main [repository](https://github.com/facebookresearch/PurpleLlama/tree/main/Llama-Guard).

This folder contains an example file to run Llama Guard inference directly.
This folder contains example notebooks on running Llama Guard stand alone and validating Llama Guard performance against a reference dataset. The dataset is not provided, only the format in which it should be to use the scripts out of the box. Additionally, Llama Guard is being used as an optional safety checker when running the regular Llama [inference script](../../inference/local_inference/inference.py).
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we callout this can be used to convert ToxicChat dataset using script to run validation on LlamaGuard?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not intended to convert the toxic chat dataset yet, but it's the base for that in the future.


## Requirements
1. Access to Llama guard model weights on Hugging Face. To get access, follow the steps described [here](https://github.com/facebookresearch/PurpleLlama/tree/main/Llama-Guard#download)
2. Llama recipes package and it's dependencies [installed](https://github.com/albertodepaola/llama-recipes/blob/llama-guard-data-formatter-example/README.md#installation)
3. A GPU with at least 21 GB of free RAM to load both 7B models quantized.
3. A big enough GPU to load the models
Copy link
Contributor

Choose a reason for hiding this comment

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

Big enough is too vague. Can we be specific?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed!

Copy link
Contributor

@HamidShojanazeri HamidShojanazeri left a comment

Choose a reason for hiding this comment

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

@albertodepaola thanks for the PR, I wonder if there is chance we make a google colab link available for this notebook as well?

For quantization are we using bits&bytes here?

@albertodepaola albertodepaola marked this pull request as draft May 14, 2024 23:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants