Getting Started with Phi-2

Feb 17, 2024 • 3 minutes to read

Phi-2 by Microsofit is a 2.7 billion parameter Transformer pushing the boundaries of language models! Unlike its predecessors, it excels in reasoning and understanding thanks to unique training data (augmented with a new data source that consists of various NLP synthetic texts and filtered websites.) and avoids fine-tuning via human feedback. Open-source and powerful, Phi-2 empowers researchers to tackle crucial safety challenges in AI.

In this article, we will cover

  • How to run Phi-2 on your own device

We will use LlamaEdge (the Rust + Wasm stack) to develop and deploy applications for this model. There is no complex Python packages or C++ toolchains to install! See why we choose this tech stack.

Run the model on your own device

Step 1: Install WasmEdge via the following command line.

curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- --plugins wasmedge_rustls wasi_nn-ggml

Step 2: Download the Phi-2 model GGUF file. It may take a long time, since the size of the model is several GBs.

curl -LO https://huggingface.co/second-state/Phi-2-GGUF/resolve/main/stablelm-2-zephyr-1_6b-Q5_K_M.gguf

Step 3: Download a cross-platform portable Wasm file for the chat app. The application allows you to chat with the model on the command line. The Rust source code for the app is here.

curl -LO https://github.com/LlamaEdge/LlamaEdge/releases/latest/download/llama-chat.wasm

That's it. You can chat with the model in the terminal by entering the following command.

wasmedge --dir .:. --nn-preload default:GGML:AUTO:phi-2-Q5_K_M.gguf llama-chat.wasm -p phi-2-instruct

The portable Wasm app automatically takes advantage of the hardware accelerators (eg GPUs) I have on the device.

[You]:
Can you explain me what is AMD?

[Bot]:
AMD, or Advanced Micro Devices, Inc., is an American multinational semiconductor manufacturing company that designs, develops, and sells a wide range of advanced digital technology products, including processors, computer systems, graphics solutions, and data center hardware. The company's primary headquarters are in El Segundo, California.

AMD was formed through the merger of two major semiconductor companies: AMD (Advanced Micro Devices) and ATI Technologies Inc., on November 26, 2013, by combining these entities to form a leading technology and innovation company.

The main goal of AMD is to provide advanced computing solutions for various industries such as gaming, professional graphics, data center, and cloud infrastructure. They produce both CPUs (Central Processing Units) and GPUs (Graphics Processors), which are crucial components in modern personal computers, workstations, and gaming consoles.

AMD's products include the Ryzen series of CPUs that feature Zen cores architecture, the Navi GPU architecture for high-end gaming systems, and various data center solutions like EPYC processors and Radeon graphics cards. The company has a wide range of product lines focused on different segments in the technology market, making it one of the major players in the semiconductor industry.

That’s all. WasmEdge is easiest, fastest, and safest way to run LLM applications. Give it a try!

Talk to us!

Join the WasmEdge discord to ask questions and share insights.

Any questions getting this model running? Please go to second-state/LlamaEdge to raise an issue or book a demo with us to enjoy your own LLMs across devices!

LLMAI inferenceRustWebAssembly
A high-performance, extensible, and hardware optimized WebAssembly Virtual Machine for automotive, cloud, AI, and blockchain applications