How Do I Obtain the Path for Storing the Dependency File in Training Code?
The code developed locally must be uploaded to the ModelArts backend. In training code, it is error-prone to set the path for storing the dependency file.
The following general solution is recommended: Use the OS API to obtain the absolute path of the dependency file.
Example:
|---project_root # Root directory for code |---bootfile.py # Boot file |---otherfileDirectory # Directory of other dependency files |---otherfile.py # Other dependency files
Do as follows to obtain the path of the dependency file, otherfile_path in this example, in the boot file:
import os current_path = os.path.dirname(os.path.realpath(__file__)) # Directory where the boot file is located project_root = os.path.dirname(current_path) # Root directory of the project, which is the code directory set on the ModelArts training console otherfile_path = os.path.join(project_root, "otherfileDirectory", "otherfile.py")
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