Closed pbruneau closed 1 year ago
Hi @pbruneau thanks for filing this! In fact, as it is currently implemented, the model does require all the inputs. So those settings should really be asserted for being > 0
(and of the appropriate length in case of cardinality
).
when it is fine to go without covariates with the MXNet DeepAR
Actually, the situation for MXNet DeepAR is exactly the same: the estimator can do without those features, and just make them up with sum dummy values, when producing batches, for the network to use; but the network does require all the inputs. Similarly, if you use the gluonts.torch.model.deepar.DeepAREstimator
you'll be able to just not provide all the features, but interacting directly with the DeepARModel
(i.e. the underlying network) requires them.
There might be the opportunity of using Optional
inputs to the DeepARModel.forward
method, I think we would need to explore that if we want to make the class easier to use on its own.
So to summarize, for the time being you can set those to 1
, and cardinality = [1]
, and provide some dummy inputs (e.g. all zeros) in the associated arguments to forward
. To facilitate this, if model
is your DeepARModel
object, consider using
model.input_shapes(batch_size=...)
model.input_types()
to see exactly how a batch of data is supposed to be structured in terms of shapes and types.
OK I followed your hint and tried to directly use gluonts.torch.model.deepar.DeepAREstimator
, in the end I came up with this in place of l23-l68:
model = DeepAREstimator(
prediction_length=prediction_length,
context_length=context_length,
distr_output=StudentTOutput(),
freq='1H',
num_feat_dynamic_real=0,
num_feat_static_real=0,
num_feat_static_cat=0,
train_sampler = ExpectedNumInstanceSampler(
num_instances=1,
min_future=prediction_length,
min_past=context_length,
),
batch_size=32,
num_batches_per_epoch=50,
trainer_kwargs={
'max_epochs': 10,
'gpus': -1 if torch.cuda.is_available() else None,
},
)
predictor = model.train(dataset.train, shuffle_buffer_length=10, num_workers=4)
I guess I have no reason to use DeepARModel
directly, so I'm going to close the issue :)
Maybe just one suggestion: it could be nice to update the tutorial at https://ts.gluon.ai/stable/tutorials/advanced_topics/howto_pytorch_lightning.html to include an example which uses a subclass of gluonts.torch.model.estimator.PyTorchLightningEstimator
(such as gluonts.torch.model.deepar.DeepAREstimator
or gluonts.torch.model.simple_feedforward.SimpleFeedForwardEstimator
)!
Maybe just one suggestion: it could be nice to update the tutorial at https://ts.gluon.ai/stable/tutorials/advanced_topics/howto_pytorch_lightning.html to include an example which uses a subclass of gluonts.torch.model.estimator.PyTorchLightningEstimator (such as gluonts.torch.model.deepar.DeepAREstimator or gluonts.torch.model.simple_feedforward.SimpleFeedForwardEstimator)!
Right, good point; another thing is to validate all the settings for DeepARModel
(e.g. that they are positive).
Description
I have been trying to adapt the PyTorch tutorial example (https://ts.gluon.ai/stable/tutorials/advanced_topics/howto_pytorch_lightning.html) to using DeepAR instead of SimpleFeedForward. This tutorial example does not involve static or dynamic covariates. But the Torch DeepAR seems to require such covariates and crashes otherwise (when it is fine to go without covariates with the MXNet DeepAR).
Did I get something wrong, and/or is there a workaround to this issue? I would think about adding a dummy static cat feature, but maybe someone has something more elegant to suggest.
To Reproduce
https://gist.github.com/pbruneau/164dbe40b994185ea722aa80d27fae6c
Specifically, as
num_feat*
arguments are mandatory in thetorch.model.deepar.DeepARModel
interface, I thought the most sensible way to go would be:Error message or code output
Environment