What is the similar command as tf.flags.DEFINE_integer in pytorch

I have been trying to convert a tensorflow code to pytorch. The code uses tf.flags.DEFINE_integer etc to initialize different parameters of the model.

import tensorflow as tf
flags = tf.flags
flags.DEFINE_integer("batchSize", 20, "batch size.")
flags.DEFINE_integer("nEpochs", 1, "number of epochs to train.")
flags.DEFINE_float("adamLr", 1e-4, "AdaM learning rate.")
flags.DEFINE_integer("hidden_size", 200, "number of hidden units in en/decoder.")
flags.DEFINE_integer("latent_size", 50, "dimensionality of latent variables.")
flags.DEFINE_integer("K", 5, "number of components in mixture model.")
flags.DEFINE_string("experimentDir", "MNIST/", "directory to save training artifacts.")
inArgs = flags.FLAGS

What is the similar command-line as tf.flags in pytorch?

I don’t know how tf.flags are used, but assuming these values are used as arguments you could use plain Python variables:

batch_size = 32
data = torch.randn(batch_size)

or in case it’s used to parse arguments you could use argparse.

1 Like