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

Cannot set logging directory when using a saved model #1062

Open
1 task done
hom-bahrani opened this issue Dec 11, 2022 · 4 comments
Open
1 task done

Cannot set logging directory when using a saved model #1062

hom-bahrani opened this issue Dec 11, 2022 · 4 comments
Labels
bug Something isn't working P2 Medium priority

Comments

@hom-bahrani
Copy link

Prerequisites

Describe the bug

I trained a model in Google Colab and then exported this model to GCP for inference using the neuralprophet save and load methods. I deployed the model to both a VM instance and Cloud functions and noticed the same error. When loading the saved model I think the MetricsLogger directory is not being set, and as a result it seems like a read only directory is being used for the logger when I try to call the predict method. I replicated the error in a virtual env on my mac

Traceback (most recent call last):
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/loggers/tensorboard.py", line 232, in log_metrics
    self.experiment.add_scalar(k, v, step)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/loggers/logger.py", line 54, in experiment
    return get_experiment() or DummyExperiment()
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/utilities/rank_zero.py", line 32, in wrapped_fn
    return fn(*args, **kwargs)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/loggers/logger.py", line 52, in get_experiment
    return fn(self)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/loggers/tensorboard.py", line 175, in experiment
    self._fs.makedirs(self.root_dir, exist_ok=True)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/fsspec/implementations/local.py", line 50, in makedirs
    os.makedirs(path, exist_ok=exist_ok)
  File "/usr/local/bin/../../../Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 213, in makedirs
    makedirs(head, exist_ok=exist_ok)
  File "/usr/local/bin/../../../Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/os.py", line 223, in makedirs
    mkdir(name, mode)
OSError: [Errno 30] Read-only file system: '/content'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "main.py", line 150, in <module>
    predicted_value = get_predictions()
  File "main.py", line 134, in get_predictions
    preds = loaded_model.predict(future_df)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/neuralprophet/forecaster.py", line 883, in predict
    dates, predicted, components = self._predict_raw(df_i, df_name, include_components=decompose)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/neuralprophet/forecaster.py", line 2926, in _predict_raw
    result = self.trainer.predict(self.model, loader)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 950, in predict
    self._predict_impl, model, dataloaders, datamodule, return_predictions, ckpt_path
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 650, in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 996, in _predict_impl
    results = self._run(model, ckpt_path=self.ckpt_path)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1154, in _run
    self._log_hyperparams()
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/trainer/trainer.py", line 1222, in _log_hyperparams
    logger.log_hyperparams(hparams_initial)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/utilities/rank_zero.py", line 32, in wrapped_fn
    return fn(*args, **kwargs)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/loggers/tensorboard.py", line 211, in log_hyperparams
    self.log_metrics(metrics, 0)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/utilities/rank_zero.py", line 32, in wrapped_fn
    return fn(*args, **kwargs)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/neuralprophet/logger.py", line 29, in log_metrics
    super(MetricsLogger, self).log_metrics(metrics, step)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/utilities/rank_zero.py", line 32, in wrapped_fn
    return fn(*args, **kwargs)
  File "/Users/hombahrani/Code/prophet_version_test/prophet_module/lib/python3.7/site-packages/pytorch_lightning/loggers/tensorboard.py", line 236, in log_metrics
    raise ValueError(m) from ex
ValueError: 
 you tried to log -1 which is currently not supported. Try a dict or a scalar/tensor.
@hom-bahrani
Copy link
Author

I realised the /content directory in the Traceback is coming from colab, I can get around this by hardcoding the directory to match the deployment env e.g. /tmp which is used in Cloud functions and can be written to, alternatively I can also train and deploy in the same VM instance. I like the idea of training in colab though as its free

@hom-bahrani
Copy link
Author

Not sure if this would be easy to implement, but it would be nice to pass in the name of the logging directory when loading a model

@hom-bahrani hom-bahrani changed the title [Bug] Cannot set logging directory when using a saved model Cannot set logging directory when using a saved model Dec 12, 2022
@karl-richter karl-richter added bug Something isn't working P2 Medium priority labels Feb 17, 2023
@leoniewgnr
Copy link
Collaborator

hi @hom-bahrani, we see that this is a relevant feature, but currently have no capacity to work on this.
Would you like to work on this?

@linhsinp
Copy link

linhsinp commented May 4, 2023

Hi there, our team is also having this issue in the process of deploying a project. Unfortunately we cannot spend time on the subject right now. Just a heads-up. Thank you for providing your thoughts @hom-bahrani - it helped us identify the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2 Medium priority
Projects
Status: Needs triage
Development

No branches or pull requests

4 participants