The code must be in a valid Python package, which will require you to have an __init__.py, which can be blank.
First, create the __init__.py. From the same directory as above run:
touch __init__.py
To run local training, you'll need to refer to module by its fully qualified name, which now includes the parent directory of the module. So if your directory structure looks like this:
- my_model
- __init__.py
- trainer.py
Then the package name is my_model and the module name is, of course, trainer. So to run training, you would use the following commands:
gcloud ml-engine local train \
--module-name my_model.trainer \
--package-path $(pwd) \
--job-dir $JOB_DIR
Here, you're telling gcloud: I have a valid Python package at $(pwd). The fully-qualified module name within that package that I want you run is my_model.trainer
Note that this is equivalent to the following command:
(cd $PACKAGE_PATH/.. && python -m my_model.trainer)
Where PACKAGE_PATH points to the my_model directory.
See also the documentation on recommended project structure.