How Do I Invoke a Shell Script in a Training Job to Execute the .sh File?
ModelArts enables you to invoke a shell script, and you can use Python to invoke .sh. The procedure is as follows:
- Upload the .sh script to an OBS bucket. For example, upload the .sh script to /bucket-name/code/test.sh.
- Create the .py file on a local PC, for example, test.py. The background automatically downloads the code directory to the /home/work/user-job-dir/ directory of the container. Therefore, you can invoke the .sh file in the test.py boot file as follows:
import os os.system('bash /home/work/user-job-dir/code/test.sh')
- Upload test.py to OBS. Then the file storage path is /bucket-name/code/test.py.
- When creating a training job, set the code directory to /bucket-name/code/, and the boot file directory to /bucket-name/code/test.py.
After the training job is created, you can use Python to invoke the .sh file.
Compiling the Training Code FAQs
- How Do I Create a Training Job When a Dependency Package Is Referenced by the Model to Be Trained?
- What Is the Common File Path for Training Jobs?
- How Do I Install a Library That C++ Depends on?
- How Do I Check Whether a Folder Copy Is Complete During Job Training?
- How Do I Load Some Well Trained Parameters During Job Training?
- How Do I Obtain Training Job Parameters from the Boot File of the Training Job?
- Why Can't I Use os.system ('cd xxx') to Access the Corresponding Folder During Job Training?
- How Do I Invoke a Shell Script in a Training Job to Execute the .sh File?
- How Do I Obtain the Path for Storing the Dependency File in Training Code?
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.
more