Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[timeseries] Fixes contentLength issue for inference #3306

Merged
merged 1 commit into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ public static TrainingResult runExample(String[] args) throws IOException, Trans
inputShapes[6] =
new Shape(
1,
predictionLength,
contextLength,
TimeFeature.timeFeaturesFromFreqStr(freq).size() + 1);
inputShapes[7] = new Shape(1, predictionLength);
inputShapes[8] = new Shape(1, predictionLength);
inputShapes[7] = new Shape(1, contextLength);
inputShapes[8] = new Shape(1, contextLength);
trainer.initialize(inputShapes);

EasyTrain.fit(trainer, arguments.getEpoch(), trainSet, null);
Expand All @@ -147,6 +147,7 @@ public static Map<String, Float> predict(String outputDir)

Map<String, Object> arguments = new ConcurrentHashMap<>();
arguments.put("prediction_length", predictionLength);
arguments.put("context_length", predictionNetwork.getContextLength());
arguments.put("freq", freq);
arguments.put("use_" + FieldName.FEAT_DYNAMIC_REAL.name().toLowerCase(), false);
arguments.put("use_" + FieldName.FEAT_STATIC_CAT.name().toLowerCase(), true);
Expand Down Expand Up @@ -239,6 +240,7 @@ private static DeepARNetwork getDeepARModel(
.setFreq(freq)
.setPredictionLength(predictionLength)
.optDistrOutput(distributionOutput)
.optContextLength(8)
.optUseFeatStaticCat(true);
return training ? builder.buildTrainingNetwork() : builder.buildPredictionNetwork();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ protected BaseTimeSeriesTranslator(BaseBuilder<?> builder) {
this.batchifier = builder.batchifier;
this.freq = builder.freq;
this.predictionLength = builder.predictionLength;
// TODO: for inferring
this.contextLength = builder.predictionLength;
this.contextLength = builder.contextLength;
}

/** {@inheritDoc} */
Expand All @@ -57,6 +56,7 @@ public Batchifier getBatchifier() {
public abstract static class BaseBuilder<T extends BaseBuilder<T>> {
protected Batchifier batchifier = Batchifier.STACK;
protected int predictionLength;
protected int contextLength;

protected String freq;

Expand All @@ -82,6 +82,8 @@ protected void configPreProcess(Map<String, ?> arguments) {
throw new IllegalArgumentException(
"The value of `prediction_length` should be > 0");
}
this.contextLength =
ArgumentsUtil.intValue(arguments, "context_length", predictionLength);
if (arguments.containsKey("batchifier")) {
batchifier = Batchifier.fromString((String) arguments.get("batchifier"));
}
Expand Down
Loading