こすたろーんエンジニアの試行錯誤部屋

作成物の備忘録を書いていきますー

How to handle command line arguments in metaflow

I have built a metaflow environment before. I wanted to run metaflow by passing arguments. so I looked into it and tried it out.

This is a memorandum.
※See below for environment construction
technoxs-stacker.hatenablog.com

contents

スポンサーリンク

abstract

How to handle command line arguments in metaflow

1.Code modifications

modify the hello world code as follows.

from metaflow import FlowSpec, step, Parameter

class HelloFlow(FlowSpec):
    """
    A flow where Metaflow prints 'Hi'.
    Run this flow to validate that Metaflow is installed correctly.
    """
    strat_msg = Parameter('strat_msg',
                          help='strat messege.',
                          type=str,
                          required=True)
    lr = Parameter('lr',
                   help='Learning rate',
                   default=0.01,
                   type=float)
    batch_size = Parameter('batch_size',
                           help='batch size',
                           default=128,
                           type=int)

    @step
    def start(self):
        """
        This is the 'start' step. All flows must have a step named 'start' that
        is the first step in the flow.
        """
        print('Metaflow says:  %s' % self.strat_msg)
        self.next(self.hello)

    @step
    def hello(self):
        """
        A step for metaflow to introduce itself.
        """
        print('learning rate is %f' % self.lr)
        print('batch size is %d' % self.batch_size)
        self.next(self.end)

    @step
    def end(self):
        """
        This is the 'end' step. All flows must have an 'end' step, which is the
        last step in the flow.
        """
        print("HelloFlow is all done.")


if __name__ == '__main__':
    HelloFlow()

2.memo on the parameter class

name contents example
name parameter name strat_msg
default default value default='hoge'
type parameter type(str, float, int, bool) type=str
help help messege help='hugahuga'
required optional(True/False) required=True

スポンサーリンク

reference

docs.metaflow.org docs.metaflow.org