Mac M1 + Ollama + Llama 3.1: A 30-minute guide to quickly install and configure Llama 3.1 with Chinese language support

Authors

Meta recently released Llama 3.1, but its performance in Chinese processing is mediocre. Fortunately, a fine-tuned, Chinese-supported version of Llama 3.1 is now available on Hugging Face. This article will guide you step-by-step on how to install this powerful model on your Mac and conduct detailed tests, allowing you to enjoy a smooth Chinese AI experience effortlessly. Ready? Let’s get started!

Install Ollama

Ollama is a powerful machine learning model management tool that helps us quickly install and manage various large language models. Here are the steps to install Ollama:

macOS

Download Ollama for macOS - https://ollama.com/download/Ollama-darwin.zip

Windows

Download Ollama for Windows - https://ollama.com/download/OllamaSetup.exe

Linux

Download and install Ollama for Linux

curl -fsSL https://ollama.com/install.sh | sh

After installation, run the following command to check if it is installed correctly.

$ ollama -v
ollama version is 0.2.1

Install Llama3.1-8B-Chinese-Chat Model

After installing Ollama, we can quickly install shenzhi-wang's Llama3.1-8B-Chinese-Chat model through Ollama. First, find the Llama3.1-8B-Chinese-Chat download page on Hugging Face and download the model. Download link: shenzhi-wang/Llama3.1-8B-Chinese-Chat · Hugging Face

macm1ollamallama31a3-0
macm1ollamallama31a3-2

Import the Model

The locally downloaded model files cannot be directly imported into Ollama, and a configuration file needs to be written. Name it anything you like, such as config.txt, and the content of the configuration file is as follows:

FROM "/Users/zhanghuan/ollama/llama3.1_8b_chinese_chat_q8_0.gguf"

TEMPLATE """{{- if .System }}
system {{ .System }}
{{- end }}
user
{{ .Prompt }}
assistant
"""

SYSTEM """"""

PARAMETER stop 
PARAMETER stop 

First, make sure that the model file path in the first line FROM "..." has been modified according to your actual situation. The rest of the template content has been optimized and does not require any changes.

Then, simply run the following command to easily import your model:

ollama create llama3-zh -f ./config.txt
macm1ollamallama31a3-3

llama3-zh is the name we gave to the model. After a successful import, you can use the list command to check:

$ ollama list
macm1ollamallama31a3-4

You can download multiple models, write a configuration file for each model (just modify the path), and give different names when importing. This way, we can conveniently run various models using Ollama.

Run the Model

After the model is installed, we can start the model and test it with the following command:

ollama run llama3-zh

Model Testing and Application

Once the model is started, you can interact with it via the command line, input Chinese questions, and get responses from the model. For example:

macm1ollamallama31a3-5

The model will generate corresponding responses. You can also integrate the model into your applications, such as chatbots, intelligent customer service, etc., to enhance the intelligence of your applications.

You can also use the curl command to use the model through the HTTP interface.

$ curl -L 'http://localhost:11434/api/generate' \
> -H 'Content-Type: application/json' \
> -d '{
>     "model": "llama3-zh:latest",
>     "prompt": "How to handle workplace conflicts?",
>     "format": "json",
>     "stream": false
> }'
{"model":"llama3-zh:latest","created_at":"2024-07-09T12:13:05.90114Z","response":"{ \"message\": \"Handling conflicts in the workplace is an important skill. Here are some strategies that may help you resolve conflicts: \\r\\n\\r\\n1. **Listen to the other party** - Give your colleague a chance to express their views and concerns in detail. You can show that you are listening by repeating, summarizing, or asking questions. \\r\\n2. **Stay calm** - Try not to let emotions affect the conversation. Take deep breaths and give yourself time to calm down so you can address the issue more systematically. \\r\\n3. **Find common ground** - Try to find things both parties agree on. This can help create a collaborative atmosphere and make negotiations easier. \\r\\n4. **Use "I" language** - Use "I feel..." or "I think..." instead of "You always...", which can reduce accusations and keep the conversation constructive. \\r\\n5. **Propose solutions** - Once you understand the other party's issues and concerns, you can propose possible solutions. Ensure these suggestions are specific, feasible, and consider both parties' interests. \\r\\n6. **Seek third-party help** - If the conflict is severe or you feel unable to handle it, seeking a neutral third party (such as an HR representative or career counselor) may be a good idea. They can offer professional advice and intervene if necessary. \\r\\n7. **Maintain respect and honesty** - Maintain respect and honesty in the conversation, even if you disagree with the other party, treat each other with respect as colleagues. \\r\\n\\r\\nRemember, no one likes conflicts, but sometimes they can be opportunities for growth. By effectively resolving conflicts, you may discover new ways of working or strengthen team cohesion.\\r\\n\\n\n\n\n\n\t\t\t\t\n\n\t\t\t\t\n\n\t\t\t\t\t\n","done":true,"done_reason":"stop","context":[198,27,91,318,62,2527,91,29,882,198,109425,55642,104077,83324,110158,104584,27,91,318,62,408,91,29,198,27,91,318,62,2527,91,29,78191,198,90,220,1,2037,794,220,1,19000,104077,83324,16325,55642,110158,104584,107226,48982,107693,9554,118552,1811,88852,107226,98184,88367,19361,103129,35304,57668,114914,110158,104584,9554,105226,105838,5232,59,81,59,77,59,81,59,77,16,13,220,334,20022,122,50287,124269,334,220,12,45154,247,110310,42016,30926,48044,126490,3922,67933,105986,30590,114706,104563,9554,103276,28542,34208,106529,26203,100,1811,57668,74770,68438,30358,59464,5486,60843,37985,58291,29172,57107,37507,21405,31958,57668,19000,30051,89151,36735,228,50287,67998,81,59,77,17,13,220,334,118551,106142,106353,334,220,12,59330,121,33857,16937,102654,40474,12774,103,109829,33764,58543,1811,102987,105324,107246,3922,90112,102099,117373,21082,106142,106353,113931,3922,104390,57668,81258,27327,34226,19361,40089,22649,30590,114914,87219,67998,81,59,77,18,13,220,334,116472,32018,119046,28542,334,220,12,59330,251,42421,125414,104836,24273,72368,126794,121738,1811,44388,74770,123725,114690,120143,112355,9554,102146,30320,249,3922,33655,50928,114638,110695,106053,124662,124778,119237,67998,81,59,77,19,13,220,334,11883,2118,40,863,

120074,334,220,12,86758,2118,37046,117293,51279,58291,2118,37046,112403,51279,69636,103668,2118,57668,60843,21043,1981,34690,104390,27327,111689,83747,64467,70616,64026,118551,33764,58543,9554,108053,34171,67998,81,59,77,20,13,220,334,118664,114914,112897,334,220,12,85997,57668,120222,35287,124269,125648,34208,106529,26203,100,34547,3922,57668,74770,118664,113882,88367,9554,114914,114997,1811,35056,33563,108787,29172,97522,21043,118789,31540,23039,9554,3922,64026,103786,124116,106837,104836,24273,9554,60632,105576,67998,81,59,77,21,13,220,334,116472,32018,109790,24273,123725,334,220,12,82363,110158,104584,108008,109759,30358,58291,57668,117293,102099,110621,55642,3922,111498,116472,93233,48044,16325,80195,9554,109790,24273,10110,30624,17792,48634,86429,106691,58291,116319,113178,57107,7705,88367,122503,53901,36668,37689,1811,104563,74770,104908,107371,122903,3922,64026,19000,109215,13646,75910,17701,48972,50338,67998,81,59,77,22,13,220,334,118551,113797,30358,34208,120228,41073,334,220,12,111505,69978,33764,58543,105363,113797,30358,58318,120228,41073,3922,106189,110878,57668,34208,124269,103276,28542,107653,3922,75863,31634,23897,42016,30926,124176,50021,106483,113797,30358,67998,81,59,77,59,81,59,77,41914,101987,3922,81543,109545,17792,114765,110158,104584,3922,78388,19361,105703,127150,74770,112743,13153,46961,9554,126490,1811,68438,89186,30590,114914,110158,104584,3922,57668,88367,38093,109836,116879,102301,76868,58291,50285,103229,104440,83266,118314,111200,48634,1811,498,220,1,1337,794,220,1,1342,498,220,1,285,62,408,62,6045,794,905,220,92,4815,720,256,12858,2355,256,12858,2355,256,18737,256],"total_duration":30680710500,"load_duration":41205916,"prompt_eval_count":33,"prompt_eval_duration":5121204000,"eval_count":448,"eval_duration":25513774000}

Conclusion

By quickly installing and running shenzhi-wang’s Llama3.1-8B-Chinese-Chat model on Mac M1 using Ollama, not only is the installation process simplified, but you can also quickly experience the excellent performance of this powerful open-source Chinese large language model. We hope this article provides some inspiration for using large models on personal computers.

If you encounter any problems during installation or use, feel free to leave a comment.

Share this content