RuntimeError: Failed to import transformers.models.flaubert.modeling_flaubert because of the following error (look up to see its traceback): module 'signal' has no attribute 'SIGKILL'
Author: BenoitDalFerro
Pull request: no

### System Info

- `transformers` version: 4.24.0
- Platform: Windows-10-10.0.19044-SP0
- Python version: 3.9.13
- Huggingface_hub version: 0.10.1
- PyTorch version (GPU?): 1.13.0 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: No

### Who can help?

@sgugger, @D3xter1922 
@malfet (we now come across each other daily, the world is so small...)

Opening here to document for the wider crowd, this is actually a PyTorch issue affecting Windows which went cf. https://github.com/pytorch/pytorch/issues/85427

cf. [Removed XLMModel inheritance from FlaubertModel(torch+tf)](https://github.com/huggingface/transformers/commit/ed858f535474d822615f846917254d586d2a5a31)

cf in [particular blame lines 26-45](https://github.com/huggingface/transformers/blame/main/src/transformers/models/flaubert/modeling_flaubert.py)

error [caused by `from ...modeling_utils import PreTrainedModel, SequenceSummary, SQuADHead` line 37]
(https://github.com/huggingface/transformers/blob/main/src/transformers/models/flaubert/modeling_flaubert.py#L37)

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

Opening here to document for the wider crowd, this is a PyTorch issue affecting Windows which went cf. https://github.com/pytorch/pytorch/issues/85427

cf. complete stack trace for your reference only and closing

error [caused by `from ...modeling_utils import PreTrainedModel, SequenceSummary, SQuADHead` line 37]
(https://github.com/huggingface/transformers/blob/main/src/transformers/models/flaubert/modeling_flaubert.py#L37)

this goes down to the accelerate package

`from transformers import (FlaubertWithLMHeadModel)`

```
NOTE: Redirects are currently not supported in Windows or MacOs.
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~\miniconda3\envs\MyEnv\lib\site-packages\transformers\utils\import_utils.py:1076, in _LazyModule._get_module(self, module_name)
   1075 try:
-> 1076     return importlib.import_module("." + module_name, self.__name__)
   1077 except Exception as e:

File ~\miniconda3\envs\MyEnv\lib\importlib\__init__.py:127, in import_module(name, package)    126         level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1030, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1007, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:986, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:680, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:850, in exec_module(self, module)

File <frozen importlib._bootstrap>:228, in _call_with_frames_removed(f, *args, **kwds)

File ~\miniconda3\envs\MyEnv\lib\site-packages\transformers\models\flaubert\modeling_flaubert.py:37, in <module>
     29 from ...modeling_outputs import (
     30     BaseModelOutput,
     31     MaskedLMOutput,
   (...)
     35     TokenClassifierOutput,
     36 )
---> 37 from ...modeling_utils import PreTrainedModel, SequenceSummary, SQuADHead
     38 from ...pytorch_utils import apply_chunking_to_forward, find_pruneable_heads_and_indices, prune_linear_layer

File ~\miniconda3\envs\MyEnv\lib\site-packages\transformers\modeling_utils.py:78, in <module>
     77 if is_accelerate_available():
---> 78     from accelerate import __version__ as accelerate_version
     79     from accelerate import dispatch_model, infer_auto_device_map, init_empty_weights

File ~\miniconda3\envs\MyEnv\lib\site-packages\accelerate\__init__.py:7, in <module>
      5 __version__ = "0.13.2"
----> 7 from .accelerator import Accelerator
      8 from .big_modeling import cpu_offload, disk_offload, dispatch_model, init_empty_weights, load_checkpoint_and_dispatch

File ~\miniconda3\envs\MyEnv\lib\site-packages\accelerate\accelerator.py:27, in <module>
     25 import torch
---> 27 from .checkpointing import load_accelerator_state, load_custom_state, save_accelerator_state, save_custom_state
     28 from .data_loader import prepare_data_loader

File ~\miniconda3\envs\MyEnv\lib\site-packages\accelerate\checkpointing.py:24, in <module>
     22 from torch.cuda.amp import GradScaler
---> 24 from .utils import (
     25     MODEL_NAME,
     26     OPTIMIZER_NAME,
     27     RNG_STATE_NAME,
     28     SCALER_NAME,
     29     SCHEDULER_NAME,
     30     get_pretty_name,
     31     is_tpu_available,
     32     save,
     33 )
     36 if is_tpu_available(check_device=False):

File ~\miniconda3\envs\MyEnv\lib\site-packages\accelerate\utils\__init__.py:96, in <module>
     87     from .deepspeed import (
     88         DeepSpeedEngineWrapper,
     89         DeepSpeedOptimizerWrapper,
   (...)
     93         HfDeepSpeedConfig,
     94     )
---> 96 from .launch import PrepareForLaunch, _filter_args, get_launch_prefix
     97 from .memory import find_executable_batch_size

File ~\miniconda3\envs\MyEnv\lib\site-packages\accelerate\utils\launch.py:25, in <module>
     24 if is_torch_version(">=", "1.9.0"):
---> 25     import torch.distributed.run as distrib_run
     28 def get_launch_prefix():

File ~\miniconda3\envs\MyEnv\lib\site-packages\torch\distributed\run.py:386, in <module>
    385 from torch.distributed.elastic.utils.logging import get_logger
--> 386 from torch.distributed.launcher.api import LaunchConfig, elastic_launch
    389 log = get_logger()

File ~\miniconda3\envs\MyEnv\lib\site-packages\torch\distributed\launcher\__init__.py:10, in <module>
      1 #!/usr/bin/env/python3
      2 
      3 # Copyright (c) Facebook, Inc. and its affiliates.
   (...)
      6 # This source code is licensed under the BSD-style license found in the
      7 # LICENSE file in the root directory of this source tree.
---> 10 from torch.distributed.launcher.api import (  # noqa: F401
     11     LaunchConfig,
     12     elastic_launch,
     13     launch_agent,
     14 )

File ~\miniconda3\envs\MyEnv\lib\site-packages\torch\distributed\launcher\api.py:15, in <module>
     14 from torch.distributed.elastic import events, metrics
---> 15 from torch.distributed.elastic.agent.server.api import WorkerSpec
     16 from torch.distributed.elastic.agent.server.local_elastic_agent import LocalElasticAgent

File ~\miniconda3\envs\MyEnv\lib\site-packages\torch\distributed\elastic\agent\server\__init__.py:40, in <module>
     31 from .api import (  # noqa: F401
     32     ElasticAgent,
     33     RunResult,
   (...)
     38     WorkerState,
     39 )
---> 40 from .local_elastic_agent import TORCHELASTIC_ENABLE_FILE_TIMER, TORCHELASTIC_TIMER_FILE

File ~\miniconda3\envs\MyEnv\lib\site-packages\torch\distributed\elastic\agent\server\local_elastic_agent.py:19, in <module>
     17 from typing import Any, Dict, Optional, Tuple
---> 19 import torch.distributed.elastic.timer as timer
     20 from torch.distributed.elastic import events

File ~\miniconda3\envs\MyEnv\lib\site-packages\torch\distributed\elastic\timer\__init__.py:44, in <module>
     43 from .local_timer import LocalTimerClient, LocalTimerServer  # noqa: F401
---> 44 from .file_based_local_timer import FileTimerClient, FileTimerServer, FileTimerRequest

File ~\miniconda3\envs\MyEnv\lib\site-packages\torch\distributed\elastic\timer\file_based_local_timer.py:63, in <module>
     52         return json.dumps(
     53             {
     54                 "version": self.version,
   (...)
     59             },
     60         )
---> 63 class FileTimerClient(TimerClient):
     64     """
     65     Client side of ``FileTimerServer``. This client is meant to be used
     66     on the same host that the ``FileTimerServer`` is running on and uses
   (...)
     79                         negative or zero signal will not kill the process.
     80     """

File ~\miniconda3\envs\MyEnv\lib\site-packages\torch\distributed\elastic\timer\file_based_local_timer.py:81, in FileTimerClient()
     64 """
     65 Client side of ``FileTimerServer``. This client is meant to be used
     66 on the same host that the ``FileTimerServer`` is running on and uses
   (...)
     79                     negative or zero signal will not kill the process.
     80 """
---> 81 def __init__(self, file_path: str, signal=signal.SIGKILL) -> None:
     82     super().__init__()

AttributeError: module 'signal' has no attribute 'SIGKILL'

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Input In [3], in <cell line: 1>()
----> 1 from transformers import (PretrainedConfig, FlaubertConfig, AutoTokenizer, FlaubertTokenizer, FlaubertWithLMHeadModel, TrainingArguments, DataCollatorForLanguageModeling) #pipeline
      2 from datasets import (load_dataset, load_from_disk, concatenate_datasets, ClassLabel)
      3 import pytorch_lightning as pl

File <frozen importlib._bootstrap>:1055, in _handle_fromlist(module, fromlist, import_, recursive)

File ~\miniconda3\envs\MyEnv\lib\site-packages\transformers\utils\import_utils.py:1067, in _LazyModule.__getattr__(self, name)
   1065 elif name in self._class_to_module.keys():
   1066     module = self._get_module(self._class_to_module[name])
-> 1067     value = getattr(module, name)
   1068 else:
   1069     raise AttributeError(f"module {self.__name__} has no attribute {name}")

File ~\miniconda3\envs\MyEnv\lib\site-packages\transformers\utils\import_utils.py:1066, in _LazyModule.__getattr__(self, name)
   1064     value = self._get_module(name)
   1065 elif name in self._class_to_module.keys():
-> 1066     module = self._get_module(self._class_to_module[name])
   1067     value = getattr(module, name)
   1068 else:

File ~\miniconda3\envs\MyEnv\lib\site-packages\transformers\utils\import_utils.py:1078, in _LazyModule._get_module(self, module_name)
   1076     return importlib.import_module("." + module_name, self.__name__)
   1077 except Exception as e:
-> 1078     raise RuntimeError(
   1079         f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
   1080         f" traceback):\n{e}"
   1081     ) from e

RuntimeError: Failed to import transformers.models.flaubert.modeling_flaubert because of the following error (look up to see its traceback):
module 'signal' has no attribute 'SIGKILL'
```

### Expected behavior

flawless import as usual

Comments:
This is a PyTorch issue affecting Windows which went cf. https://github.com/pytorch/pytorch/issues/85427

actually reopening as bug on Windows PyTorch side makes Transformers crash

I'm not sure what you intend us to do to fix this, since it comes from PyTorch?

for pip would propose to add to requirement.txt torch<=1.12.1 ? and for conda feedstocks' environment.yaml pytorch<=1.12.1
point is Transformers do really crash on Windows with PyTorch=1.13.0

PyTorch is already pinned in the setup.

indeed, not yet visible downstream (pip, conda) as of currentbut quite right https://github.com/huggingface/transformers/blame/main/setup.py#L166
https://github.com/huggingface/transformers/pull/19989
closing