forked from thuml/Autoformer
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93efcd0
commit 0610c4f
Showing
11 changed files
with
589 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import torch | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
from layers.Transformer_EncDec import Decoder, DecoderLayer, Encoder, EncoderLayer, ConvLayer | ||
from layers.SelfAttention_Family import ReformerLayer | ||
from layers.Embed import DataEmbedding | ||
import numpy as np | ||
|
||
|
||
class Model(nn.Module): | ||
""" | ||
Reformer with O(LlogL) complexity | ||
- It is notable that Reformer is not proposed for time series forecasting, in that it cannot accomplish the cross attention. | ||
- Here is only one adaption in BERT-style, other possible implementations can also be acceptable | ||
- The hyper-parameters, such as bucket_size and n_hashes, need to be further tuned. | ||
The official repo of Reformer (https://github.com/lucidrains/reformer-pytorch) can be very helpful, if you have any question. | ||
""" | ||
|
||
def __init__(self, configs): | ||
super(Model, self).__init__() | ||
self.pred_len = configs.pred_len | ||
self.pred_len = configs.pred_len | ||
self.output_attention = configs.output_attention | ||
|
||
# Embedding | ||
self.enc_embedding = DataEmbedding(configs.enc_in, configs.d_model, configs.embed, configs.freq, | ||
configs.dropout) | ||
# Encoder | ||
self.encoder = Encoder( | ||
[ | ||
EncoderLayer( | ||
ReformerLayer(None, configs.d_model, configs.n_heads, bucket_size=configs.bucket_size, | ||
n_hashes=configs.n_hashes), | ||
configs.d_model, | ||
configs.d_ff, | ||
dropout=configs.dropout, | ||
activation=configs.activation | ||
) for l in range(configs.e_layers) | ||
], | ||
norm_layer=torch.nn.LayerNorm(configs.d_model) | ||
) | ||
self.projection = nn.Linear(configs.d_model, configs.c_out, bias=True) | ||
|
||
def forward(self, x_enc, x_mark_enc, x_dec, x_mark_dec, | ||
enc_self_mask=None, dec_self_mask=None, dec_enc_mask=None): | ||
# add placeholder | ||
x_enc = torch.cat([x_enc, x_dec[:, -self.pred_len:, :]], dim=1) | ||
x_mark_enc = torch.cat([x_mark_enc, x_mark_dec[:, -self.pred_len:, :]], dim=1) | ||
# Reformer: encoder only | ||
enc_out = self.enc_embedding(x_enc, x_mark_enc) | ||
enc_out, attns = self.encoder(enc_out, attn_mask=enc_self_mask) | ||
enc_out = self.projection(enc_out) | ||
|
||
if self.output_attention: | ||
return enc_out[:, -self.pred_len:, :], attns | ||
else: | ||
return enc_out[:, -self.pred_len:, :] # [B, L, D] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pandas | ||
sklearn | ||
torchvision | ||
numpy | ||
matplotlib | ||
reformer_pytorch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
export CUDA_VISIBLE_DEVICES=2 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/electricity/ \ | ||
--data_path electricity.csv \ | ||
--model_id ECL_96_96 \ | ||
--model Reformer \ | ||
--data custom \ | ||
--features S \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 96 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--factor 3 \ | ||
--enc_in 1 \ | ||
--dec_in 1 \ | ||
--c_out 1 \ | ||
--des 'Exp' \ | ||
--itr 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/electricity/ \ | ||
--data_path electricity.csv \ | ||
--model_id ECL_96_192 \ | ||
--model Reformer \ | ||
--data custom \ | ||
--features S \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 192 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--factor 3 \ | ||
--enc_in 1 \ | ||
--dec_in 1 \ | ||
--c_out 1 \ | ||
--des 'Exp' \ | ||
--itr 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/electricity/ \ | ||
--data_path electricity.csv \ | ||
--model_id ECL_96_336 \ | ||
--model Reformer \ | ||
--data custom \ | ||
--features S \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 336 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--factor 3 \ | ||
--enc_in 1 \ | ||
--dec_in 1 \ | ||
--c_out 1 \ | ||
--des 'Exp' \ | ||
--itr 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/electricity/ \ | ||
--data_path electricity.csv \ | ||
--model_id ECL_96_720 \ | ||
--model Reformer \ | ||
--data custom \ | ||
--features S \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 720 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--factor 3 \ | ||
--enc_in 1 \ | ||
--dec_in 1 \ | ||
--c_out 1 \ | ||
--des 'Exp' \ | ||
--itr 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
export CUDA_VISIBLE_DEVICES=0 | ||
|
||
# multivariate setting of vanilla transformer | ||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/ETT-small/ \ | ||
--data_path ETTm1.csv \ | ||
--model_id ETTm1_96_96 \ | ||
--model Reformer \ | ||
--data ETTm1 \ | ||
--features M \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 96 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--enc_in 7 \ | ||
--dec_in 7 \ | ||
--c_out 7 \ | ||
--des 'Exp' \ | ||
--itr 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/ETT-small/ \ | ||
--data_path ETTm1.csv \ | ||
--model_id ETTm1_96_192 \ | ||
--model Reformer \ | ||
--data ETTm1 \ | ||
--features M \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 192 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--enc_in 7 \ | ||
--dec_in 7 \ | ||
--c_out 7 \ | ||
--des 'Exp' \ | ||
--itr 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/ETT-small/ \ | ||
--data_path ETTm1.csv \ | ||
--model_id ETTm1_96_336 \ | ||
--model Reformer \ | ||
--data ETTm1 \ | ||
--features M \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 336 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--enc_in 7 \ | ||
--dec_in 7 \ | ||
--c_out 7 \ | ||
--des 'Exp' \ | ||
--itr 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/ETT-small/ \ | ||
--data_path ETTm1.csv \ | ||
--model_id ETTm1_96_720 \ | ||
--model Reformer \ | ||
--data ETTm1 \ | ||
--features M \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 720 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--enc_in 7 \ | ||
--dec_in 7 \ | ||
--c_out 7 \ | ||
--des 'Exp' \ | ||
--itr 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
export CUDA_VISIBLE_DEVICES=4 | ||
|
||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/exchange_rate/ \ | ||
--data_path exchange_rate.csv \ | ||
--model_id Exchange_96_96 \ | ||
--model Reformer \ | ||
--data custom \ | ||
--features M \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 96 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--factor 3 \ | ||
--enc_in 8 \ | ||
--dec_in 8 \ | ||
--c_out 8 \ | ||
--des 'Exp' \ | ||
--itr 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/exchange_rate/ \ | ||
--data_path exchange_rate.csv \ | ||
--model_id Exchange_96_192 \ | ||
--model Reformer \ | ||
--data custom \ | ||
--features M \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 192 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--factor 3 \ | ||
--enc_in 8 \ | ||
--dec_in 8 \ | ||
--c_out 8 \ | ||
--des 'Exp' \ | ||
--itr 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/exchange_rate/ \ | ||
--data_path exchange_rate.csv \ | ||
--model_id Exchange_96_336 \ | ||
--model Reformer \ | ||
--data custom \ | ||
--features M \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 336 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--factor 3 \ | ||
--enc_in 8 \ | ||
--dec_in 8 \ | ||
--c_out 8 \ | ||
--des 'Exp' \ | ||
--itr 1 \ | ||
--train_epochs 1 | ||
|
||
python -u run.py \ | ||
--is_training 1 \ | ||
--root_path ./dataset/exchange_rate/ \ | ||
--data_path exchange_rate.csv \ | ||
--model_id Exchange_96_720 \ | ||
--model Reformer \ | ||
--data custom \ | ||
--features M \ | ||
--seq_len 96 \ | ||
--label_len 48 \ | ||
--pred_len 720 \ | ||
--e_layers 2 \ | ||
--d_layers 1 \ | ||
--factor 3 \ | ||
--enc_in 8 \ | ||
--dec_in 8 \ | ||
--c_out 8 \ | ||
--des 'Exp' \ | ||
--itr 1 |
Oops, something went wrong.