Custom Python
Any Python script can become a HyperOptimizer workload if it accepts --hpo-* arguments, runs one trial, and prints metrics.
Project layout
Section titled “Project layout”- Dockerfile
- requirements.txt
- train.py
Minimal Python shape
Section titled “Minimal Python shape”import argparseimport json
def parse_args(): parser = argparse.ArgumentParser() parser.add_argument("--hpo-learning-rate", type=float, required=True) parser.add_argument("--hpo-batch-size", type=int, required=True) return parser.parse_args()
def main(): args = parse_args() result = train_model( learning_rate=args.hpo_learning_rate, batch_size=args.hpo_batch_size, )
print(f"hpo.metrics.loss={json.dumps(result.loss)}") print(f"hpo.metrics.accuracy={json.dumps(result.accuracy)}")
if __name__ == "__main__": main()Package it
Section titled “Package it”FROM python:3.12-slim
WORKDIR /appCOPY requirements.txt .RUN pip install --no-cache-dir -r requirements.txtCOPY . .
CMD ["python", "train.py"]Next steps
Section titled “Next steps”Build the imageMake the script repeatable, then publish it to your org Images registry.
Publish an imageTag and push so the create-experiment wizard can select your tag.
Define the search spaceChoose ranges and choices for the parameters you exposed.
Choose the objectiveDecide whether to maximize accuracy, minimize loss, or use a custom score.