I am trying to do llama model inference: Local Inference Hugging face setup Important…
- User
I am trying to do llama model inference: Local Inference Hugging face setup Important Note: Before running the inference, you'll need your Hugging Face access token, which you can get at your Settings page here. Then run huggingface-cli login and copy and paste your Hugging Face access token to complete the login to make sure the scripts can download Hugging Face models if needed.
Multimodal Inference For Multi-Modal inference we have added multi_modal_infer.py which uses the transformers library.
The way to run this would be:
python multi_modal_infer.py --image_path PATH_TO_IMAGE --prompt_text "Describe this image" --temperature 0.5 --top_p 0.8 --model_name "meta-llama/Llama-3.2-11B-Vision-Instruct" Multi-modal Inferencing Using gradio UI for inferencing For multi-modal inferencing using gradio UI we have added multi_modal_infer_gradio_UI.py which used gradio and transformers library.
Steps to Run The way to run this would be:
Ensure having proper access to llama 3.2 vision models, then run the command given below python multi_modal_infer_gradio_UI.py --hf_token Text-only Inference For local inference we have provided an inference script. Depending on the type of finetuning performed during training the inference script takes different arguments.
To finetune all model parameters the output dir of the training has to be given as --model_name argument. In the case of a parameter efficient method like lora the base model has to be given as --model_name and the output dir of the training has to be given as --peft_model argument. Additionally, a prompt for the model in the form of a text file has to be provided. The prompt file can either be piped through standard input or given as --prompt_file parameter.
Content Safety The inference script also supports safety checks for both user prompt and model outputs. In particular, we use two packages, AuditNLG and Azure content safety.
Note If using Azure content Safety, please make sure to get the endpoint and API key as described here and add them as the following environment variables,CONTENT_SAFETY_ENDPOINT and CONTENT_SAFETY_KEY.
Examples:
Full finetuning of all parameters cat | python inference.py --model_name <training_config.output_dir> --use_auditnlg
PEFT method cat | python inference.py --model_name <training_config.model_name> --peft_model <training_config.output_dir> --use_auditnlg
prompt as parameter python inference.py --model_name <training_config.output_dir> --prompt_file --use_auditnlg The folder contains test prompts for summarization use-case:
samsum_prompt.txt ... Note on Llama version < 3.1 The default padding token in HuggingFace Tokenizer is None. To use padding the padding token needs to be added as a special token to the tokenizer, which in this case requires to resize the token_embeddings as shown below:
tokenizer.add_special_tokens( {
code - Assistant
- User
- Assistant
The error message you're seeing indicates that the script is trying to use a chat template function for tokenizing the input dialogues, but the necessary configuration is missing. This configuration is typically present in tokenizer settings for models that support chat-based interaction. Here’s what you can do to resolve this issue: