Migrating Existing Images to ModelArts
Overview
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-userNote:
- 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 run cat /etc/group | grep 100 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 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 run cat /etc/passwd | grep 1000 to check whether the user whose UID is 1000 exists.
- If the user whose uid is 1000 already exists, skip this step and delete 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, perform the following operations:
- New console: Choose Model Build > Training.
- Old console: Choose .
- Click Create Training Job and set parameters. The configuration methods for the new and old consoles are as follows:
- New console: For details about how to create a training job, see Table 1. For details about other parameters for creating a training job, see Creating a Training Job.
Table 1 Training configuration Parameter
Description
Preset Template (Optional)
Click Select Preset Template to filter templates by type (currently supporting text generation and image understanding) or brand (currently supporting Qwen).
After you select a preset template, some templates will automatically fill in the description (optional), image, boot command code directory, local code directory, and environment variables of the current job. Refer to the actual GUI for final details.
You can also adjust the configuration as needed.
Select Image
Specifies the container image used to run the training code. The following options are available:
Preset Images: Ready-to-use images provided by ModelArts that include popular frameworks (e.g., PyTorch 1.8, TensorFlow 2.1). Ideal for most standard scenarios.
Custom Images: Select an image that you have created and pushed to the SWR image repository or a registered image.
- You can select an image from SWR Basic Edition or Enterprise Edition.
- Registered Images: Select an image that you have registered on the ModelArts console.
Custom images must be registered in ModelArts Image Management before use. This option is recommended when preset base images do not meet specific dependency requirements.
Boot Command
Defines the command executed upon container startup to launch your training script.- 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 an .sh file, main.sh for example, the boot command is as follows:
bash ${MA_JOB_DIR}/demo-code/main.sh
The boot command supports multiple commands concatenated with ; or &&. Note that demo-code represents the leaf directory of the OBS path where your code is stored; adjust this according to your actual project structure.
NOTE:To ensure data security, do not include sensitive information such as plaintext passwords.
Code Directory (Optional)
Specifies the OBS directory containing the training code. This parameter is required when using a preset image and optional when using a custom image. You can choose your own OBS bucket or enter a path. The path must start with obs:// and end with a slash (/), like this: obs://bucketname/path/. For shared buckets from other users, you must enter the path. In the OBS bucket, files with the .txt, .py, .sh, and .yaml extensions can be edited online, and files with the .log, .json, and .md extensions can be viewed online.
- 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. If there is a pre-trained model, put it in the code directory.
- 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.
Code Backup Directory (Optional)
Specifies the OBS directory where you want to back up the training code file.
- You must create the directory in advance.
- When a training job is started, files in the code directory are automatically backed up to ${MA_RECORD_CODE_DIR_OBS}/${ma_job_name}-${MA_TASK_NAME}-${task_index}/user-job-dir/demo-code. demo-code is the last-level OBS directory for storing the code. For example, if the code backup directory is /test/record-dir and the code directory is /test/code, the training code file will be backed up to the /test/record-dir/job_name-work-0/user-job-dir/code directory.
Local Code Directory
Specifies the local directory within the training container where the code will be downloaded. The default path is /home/ma-user/modelarts/user-job-dir.
Cannot be under /home/ma-user/modelarts/*, /home/ma-user/modelarts-dev/*, /home/ma-user/infer/*, or /home/ma-user.
Click Preview Runtime Environment to view the actual working directory of the training job.
Environment Variable
Add environment variables based on service requirements. For details about the environment variables preset in a training container, see Managing Environment Variables of a Training Container.
- Click Add to add environment variables. The total number of environment variables cannot exceed 100.
- To import environment variables in batches, click Upload. You will need to fill in the environment variables based on the provided template. The total number of environment variables should not exceed 100, or the import will fail.
NOTE:To ensure data security, do not include sensitive information such as plaintext passwords.
- Old console: For details about how to create a training job, see Table 2. For details about other parameters for creating a training job, see Creating a Production Training Job.
Table 2 Creating a training job using a custom image Parameter
Description
Algorithm Type
Select Custom algorithm. This parameter is mandatory.
Boot Mode
Mandatory. Select Custom image.

Image
Mandatory. Click the select button on the right and select the new image from the container image repository to upload it to SWR.
Code Directory
Specifies the OBS directory containing the training code. 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 1000, 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 an .sh file, main.sh for example, the boot command is as follows:
bash ${MA_JOB_DIR}/demo-code/main.sh
The boot command supports multiple commands concatenated with ; or &&. Note that demo-code represents the leaf directory of the OBS path where your code is stored; adjust this according to your actual project structure.
Local Code Directory
Specify the local directory of a training container. When the 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.
- New console: For details about how to create a training job, see Table 1. For details about other parameters for creating a training job, see Creating a Training Job.
- Log in to the ModelArts console. In the navigation pane on the left, perform the following operations:
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