0
votes

I try to get my feet wet with Google Cloud Machine Learning (ML) Engine by attempting to run a local trainer. I have followed Google's setup instructions and issued this command:

gcloud ml-engine local train \
  --module-name trainer \
  --package-path $(pwd) \
  --job-dir $JOB_DIR

My trainer exists in a file $(pwd)/trainer.py, yet I receive this error message:

~/cmle-quickstart/bin/python: No module named trainer

What am I doing wrong?

1

1 Answers

3
votes

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.