qlib icon indicating copy to clipboard operation
qlib copied to clipboard

why the examples workflow_config_transformer_Alpha360.yaml can not work

Open CamelShoko opened this issue 7 months ago • 1 comments

❓ why the examples workflow_config_transformer_Alpha360.yaml can not work

cd qlib/examples/benchmarks/Transformer
qrun workflow_config_transformer_Alpha360.yaml
[2948750:MainThread](2025-05-15 08:18:15,686) INFO - qlib.qrun - [cli.py:78] - Render the template with the context: {}
[2948750:MainThread](2025-05-15 08:18:15,704) INFO - qlib.Initialization - [config.py:420] - default_conf: client.
[2948750:MainThread](2025-05-15 08:18:15,708) INFO - qlib.Initialization - [__init__.py:74] - qlib successfully initialized based on client settings.
[2948750:MainThread](2025-05-15 08:18:15,708) INFO - qlib.Initialization - [__init__.py:76] - data_path={'__DEFAULT_FREQ': PosixPath('/home/r730/.qlib/qlib_data/cn_data')}
[2948750:MainThread](2025-05-15 08:18:15,721) INFO - qlib.workflow - [exp.py:258] - Experiment 848419226136946974 starts running ...
[2948750:MainThread](2025-05-15 08:18:16,647) INFO - qlib.workflow - [recorder.py:345] - Recorder 697efc8737e14a7b998fcdcbd4d9ec5c starts running under Experiment 848419226136946974 ...
[2948750:MainThread](2025-05-15 08:18:27,028) INFO - qlib.TransformerModel - [pytorch_transformer.py:63] - Naive Transformer:
batch_size : 2048
device : cuda:0
/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/torch/nn/modules/transformer.py:382: UserWarning: enable_nested_tensor is True, but self.use_nested_tensor is False because encoder_layer.self_attn.batch_first was not True(use batch_first for better inference performance)
  warnings.warn(
[2948750:MainThread](2025-05-15 08:18:58,591) INFO - qlib.timer - [log.py:127] - Time cost: 27.738s | Loading data Done
[2948750:MainThread](2025-05-15 08:19:23,602) INFO - qlib.timer - [log.py:127] - Time cost: 20.276s | RobustZScoreNorm Done
[2948750:MainThread](2025-05-15 08:19:25,622) INFO - qlib.timer - [log.py:127] - Time cost: 2.018s | Fillna Done
[2948750:MainThread](2025-05-15 08:19:29,189) INFO - qlib.timer - [log.py:127] - Time cost: 0.625s | DropnaLabel Done
/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/qlib/data/dataset/processor.py:363: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  df[cols] = t
[2948750:MainThread](2025-05-15 08:19:29,498) INFO - qlib.timer - [log.py:127] - Time cost: 0.308s | CSRankNorm Done
[2948750:MainThread](2025-05-15 08:19:29,522) INFO - qlib.timer - [log.py:127] - Time cost: 30.929s | fit & process data Done
[2948750:MainThread](2025-05-15 08:19:29,523) INFO - qlib.timer - [log.py:127] - Time cost: 58.672s | Init data Done
[2948750:MainThread](2025-05-15 08:19:29,524) WARNING - qlib.utils - [__init__.py:849] - The parameter `reweighter` with value `None` is ignored.
[2948750:MainThread](2025-05-15 08:19:31,938) INFO - qlib.TransformerModel - [pytorch_transformer.py:183] - training...
[2948750:MainThread](2025-05-15 08:19:31,939) INFO - qlib.TransformerModel - [pytorch_transformer.py:187] - Epoch0:
[2948750:MainThread](2025-05-15 08:19:31,940) INFO - qlib.TransformerModel - [pytorch_transformer.py:188] - training...
[2948750:MainThread](2025-05-15 08:20:02,793) INFO - qlib.TransformerModel - [pytorch_transformer.py:190] - evaluating...
[2948750:MainThread](2025-05-15 08:20:16,035) INFO - qlib.TransformerModel - [pytorch_transformer.py:193] - train nan, valid nan
[2948750:MainThread](2025-05-15 08:20:16,036) INFO - qlib.TransformerModel - [pytorch_transformer.py:187] - Epoch1:
[2948750:MainThread](2025-05-15 08:20:16,036) INFO - qlib.TransformerModel - [pytorch_transformer.py:188] - training...
[2948750:MainThread](2025-05-15 08:20:45,009) INFO - qlib.TransformerModel - [pytorch_transformer.py:190] - evaluating...
[2948750:MainThread](2025-05-15 08:20:58,209) INFO - qlib.TransformerModel - [pytorch_transformer.py:193] - train nan, valid nan
[2948750:MainThread](2025-05-15 08:20:58,210) INFO - qlib.TransformerModel - [pytorch_transformer.py:187] - Epoch2:
[2948750:MainThread](2025-05-15 08:20:58,210) INFO - qlib.TransformerModel - [pytorch_transformer.py:188] - training...
[2948750:MainThread](2025-05-15 08:21:27,148) INFO - qlib.TransformerModel - [pytorch_transformer.py:190] - evaluating...
[2948750:MainThread](2025-05-15 08:21:40,349) INFO - qlib.TransformerModel - [pytorch_transformer.py:193] - train nan, valid nan
[2948750:MainThread](2025-05-15 08:21:40,350) INFO - qlib.TransformerModel - [pytorch_transformer.py:187] - Epoch3:
[2948750:MainThread](2025-05-15 08:21:40,351) INFO - qlib.TransformerModel - [pytorch_transformer.py:188] - training...
[2948750:MainThread](2025-05-15 08:22:09,294) INFO - qlib.TransformerModel - [pytorch_transformer.py:190] - evaluating...
[2948750:MainThread](2025-05-15 08:22:22,488) INFO - qlib.TransformerModel - [pytorch_transformer.py:193] - train nan, valid nan
[2948750:MainThread](2025-05-15 08:22:22,489) INFO - qlib.TransformerModel - [pytorch_transformer.py:187] - Epoch4:
[2948750:MainThread](2025-05-15 08:22:22,490) INFO - qlib.TransformerModel - [pytorch_transformer.py:188] - training...
[2948750:MainThread](2025-05-15 08:22:51,435) INFO - qlib.TransformerModel - [pytorch_transformer.py:190] - evaluating...
[2948750:MainThread](2025-05-15 08:23:04,639) INFO - qlib.TransformerModel - [pytorch_transformer.py:193] - train nan, valid nan
[2948750:MainThread](2025-05-15 08:23:04,640) INFO - qlib.TransformerModel - [pytorch_transformer.py:205] - early stop
[2948750:MainThread](2025-05-15 08:23:04,641) INFO - qlib.TransformerModel - [pytorch_transformer.py:208] - best score: -inf @ 0
[2948750:MainThread](2025-05-15 08:23:04,642) INFO - qlib.timer - [log.py:127] - Time cost: 0.001s | waiting `async_log` Done
[2948750:MainThread](2025-05-15 08:23:04,646) ERROR - qlib.workflow - [utils.py:41] - An exception has been raised[UnboundLocalError: cannot access local variable 'best_param' where it is not associated with a value].
  File "/home/r730/miniconda3/envs/qlib/bin/qrun", line 8, in <module>
    sys.exit(run())
             ^^^^^
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/qlib/workflow/cli.py", line 153, in run
    fire.Fire(workflow)
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/fire/core.py", line 135, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/fire/core.py", line 468, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
                                ^^^^^^^^^^^^^^^^^^^^
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/fire/core.py", line 684, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/qlib/workflow/cli.py", line 147, in workflow
    recorder = task_train(config.get("task"), experiment_name=experiment_name)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/qlib/model/trainer.py", line 127, in task_train
    _exe_task(task_config)
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/qlib/model/trainer.py", line 49, in _exe_task
    auto_filter_kwargs(model.fit)(dataset, reweighter=reweighter)
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/qlib/utils/__init__.py", line 852, in _func
    return func(*args, **new_kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/r730/miniconda3/envs/qlib/lib/python3.12/site-packages/qlib/contrib/model/pytorch_transformer.py", line 209, in fit
    self.model.load_state_dict(best_param)
                               ^^^^^^^^^^
UnboundLocalError: cannot access local variable 'best_param' where it is not associated with a value

CamelShoko avatar May 15 '25 08:05 CamelShoko

Hi, @CamelShoko I pulled the latest code, created the virtual environment and installed it, then ran the qrun examples/benchmarks/Transformer/workflow_config_transformer_Alpha360.yaml command and didn't find the problem you mentioned, how should your problem be reproduced?

SunsetWolf avatar May 16 '25 08:05 SunsetWolf