5.2.9 Large Language Model
Introduction
This section introduces how to experience Large Language Model (LLM) on RDK.
Code repository: (https://github.com/D-Robotics/hobot_llm.git)
Supported Platforms
Platform | System | Function |
---|---|---|
RDK X3, RDK X3 Module (4GB RAM) | Ubuntu 20.04 (Foxy), Ubuntu 22.04 (Humble) | Edge-side LLM Experience |
Note: Only supports RDK X3 and RDK X3 Module with 4GB RAM version.
Preparation
RDK
- RDK with 4GB RAM version.
- RDK has been flashed with the provided Ubuntu 20.04/22.04 system image.
- RDK has successfully installed TogetheROS.Bot.
- Install transformers, the command is
pip3 install transformers -i https://pypi.tuna.tsinghua.edu.cn/simple
.
Usage
RDK
Before running the program, you need to download the model file and extract it, the commands are as follows:
- Foxy
- Humble
# Configure the tros.b environment
source /opt/tros/setup.bash
# Configure the tros.b environment
source /opt/tros/humble/setup.bash
# Download the model file
wget http://archive.d-robotics.cc/tros/llm-model/llm_model.tar.gz
# Extract
sudo tar -xf llm_model.tar.gz -C /opt/tros/${TROS_DISTRO}/lib/hobot_llm/
Use the command srpi-config
to modify the ION memory size to 1.7GB. The configuration method can be referred to the "Performance Options" section of the RDK User Manual Configuration Tool srpi-config
Guide Performance Options
After restarting, set the CPU maximum frequency to 1.5GHz and the scheduling mode to performance
, the commands are as follows:
sudo bash -c 'echo 1 > /sys/devices/system/cpu/cpufreq/boost'
sudo bash -c 'echo performance > /sys/devices/system/cpu/cpufreq/policy0/scaling_governor'
Currently, there are two ways to experience it. One is to directly input text in the terminal for chat interaction, and the other is to subscribe to text messages and then publish the results in text format.
Terminal Interaction
- Foxy
- Humble
# Configure the tros.b environment
source /opt/tros/setup.bash
# Configure the tros.b environment
source /opt/tros/humble/setup.bash
ros2 run hobot_llm hobot_llm_chat
After the program starts, you can chat directly with the robot in the current terminal.
Subscribe and Publish Messages
-
Start hobot_llm
- Foxy
- Humble
# Configure the tros.b environment
source /opt/tros/setup.bash# Configure the tros.b environment
source /opt/tros/humble/setup.bashros2 run hobot_llm hobot_llm
-
Open a new terminal to subscribe
- Foxy
- Humble
# Configure the tros.b environment
source /opt/tros/setup.bash# Configure the tros.b environment
source /opt/tros/humble/setup.bashros2 topic echo /text_result
-
Open a new terminal to publish
- Foxy
- Humble
# Configure the tros.b environment
source /opt/tros/setup.bash# Configure the tros.b environment
source /opt/tros/humble/setup.bashros2 topic pub --once /text_query std_msgs/msg/String "{data: ""What is the highest mountain?""}"
After sending the message, you can check the output result in the subscribed terminal.
Note
Make sure the development board has 4GB of memory and modify the ION memory size to 1.7GB, otherwise the model loading will fail.