pytorch lightning Tuner(trainer).lr_find() raises FileNotFoundError with placeholder variable "<input>" for filename

32 Views Asked by At

I am trying to replicate this getting started example from pytorch forecasting it is not working due to a FileNotFoundError in the when using lr_find() method of the Tuner class.

My code looks like this:

early_stop_callback = EarlyStopping(monitor="val_loss", min_delta=1e-4, patience=1, verbose=False, mode="min")
lr_logger = LearningRateMonitor()
trainer = pl.Trainer(
    max_epochs=100,
    accelerator="mps",
    devices=1,
    gradient_clip_val=0.1,
    limit_train_batches=30,
    log_every_n_steps=1,
    callbacks=[lr_logger, early_stop_callback],
)

# create the model
tft = TemporalFusionTransformer.from_dataset(
    training,
    learning_rate=0.03,
    hidden_size=32,
    attention_head_size=1,
    dropout=0.1,
    hidden_continuous_size=16,
    output_size=13,
    loss=QuantileLoss(),
    log_interval=2,
    reduce_on_plateau_patience=4
)

print(f"Number of parameters in network: {tft.size()/1e3:.1f}k")

# find optimal learning rate (set limit_train_batches to 1.0 and log_interval = -1)
res = Tuner(trainer).lr_find(
    tft,
    train_dataloaders=train_dataloader,
    val_dataloaders=val_dataloader,
    early_stop_threshold=1000.0,
    max_lr=0.3,
)

But when I run the part with res = Tuner(trainer).lr_find(...) I get a FileNotFoundError:

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/Username/miniconda3/envs/Favoritas/lib/python3.10/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/Users/Username/miniconda3/envs/Favoritas/lib/python3.10/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/Users/Username/miniconda3/envs/Favoritas/lib/python3.10/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/Users/Username/miniconda3/envs/Favoritas/lib/python3.10/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/Users/Username/miniconda3/envs/Favoritas/lib/python3.10/runpy.py", line 288, in run_path
    code, fname = _get_code_from_file(run_name, path_name)
  File "/Users/Username/miniconda3/envs/Favoritas/lib/python3.10/runpy.py", line 252, in _get_code_from_file
    with io.open_code(decoded_path) as f:
FileNotFoundError: [Errno 2] No such file or directory: '/Users/Username/Documents/GitHub/Favoritas/<input>'

In the indicated sources I just cannot find something like '<input>', which seems like a placeholder variable to me and so I cannot find out which file is missing. My guess is, that it refers somehow to the lightning_logs folder, but this folder exists already, so it is not supposed to throw the error though.

I am using Pycharm CE version 2023.3.3. on a Mac with macOS Ventura 13.6 and an Apple M1 Chip.

Python version is 3.10 and package versions are:

  • pytorch-lightning: 2.0.3

  • pytorch-forecasting: 1.0.0

  • torch 2.1.2

I have searched the web, but was not able to find anything similar. All I found were solutions to the generic FileNotFoundError like the wrong path or something totally different.

I also tried to fix it via the argument default_root_dir=os.getcwd() in the initiation of the trainer but it does not help because current working directory via os.getcwd() is the one I get the error message for.

Do you have any ideas where in the module this '<input>' is generated and what I have to do to fix the error? Any help is much appreciated!

0

There are 0 best solutions below