|
| 1 | +--- |
| 2 | +title: Mobile Plartform for Fine Tuning Large Language Model |
| 3 | +weight: 9 |
| 4 | + |
| 5 | +### FIXED, DO NOT MODIFY |
| 6 | +layout: learningpathall |
| 7 | +--- |
| 8 | + |
| 9 | +## Development environment |
| 10 | +You will learn to build the ExecuTorch runtime for fine-tuning models using KleidiAI, create JNI libraries for an mobile application, and integrate these libraries into the application. |
| 11 | + |
| 12 | +The first step is to set up a development environment with the necessary software: |
| 13 | +- Python 3.10 or later |
| 14 | +- Git |
| 15 | +- Java 17 JDK |
| 16 | +- Latest Version of Android Studio |
| 17 | +- Android NDK |
| 18 | + |
| 19 | +###### Installation of Android Studio and Android NDK |
| 20 | +- Download and install the latest version of Android Studio |
| 21 | +- Launch Android Studio and open the Settings dialog. |
| 22 | +- Go to Languages & Frameworks > Android SDK. |
| 23 | +- In the SDK Platforms tab, select Android 14.0 ("UpsideDownCake"). |
| 24 | +- Install the required version of Android NDK by first setting up the Android command line tools. |
| 25 | + |
| 26 | +###### Install Java 17 JDK |
| 27 | +- Open the [Java SE 17 Archive Downloads](https://www.oracle.com/java/technologies/javase/jdk17-archive-downloads.html) Downloads page in your browser. |
| 28 | +- Choose the appropriate version for your operating system. |
| 29 | +- Downloads are available for macOS and Linux. |
| 30 | + |
| 31 | +###### Install Git and cmake |
| 32 | + |
| 33 | +For macOS use [Homebrew](https://brew.sh/): |
| 34 | + |
| 35 | +``` bash |
| 36 | +brew install git cmake |
| 37 | +``` |
| 38 | + |
| 39 | +For Linux, use the package manager for your distribution: |
| 40 | + |
| 41 | +``` bash |
| 42 | +sudo apt install git-all cmake |
| 43 | +``` |
| 44 | + |
| 45 | +###### Install Python 3.10 |
| 46 | + |
| 47 | +For macOS: |
| 48 | + |
| 49 | +``` bash |
| 50 | + |
| 51 | +``` |
| 52 | + |
| 53 | +For Linux: |
| 54 | + |
| 55 | +``` bash |
| 56 | +sudo apt update |
| 57 | +sudo apt install software-properties-common -y |
| 58 | +sudo add-apt-repository ppa:deadsnakes/ppa |
| 59 | +sudo apt install Python3.10 python3.10-venv |
| 60 | +``` |
| 61 | + |
| 62 | + |
| 63 | +###### Setup the [Executorch](https://pytorch.org/executorch/stable/intro-overview.html) Environments |
| 64 | +For mobile device execution, [ExecuTorch](https://pytorch.org/executorch/stable/intro-overview.html) is required. It enables efficient on-device model deployment and execution |
| 65 | + |
| 66 | +- Python virtual environment creation |
| 67 | + |
| 68 | +```bash |
| 69 | +python3.10 -m venv executorch |
| 70 | +source executorch/bin/activate |
| 71 | +``` |
| 72 | + |
| 73 | +The prompt of your terminal has `executorch` as a prefix to indicate the virtual environment is active. |
| 74 | + |
| 75 | +- Conda virtual environment creation |
| 76 | + |
| 77 | +Install Miniconda on your development machine by following the [Installing conda](https://conda.io/projects/conda/en/latest/user-guide/install/index.html) instructions. |
| 78 | + |
| 79 | +Once `conda` is installed, create the environment: |
| 80 | + |
| 81 | +```bash |
| 82 | +conda create -yn executorch python=3.10.0 |
| 83 | +conda activate executorch |
| 84 | +``` |
| 85 | + |
| 86 | +###### Clone ExecuTorch and install the required dependencies |
| 87 | + |
| 88 | +From within the conda environment, run the commands below to download the ExecuTorch repository and install the required packages: |
| 89 | + |
| 90 | +- You need to download Executorch from this [GitHub repository](https://github.com/pytorch/executorch/tree/main) |
| 91 | +- Download the executorch.aar file from [executorch.aar](https://ossci-android.s3.us-west-1.amazonaws.com/executorch/release/executorch-241002/executorch.aar ) |
| 92 | +- Add a libs folder in this path \executorch-main\executorch-main\examples\demo-apps\android\LlamaDemo\app\libs and add executorch.aar |
| 93 | + |
| 94 | +``` bash |
| 95 | +git submodule sync |
| 96 | +git submodule update --init |
| 97 | +./install_requirements.sh |
| 98 | +./install_requirements.sh --pybind xnnpack |
| 99 | +./examples/models/llama/install_requirements.sh |
| 100 | +``` |
| 101 | + |
| 102 | +###### Mobile Device Setup |
| 103 | +- Enable the mobile device in [Android Studio](https://support.google.com/android/community-guide/273205728/how-to-enable-developer-options-on-android-pixels-6-secret-android-tips?hl=en) |
| 104 | +- On the Android phone, enable Developer Options |
| 105 | + - First, navigate to Settings > About Phone. |
| 106 | + - At the bottom, locate Build Number and tap it seven times. A message will appear confirming that you are now a developer.(if only it were that easy to become one XD) |
| 107 | + - Access Developer Options by navigating to Settings > System > Developer Options. |
| 108 | + - You will see a large number of options, I repeat: DO NOT TOUCH ANYTHING YOU DO NOT KNOW. |
| 109 | + - Enable USB Debugging to connect your mobile device to Android Studio. |
0 commit comments