interscript / rababa

Rababa, the diacritization library for Arabic and Hebrew (Abjad scripts in general)
12 stars 1 forks source link

Enable CPU training #22

Closed ronaldtse closed 3 years ago

ronaldtse commented 3 years ago

Currently fails with no GPU:

  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 852, in to
    return self._apply(convert)
  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 530, in _apply
    module._apply(fn)
  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 552, in _apply
    param_applied = fn(param)
  File "/usr/local/lib/python3.9/site-packages/torch/nn/modules/module.py", line 850, in convert
    return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
  File "/usr/local/lib/python3.9/site-packages/torch/cuda/__init__.py", line 166, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled
gilgameshjw commented 3 years ago

done

ronaldtse commented 3 years ago

I'm facing this double-invocation error:

The model has 15413521 trainable parameters parameters
/usr/local/lib/python3.9/site-packages/torch/cuda/amp/grad_scaler.py:115: UserWarning: torch.cuda.amp.GradScaler is enabled, but CUDA is not available.  Disabling.
  warnings.warn("torch.cuda.amp.GradScaler is enabled, but CUDA is not available.  Disabling.")
Length of training iterator = 86962
Length of valid iterator = 4676
data loaded
----------------------------------------------------------
Eval:   0%|                                                                                                                                 | 0/4676 [00:00<?, ?it/sTraceback (most recent call last):                                                                                                           | 0/4676 [00:00<?, ?it/s]
  File "<string>", line 1, in <module>                                                                                                   | 0/2000000 [00:00<?, ?it/s]
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/me/src/interscript/rababa/python/train.py", line 43, in <module>
    trainer.run()
  File "/Users/me/src/interscript/rababa/python/trainer.py", line 209, in run
    for batch_inputs in repeater(train_iterator):
  File "/Users/me/src/interscript/rababa/python/util/utils.py", line 64, in repeater
    for data in loader:
  File "/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 359, in __iter__
    return self._get_iterator()
  File "/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 305, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
  File "/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 918, in __init__
    w.start()
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError: 
        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.
gilgameshjw commented 3 years ago

should be solved.

ronaldtse commented 3 years ago

@gilgameshjw I'm still seeing the same issue... double invocation, and no progress:

me:~/src/interscript/rababa/python (main *): python3.9 train.py --model "cbhg" --config config/cbhg.yml

CONFIGURATION CA_MSA.base.cbhg
- session_name : base
- data_directory : data
- data_type : CA_MSA
- log_directory : log_dir
- load_training_data : True
- load_test_data : False
- load_validation_data : True
- n_training_examples : None
- n_test_examples : None
- n_validation_examples : None
- test_file_name : test.csv
- is_data_preprocessed : False
- data_separator : |
- diacritics_separator : *
- text_encoder : ArabicEncoderWithStartSymbol
- text_cleaner : valid_arabic_cleaners
- max_len : 600
- reconcile : True
- max_steps : 2000000
- learning_rate : 0.001
- batch_size : 32
- adam_beta1 : 0.9
- adam_beta2 : 0.999
- use_decay : True
- weight_decay : 0.0
- embedding_dim : 256
- use_prenet : False
- prenet_sizes : [512, 256]
- cbhg_projections : [128, 256]
- cbhg_filters : 16
- cbhg_gru_units : 256
- post_cbhg_layers_units : [256, 256]
- post_cbhg_use_batch_norm : True
- use_mixed_precision : False
- optimizer_type : Adam
- device : cuda
- evaluate_frequency : 5000
- evaluate_with_error_rates_frequency : 5000
- n_predicted_text_tensorboard : 10
- model_save_frequency : 5000
- train_plotting_frequency : 50000000
- n_steps_avg_losses : [100, 500, 1000, 5000]
- error_rates_n_batches : 10000
- test_model_path : None
- train_resume_model_path : None
- len_input_symbols : 44
- len_target_symbols : 17
- optimizer : OptimizerType.Adam
- git_hash : v0.1.0-34-g4e8ffa9
The model has 15413521 trainable parameters parameters
/usr/local/lib/python3.9/site-packages/torch/cuda/amp/grad_scaler.py:115: UserWarning: torch.cuda.amp.GradScaler is enabled, but CUDA is not available.  Disabling.
  warnings.warn("torch.cuda.amp.GradScaler is enabled, but CUDA is not available.  Disabling.")
Length of training iterator = 86962
Length of valid iterator = 4676
data loaded
----------------------------------------------------------
Eval:   0%|                                                                                                                                 | 0/4676 [00:00<?, ?it/s]
CONFIGURATION CA_MSA.base.cbhg                                                                                                              | 0/4676 [00:00<?, ?it/s]
- session_name : base                                                                                                                    | 0/2000000 [00:00<?, ?it/s]
- data_directory : data
- data_type : CA_MSA
- log_directory : log_dir
- load_training_data : True
- load_test_data : False
- load_validation_data : True
- n_training_examples : None
- n_test_examples : None
- n_validation_examples : None
- test_file_name : test.csv
- is_data_preprocessed : False
- data_separator : |
- diacritics_separator : *
- text_encoder : ArabicEncoderWithStartSymbol
- text_cleaner : valid_arabic_cleaners
- max_len : 600
- reconcile : True
- max_steps : 2000000
- learning_rate : 0.001
- batch_size : 32
- adam_beta1 : 0.9
- adam_beta2 : 0.999
- use_decay : True
- weight_decay : 0.0
- embedding_dim : 256
- use_prenet : False
- prenet_sizes : [512, 256]
- cbhg_projections : [128, 256]
- cbhg_filters : 16
- cbhg_gru_units : 256
- post_cbhg_layers_units : [256, 256]
- post_cbhg_use_batch_norm : True
- use_mixed_precision : False
- optimizer_type : Adam
- device : cuda
- evaluate_frequency : 5000
- evaluate_with_error_rates_frequency : 5000
- n_predicted_text_tensorboard : 10
- model_save_frequency : 5000
- train_plotting_frequency : 50000000
- n_steps_avg_losses : [100, 500, 1000, 5000]
- error_rates_n_batches : 10000
- test_model_path : None
- train_resume_model_path : None
- len_input_symbols : 44
- len_target_symbols : 17
- optimizer : OptimizerType.Adam
- git_hash : v0.1.0-34-g4e8ffa9
The model has 15413521 trainable parameters parameters
/usr/local/lib/python3.9/site-packages/torch/cuda/amp/grad_scaler.py:115: UserWarning: torch.cuda.amp.GradScaler is enabled, but CUDA is not available.  Disabling.
  warnings.warn("torch.cuda.amp.GradScaler is enabled, but CUDA is not available.  Disabling.")
Length of training iterator = 86962
Length of valid iterator = 4676
data loaded
----------------------------------------------------------
Eval:   0%|                                                                                                                                 | 0/4676 [00:00<?, ?it/sTraceback (most recent call last):                                                                                                           | 0/4676 [00:00<?, ?it/s]
  File "<string>", line 1, in <module>                                                                                                   | 0/2000000 [00:00<?, ?it/s]
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/me/src/interscript/rababa/python/train.py", line 43, in <module>
    trainer.run()
  File "/Users/me/src/interscript/rababa/python/trainer.py", line 210, in run
    for batch_inputs in repeater(train_iterator):
  File "/Users/me/src/interscript/rababa/python/util/utils.py", line 64, in repeater
    for data in loader:
  File "/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 359, in __iter__
    return self._get_iterator()
  File "/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 305, in _get_iterator
    return _MultiProcessingDataLoaderIter(self)
  File "/usr/local/lib/python3.9/site-packages/torch/utils/data/dataloader.py", line 918, in __init__
    w.start()
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "/usr/local/Cellar/python@3.9/3.9.6/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError: 
        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.
Eval:   0%|                                                                                                                                 | 0/4676 [00:00<?, ?it/s]
WER/DER : :   0%|                                                                                                                           | 0/4676 [00:00<?, ?it/s]
  0%|                                                                                                                                    | 0/2000000 [00:00<?, ?it/s]
ronaldtse commented 3 years ago

Works on GitHub Actions, but still failing locally... there seems to be a double invocation still in the logs.

gilgameshjw commented 3 years ago

i think i fixed it yesterday

gilgameshjw commented 3 years ago

Never seen that pbm that I dont understand.

Was python installed with conda, 3.6? That might be the issue!

ronaldtse commented 3 years ago

I just tried Pyenv with 3.7, upgraded pip, and updated setup.py. It seems to work! (Just extremely slow...)


CONFIGURATION CA_MSA.base.cbhg
- session_name : base
- data_directory : data
- data_type : CA_MSA
- log_directory : log_dir
- load_training_data : True
- load_test_data : False
- load_validation_data : True
- n_training_examples : None
- n_test_examples : None
- n_validation_examples : None
- test_file_name : test.csv
- is_data_preprocessed : False
- data_separator : |
- diacritics_separator : *
- text_encoder : ArabicEncoderWithStartSymbol
- text_cleaner : valid_arabic_cleaners
- max_len : 600
- reconcile : True
- max_steps : 2000000
- learning_rate : 0.001
- batch_size : 32
- adam_beta1 : 0.9
- adam_beta2 : 0.999
- use_decay : True
- weight_decay : 0.0
- embedding_dim : 256
- use_prenet : False
- prenet_sizes : [512, 256]
- cbhg_projections : [128, 256]
- cbhg_filters : 16
- cbhg_gru_units : 256
- post_cbhg_layers_units : [256, 256]
- post_cbhg_use_batch_norm : True
- use_mixed_precision : False
- optimizer_type : Adam
- device : cuda
- evaluate_frequency : 5000
- evaluate_with_error_rates_frequency : 5000
- n_predicted_text_tensorboard : 10
- model_save_frequency : 5000
- train_plotting_frequency : 50000000
- n_steps_avg_losses : [100, 500, 1000, 5000]
- error_rates_n_batches : 10000
- test_model_path : None
- train_resume_model_path : None
- len_input_symbols : 44
- len_target_symbols : 17
- optimizer : OptimizerType.Adam
- git_hash : v0.1.0-61-g46102ec
The model has 15413521 trainable parameters parameters
/Users/me/.pyenv/versions/3.7.11/lib/python3.7/site-packages/torch/cuda/amp/grad_scaler.py:115: UserWarning: torch.cuda.amp.GradScaler is enabled, but CUDA is not available.  Disabling.
  warnings.warn("torch.cuda.amp.GradScaler is enabled, but CUDA is not available.  Disabling.")
Length of training iterator = 86962
Length of valid iterator = 4676
data loaded
----------------------------------------------------------
Eval:   0%|                                                                                 | 0/4676 [00:00<?, ?it/s[W ParallelNative.cpp:212] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)           | 0/2000000 [00:00<?, ?it/s]
[W ParallelNative.cpp:212] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
                                                                                                                    /Users/me/.pyenv/versions/3.7.11/lib/python3.7/site-packages/torch/nn/functional.py:652: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  ../c10/core/TensorImpl.h:1156.)
  return torch.max_pool1d(input, kernel_size, stride, padding, dilation, ceil_mode)

Global Step 4:   0%|                                                        | 3/2000000 [00:26<4821:01:28,  8.68s/it]
loss: 3.081960916519165                                                     
ronaldtse commented 3 years ago

There are some warnings, but doesn't seem to affect training:

[W ParallelNative.cpp:212] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native 

[W ParallelNative.cpp:212] Warning: Cannot set number of intraop threads after parallel work has started or after set_num_threads call when using native parallel backend (function set_num_threads)
                                                                                                                    /Users/me/.pyenv/versions/3.7.11/lib/python3.7/site-packages/torch/nn/functional.py:652: UserWarning: Named tensors and all their associated APIs are an experimental feature and subject to change. Please do not use them for anything important until they are released as stable. (Triggered internally at  ../c10/core/TensorImpl.h:1156.)

  return torch.max_pool1d(input, kernel_size, stride, padding, dilation, ceil_mode)
ronaldtse commented 3 years ago

Interestingly it works with Python 3.6, 3.7 but not 3.9 (haven't tried 3.8).

ronaldtse commented 3 years ago

Closing this since 3.7 works.