Spaces:
Running
Running
| <html> | |
| <head> | |
| <meta name="GENERATOR" content="mkd2html 2.2.7 GITHUB_CHECKBOX"> | |
| <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> | |
| <link rel="stylesheet" | |
| type="text/css" | |
| href="header.css" /> | |
| <title></title> | |
| </head> | |
| <body> | |
| <h1>Prepare Python environment to download Hugging Face models</h1> | |
| <p>This guide will walk you through setting up a Python environment named | |
| <strong><code>empower</code></strong>, installing the necessary Hugging Face packages, and | |
| downloading and using the <strong><code>microsoft/Phi-4-mini-instruct</code></strong> model on | |
| a GNU/Linux system.</p> | |
| <p>Follow this guide, or <a href="index.html">return to the main page</a> if needed.</p> | |
| <hr /> | |
| <h2>1. Set Up Python Environment</h2> | |
| <h3>Check Python Installation</h3> | |
| <p>Ensure Python 3 is installed by running:</p> | |
| <p><code>bash | |
| python3 --version | |
| </code></p> | |
| <p>If Python is not installed, install it using your package manager. For example:</p> | |
| <ul> | |
| <li><p>On Debian/Ubuntu:</p> | |
| <p><code>bash | |
| sudo apt update | |
| sudo apt install python3 python3-venv | |
| </code></p></li> | |
| <li><p>On Fedora:</p> | |
| <p><code>bash | |
| sudo dnf install python3 | |
| </code></p></li> | |
| </ul> | |
| <h3>Create a Virtual Environment</h3> | |
| <p>Create a virtual environment named <strong><code>empower</code></strong>:</p> | |
| <p><code>bash | |
| python3 -m venv empower | |
| </code></p> | |
| <p>Activate the virtual environment: | |
| <code>bash | |
| source empower/bin/activate | |
| </code></p> | |
| <hr /> | |
| <h2>2. Install Hugging Face Packages</h2> | |
| <p>Install the necessary Hugging Face packages to interact with models and the Hugging Face Hub.</p> | |
| <h3>Install <code>transformers</code> and <code>huggingface_hub</code></h3> | |
| <p>Run the following command to install both packages:</p> | |
| <p><code>bash | |
| pip install transformers huggingface_hub | |
| </code></p> | |
| <h3>Verify Installation</h3> | |
| <p>Check if the packages are installed correctly:</p> | |
| <p><code>bash | |
| python3 -c "from transformers import pipeline; print('Transformers installed successfully!')" | |
| python3 -c "from huggingface_hub import HfApi; print('Hugging Face Hub installed successfully!')" | |
| </code></p> | |
| <hr /> | |
| <h2>3. Download the <code>microsoft/Phi-4-mini-instruct</code> Model</h2> | |
| <p>To download and use the <strong><code>microsoft/Phi-4-mini-instruct</code></strong> model, follow these steps.</p> | |
| <h3>Using <code>huggingface-cli</code> to Download the Model</h3> | |
| <p>Run the following command to download the model:</p> | |
| <p><code>bash | |
| huggingface-cli download microsoft/Phi-4-mini-instruct | |
| </code></p> | |
| <p>This will download the model files to your current directory.</p> | |
| <hr /> | |
| <h2>4. Load and Use the Model in Python</h2> | |
| <p>Once the model is downloaded, you can load and use it in your Python code.</p> | |
| <h3>Example Code</h3> | |
| <p>```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer</p> | |
| <h1>Load the model and tokenizer</h1> | |
| <p>model_name = “microsoft/Phi-4-mini-instruct” | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| model = AutoModelForCausalLM.from_pretrained(model_name)</p> | |
| <h1>Generate text</h1> | |
| <p>input_text = “What is the capital of France?” | |
| inputs = tokenizer(input_text, return_tensors=“pt”) | |
| outputs = model.generate(**inputs, max_length=50)</p> | |
| <h1>Decode and print the output</h1> | |
| <p>print(tokenizer.decode(outputs[0], skip_special_tokens=True)) | |
| ```</p> | |
| <hr /> | |
| <h2>5. Summary of Commands</h2> | |
| <table> | |
| <thead> | |
| <tr> | |
| <th> Command </th> | |
| <th> Description </th> | |
| </tr> | |
| </thead> | |
| <tbody> | |
| <tr> | |
| <td> <code>python3 -m venv empower</code> </td> | |
| <td> Create a virtual environment named <code>empower</code>. </td> | |
| </tr> | |
| <tr> | |
| <td> <code>source empower/bin/activate</code> </td> | |
| <td> Activate the <code>empower</code> environment. </td> | |
| </tr> | |
| <tr> | |
| <td> <code>pip install transformers huggingface_hub</code> </td> | |
| <td> Install Hugging Face packages. </td> | |
| </tr> | |
| <tr> | |
| <td> <code>huggingface-cli download microsoft/Phi-4-mini-instruct</code> </td> | |
| <td> Download the model. </td> | |
| </tr> | |
| </tbody> | |
| </table> | |
| <hr /> | |
| <p>Now you’re ready to use the <strong><code>microsoft/Phi-4-mini-instruct</code></strong> model in your Python projects on GNU/Linux! 🚀</p> | |
| <h1>Proceed to next step</h1> | |
| <p><a href="index.html">Proceed to next step.</a></p> | |
| </body> | |
| </html> | |