Migrating Existing Images to ModelArts
Description
An image is available on the local host and needs to be adapted on the cloud for ModelArts model training.
Procedure
- Modify an existing image by referring to the following Dockerfile so that the image complies with specifications for custom images of the model training.
FROM {An existing image} USER root # If the user group whose GID is 100 already exists, delete the groupadd command. RUN groupadd ma-group -g 100 # If the user whose UID is 1000 already exists, delete the useradd command. RUN useradd -m -d /home/ma-user -s /bin/bash -g 100 -u 1000 ma-user # Modify the permissions on image files so that user ma-user whose UID is 1000 can read and write the files. RUN chown -R ma-user:100 {Path to the Python software package} # Configure the preset environment variables of the container image. # Set PYTHONUNBUFFERED to 1 to prevent log loss. ENV PYTHONUNBUFFERED=1 # Configure the default user and working directory of the container image. USER ma-user WORKDIR /home/ma-user
Note:
- Add the default user group ma-group (gid = 100) of the model training for the image.
If the user group whose gid is 100 already exists, the error message "groupadd: GID '100' already exists" may be displayed. You can use the cat /etc/group | grep 100 command to check whether the user group whose GID is 100 exists.
If the user group whose gid is 100 already exists, skip this step and delete the command RUN groupadd ma-group -g 100 from the Dockerfile.
- Add the default user ma-user (uid = 1000) of the model training for the image.
If the user whose uid is 1000 already exists, the error message "useradd: UID 1000 is not unique" may be displayed. You can use the cat /etc/passwd | grep 1000 command to check whether the user whose UID is 1000 exists.
If the user whose uid is 1000 already exists, skip this step and delete the command RUN useradd -d /home/ma-user -m -u 1000 -g 100 -s /bin/bash ma-user from the Dockerfile.
- Modify the permissions on files in the image to allow ma-user whose uid is 1000 to read and write the files.
- Add the default user group ma-group (gid = 100) of the model training for the image.
- After editing the Dockerfile, run the following command to build an image:
docker build -f Dockerfile . -t {New image}
- Upload the new image to SWR. For details, see 6.
- Create a training job on ModelArts.
- Log in to the ModelArts console.
- In the navigation pane on the left, choose Model Training > Training Jobs.
- Click Create Training Job. On the displayed page, configure the parameters by referring to Table 1. For details about the parameters, see Creating a Production Training Job.
Table 1 Creating a training job using a custom image Parameter
Description
Algorithm Type
Mandatory. Select Custom algorithm.
Boot Mode
Mandatory. Select Custom image.
Image
Mandatory. Select the image uploaded to SWR for container image.
Code Directory
OBS directory where the training code file is stored. Configure this parameter only if your custom image does not contain training code.
- Upload code to the OBS bucket beforehand. The total size of files in the directory cannot exceed 5 GB, the number of files cannot exceed 1,000, and the folder depth cannot exceed 32.
- The training code file is automatically downloaded to the ${MA_JOB_DIR}/demo-code directory of the training container when the training job is started. demo-code is the last-level OBS directory for storing the code. For example, if Code Directory is set to /test/code, the training code file is downloaded to the ${MA_JOB_DIR}/code directory of the training container.
User ID
User ID for running the container. The default value 1000 is recommended.
If the UID needs to be specified, its value must be within the specified range. The UID ranges of different resource pools are as follows:
- Public resource pool: 1000 to 65535
- Dedicated resource pool: 0 to 65535
Boot Command
Mandatory. Command for booting an image.
When a training job is running, the boot command is automatically executed after the code directory is downloaded.- If the training boot script is a .py file, train.py for example, the boot command is as follows:
python ${MA_JOB_DIR}/demo-code/train.py
- If the training boot script is a .sh file, main.sh for example, the boot command is as follows:
bash ${MA_JOB_DIR}/demo-code/main.sh
You can use semicolons (;) and ampersands (&&) to combine multiple commands. demo-code in the command is the last-level OBS directory where the code is stored. Replace it with the actual one.
Local Code Directory
Specify the local directory of a training container. When a training starts, the system automatically downloads the code directory to this directory.
(Optional) The default local code directory is /home/ma-user/modelarts/user-job-dir.
Work Directory
During training, the system automatically runs the cd command to execute the boot file in this directory.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot