Multiprocessing on windows

I am a new user. I have some problems when I set num_workers on windowns. I received the following notification

An attempt has been made to start a new process before the
current process has finished its bootstrapping phase.

This probably means that you are not using fork to start your
child processes and you have forgotten to use the proper idiom
in the main module:

if name == ‘main‘:
freeze_support()

The “freeze_support()” line can be omitted if the program
is not going to be frozen to produce an executable.

Then, I modify the code:

import numpy as np
import pandas as pd

import torch
from gluonts.dataset.multivariate_grouper import MultivariateGrouper
from gluonts.dataset.repository.datasets import dataset_recipes, get_dataset
from pts.model.tempflow import TempFlowEstimator
from pts.model.transformer_tempflow import TransformerTempFlowEstimator
from pts.model.time_grad import TimeGradEstimator
from pts import Trainer
from gluonts.evaluation.backtest import make_evaluation_predictions
from gluonts.evaluation import MultivariateEvaluator

from gluonts.dataset.common import ListDataset
from gluonts.dataset.rolling_dataset import (
    StepStrategy,
    generate_rolling_dataset,
)

device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

from deepnegpol import DeepNEGPOLEstimator
from pts.model.deepvar import DeepVAREstimator
from pts.modules import LowRankMultivariateNormalOutput
from pts.modules import NormalOutput
from gluonts.model.gpvar import GPVAREstimator
from gluonts.mx.distribution.lowrank_gp import LowrankGPOutput
from hyperparams import Hyperparams
from train_and_plot_predictions import data_creation, metrics_rolling_dataset1,metrics_rolling_dataset2, plot
params = Hyperparams()

import warnings
warnings.filterwarnings("ignore")




####################################################################################
# BIKE
####################################################################################

train_ds, test_ds, target_dim, freq, prediction_length = data_creation(params, data = "bike")
    





##############################################################################################
# TRAINING
##############################################################################################
def estimator_model(test):
    
 modele = test['model']
 num_cells =  test['num_cells']
 num_cells1 = test['num_cells1']  
 num_cells2 = test['num_cells2']  
 lr = test['lr']


 
 if modele == "timegrad":
    from pts import Trainer
    estimator = TimeGradEstimator(
        input_size = 564,
        num_cells = num_cells,
        num_layers=params.num_layers,
        dropout_rate=params.dropout_rate,
        target_dim=target_dim,
        prediction_length=prediction_length,
        context_length = prediction_length,
        cell_type='LSTM',
        freq=freq,
        loss_type='l2',
        diff_steps=100,
        beta_end=0.1,
        beta_schedule="linear",
        scaling=False,
        lags_seq = params.lags_seq2,
        trainer=Trainer(
         epochs=params.epochs,
         batch_size=params.batch_size,
         learning_rate=lr,
         num_batches_per_epoch=params.num_batches_per_epoch      ),
    conditioning_length = params.conditioning_length,
    use_marginal_transformation = True
    )


        
 if modele == "deepnegpol":
   from pts import Trainer
   estimator = DeepNEGPOLEstimator(
        input_size1 = 10,
        input_size2 = 484,
        num_cells1 = num_cells1,
        num_cells2 = num_cells2,
        num_layers1=params.num_layers,
        num_layers2=params.num_layers,
        dropout_rate=params.dropout_rate,
        target_dim=target_dim,
        prediction_length=prediction_length,
        freq=freq,
        scaling=True,
        lags_seq = params.lags_seq2,
        trainer=Trainer(
         epochs=params.epochs,
         batch_size=params.batch_size,
         learning_rate=lr,
         num_batches_per_epoch=params.num_batches_per_epoch      )
    )
   
   
 if modele == "lstmcop":
   from pts import Trainer
   estimator = DeepVAREstimator(
    target_dim=target_dim,
    prediction_length=prediction_length,
    num_cells = num_cells,
    cell_type='LSTM',
    input_size=567,
    freq=freq,
    scaling=False,
    dropout_rate=params.dropout_rate,
    distr_output = LowRankMultivariateNormalOutput(target_dim,params.rank),
    rank = params.rank,
    lags_seq = params.lags_seq2,
    trainer=Trainer(
         epochs=params.epochs,
         batch_size=params.batch_size,
         learning_rate=lr,
         num_batches_per_epoch=params.num_batches_per_epoch      ),
    conditioning_length = params.conditioning_length,
    use_marginal_transformation = True
   )
   
   
 if modele == "lstmindscaling":
   from pts import Trainer
   estimator = DeepVAREstimator(
    target_dim=target_dim,
    prediction_length=prediction_length,
    cell_type='LSTM',
    num_cells = num_cells,
    input_size=567,
    freq=freq,
    scaling=True,
    dropout_rate=params.dropout_rate,
    distr_output = LowRankMultivariateNormalOutput(target_dim,params.rank),
    rank = params.rank,
    lags_seq = params.lags_seq2,
    trainer=Trainer(
         epochs=params.epochs,
         batch_size=params.batch_size,
         learning_rate=lr,
         num_batches_per_epoch=params.num_batches_per_epoch      ),
    conditioning_length = params.conditioning_length,
    use_marginal_transformation = False
   )
   
   
   
   
 if modele == "gpscaling":
   from gluonts.mx.trainer import Trainer
   estimator = GPVAREstimator(
            target_dim=target_dim,
            num_cells = num_cells,
            dropout_rate=params.dropout_rate,
            prediction_length=prediction_length,
            cell_type="lstm",
            target_dim_sample=params.target_dim_sample,
            lags_seq = params.lags_seq2,
            conditioning_length = params.conditioning_length,
            scaling=False,
            freq=freq,
            rank = params.rank,
            use_marginal_transformation=True,
            distr_output=LowrankGPOutput(rank = params.rank, dim = target_dim),
            trainer=Trainer(
         epochs=params.epochs,
         batch_size=params.batch_size,
         learning_rate=lr,
         num_batches_per_epoch=params.num_batches_per_epoch      )
        )
 



 if modele == "gpcop":
   from gluonts.mx.trainer import Trainer
   estimator = GPVAREstimator(
            target_dim=target_dim,
            dropout_rate=params.dropout_rate,
            prediction_length=prediction_length,
            cell_type="lstm",
            num_cells = num_cells,
            target_dim_sample=params.target_dim_sample,
            lags_seq = params.lags_seq2,
            conditioning_length = params.conditioning_length,
            scaling=False,
            freq=freq,
            rank = params.rank,
            use_marginal_transformation=True,
            distr_output=LowrankGPOutput(rank = params.rank, dim = target_dim),
            trainer=Trainer(
         epochs=params.epochs,
         batch_size=params.batch_size,
         learning_rate=lr,
         num_batches_per_epoch=params.num_batches_per_epoch      ),
        )




 if modele == "lstmmaf":
   from pts import Trainer
   estimator = TempFlowEstimator(
    target_dim=target_dim,
    prediction_length=prediction_length,
    cell_type = 'LSTM',
    input_size = 564,
    lags_seq = params.lags_seq2,
    num_cells = num_cells,
    freq=freq,
    n_blocks = 2,
    scaling = False,
    dequantize = False,
    flow_type = 'MAF',
    trainer=Trainer(
         epochs=params.epochs,
         batch_size=params.batch_size,
         learning_rate=lr,
         num_batches_per_epoch=params.num_batches_per_epoch),
    )
  
   
 return estimator





#test0 = {'model':'lstmmaf', 'num_cells':40  ,  'lr':1e-3, 'num_cells1':20, 'num_cells2':40}
test1 = {'model':'deepnegpol', 'num_cells':80  ,  'lr':1e-3, 'num_cells1':20, 'num_cells2':40}
#test2 = {'model':'lstmcop', 'num_cells':40  ,  'lr':1e-3, 'num_cells1':20, 'num_cells2':40}
#test3 = {'model':'lstmindscaling', 'num_cells':40  ,  'lr':1e-3, 'num_cells1':20, 'num_cells2':40}
#test4 = {'model':'gpcop', 'num_cells':40  ,  'lr':1e-3, 'num_cells1':20, 'num_cells2':40}
#test5 = {'model':'gpscaling', 'num_cells':40  ,  'lr':1e-3, 'num_cells1':20, 'num_cells2':40}
#test6 = {'model':'timegrad', 'num_cells':40  ,  'lr':1e-3, 'num_cells1':20, 'num_cells2':40}

def main():
    list_tests_str = ['test' + str(i) for i in range(0, 25)]
    list_tests = []
    data = "bike"
    for test in list_tests_str:
        if test in locals():
            list_tests.append(eval(test))

    for test in list_tests:
        for rep in range(0, 3):
            print(f"Essai numéro {rep} du modele {test['model']} avec {test['num_cells']} cellules")
            estimator = estimator_model(test)
            try:
                predictor = estimator.train(train_ds, num_workers=2)
                targets, forecasts = metrics_rolling_dataset2(test_ds, predictor, params, test, rep, data)
            except Exception as e:
                print("An exception occurred: ", e)
                # traceback.print_exc()

if __name__ == '__main__':
    main()

But I still can’t run the code and received the following notification

PS D:InternPaulProbabilistic_forecasting-mainProbabilistic_forecasting-main> & C:/Users/ASUS/anaconda3/envs/test6/python.exe d:/Intern/Paul/Probabilistic_forecasting-main/Probabilistic_forecasting-main/example_bike.py
Experiment with bike data

Could you please help me with that problem? Thank you very much
p.s: I am using windows 11, I created an environment with annaconda.

I tried to modify the code based on what ChatGPT suggested but it doesn’t work.

New contributor

Pipnap is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật