Skip to content

Instantly share code, notes, and snippets.

@justinhchae
Created February 28, 2021 16:38
Show Gist options
  • Select an option

  • Save justinhchae/1a06e6ffa61f9094372538a12cb79fa2 to your computer and use it in GitHub Desktop.

Select an option

Save justinhchae/1a06e6ffa61f9094372538a12cb79fa2 to your computer and use it in GitHub Desktop.
# how to pool processes for prophet
# given chunked data from data_chunker.py
# https://gist.github.com/justinhchae/13d246e8e2e2d521a8d2cce20eb09a09
# given prophet function wrapper
# https://gist.github.com/justinhchae/8ef78743f13f50051ad1aca2106eaa1a
# dependencies
from tqdm import tqdm
import torch
import torch.multiprocessing as mp
from functools import partial
if __name__ == '__main__':
# given a dataframe, df
chunked_data = chunk_data(df, price_col='c', time_col='t', n_prediction_units=1)
model = run_prophet
p = mp.Pool(8)
# pass the model and its params to a new partial object
model_ = partial(model, n_prediction_units=1)
# iterate over the partial object and the data
# wrap the object inside tqdm to get a progress bar
results = list(tqdm(p.imap(model_, chunked_data)))
# close out the pool
p.close()
p.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment