Repository: huggingface/trl

Issue:
from trl import SFTTrainer getting issue 
when importing  SFTTrainer from trl then getting below issue 

Same happening when i copy and paste the trl code from github

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
File /opt/conda/lib/python3.10/site-packages/trl/import_utils.py:172, in _LazyModule._get_module(self, module_name)
    171 try:
--> 172     return importlib.import_module("." + module_name, self.__name__)
    173 except Exception as e:

File /opt/conda/lib/python3.10/importlib/__init__.py:126, in import_module(name, package)
    125         level += 1
--> 126 return _bootstrap._gcd_import(name[level:], package, level)

File <frozen importlib._bootstrap>:1050, in _gcd_import(name, package, level)

File <frozen importlib._bootstrap>:1027, in _find_and_load(name, import_)

File <frozen importlib._bootstrap>:1006, in _find_and_load_unlocked(name, import_)

File <frozen importlib._bootstrap>:688, in _load_unlocked(spec)

File <frozen importlib._bootstrap_external>:883, in exec_module(self, module)

File <frozen importlib._bootstrap>:241, in _call_with_frames_removed(f, *args, **kwds)

File /opt/conda/lib/python3.10/site-packages/trl/trainer/sft_trainer.py:23
     22 from accelerate.state import PartialState
---> 23 from datasets import Dataset
     24 from datasets.arrow_writer import SchemaInferenceError

File /opt/conda/lib/python3.10/site-packages/datasets/__init__.py:18
     16 __version__ = "2.18.0"
---> 18 from .arrow_dataset import Dataset
     19 from .arrow_reader import ReadInstruction

File /opt/conda/lib/python3.10/site-packages/datasets/arrow_dataset.py:66
     64 from tqdm.contrib.concurrent import thread_map
---> 66 from . import config
     67 from .arrow_reader import ArrowReader

File /opt/conda/lib/python3.10/site-packages/datasets/config.py:41
     40 DILL_VERSION = version.parse(importlib.metadata.version("dill"))
---> 41 FSSPEC_VERSION = version.parse(importlib.metadata.version("fsspec"))
     42 PANDAS_VERSION = version.parse(importlib.metadata.version("pandas"))

File /opt/conda/lib/python3.10/site-packages/packaging/version.py:49, in parse(version)
     48 try:
---> 49     return Version(version)
     50 except InvalidVersion:

File /opt/conda/lib/python3.10/site-packages/packaging/version.py:264, in Version.__init__(self, version)
    261 def __init__(self, version: str) -> None:
    262 
    263     # Validate the version and parse it into pieces
--> 264     match = self._regex.search(version)
    265     if not match:

TypeError: expected string or bytes-like object

The above exception was the direct cause of the following exception:

RuntimeError                              Traceback (most recent call last)
Cell In[4], line 4
      2 import transformers
      3 import torch
----> 4 from trl import SFTTrainer
      5 from peft import LoraConfig
      6 from transformers import AutoTokenizer, AutoModelForCausalLM

File <frozen importlib._bootstrap>:1075, in _handle_fromlist(module, fromlist, import_, recursive)

File /opt/conda/lib/python3.10/site-packages/trl/import_utils.py:163, in _LazyModule.__getattr__(self, name)
    161 elif name in self._class_to_module.keys():
    162     module = self._get_module(self._class_to_module[name])
--> 163     value = getattr(module, name)
    164 else:
    165     raise AttributeError(f"module {self.__name__} has no attribute {name}")

File /opt/conda/lib/python3.10/site-packages/trl/import_utils.py:162, in _LazyModule.__getattr__(self, name)
    160     value = self._get_module(name)
    161 elif name in self._class_to_module.keys():
--> 162     module = self._get_module(self._class_to_module[name])
    163     value = getattr(module, name)
    164 else:

File /opt/conda/lib/python3.10/site-packages/trl/import_utils.py:174, in _LazyModule._get_module(self, module_name)
    172     return importlib.import_module("." + module_name, self.__name__)
    173 except Exception as e:
--> 174     raise RuntimeError(
    175         f"Failed to import {self.__name__}.{module_name} because of the following error (look up to see its"
    176         f" traceback):\n{e}"
    177     ) from e

RuntimeError: Failed to import trl.trainer.sft_trainer because of the following error (look up to see its traceback):
expected string or bytes-like object


Discussion:
Hi @DimensionZer0 
Thanks for the issue! 
just tried it locally and the import worked for me, it also works in our CI, can you try again on a fresh new env?
```bash
 > python
Python 3.9.12 | packaged by conda-forge | (main, Mar 24 2022, 23:25:14)
[Clang 12.0.1 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from trl import SFTTrainer
>>>
```
Can you share more details about your setup / env?
I am using kaggle notebook @younesbelkada  and still getting same issue ..

version of python is 3.10.13

Till yesterday it was working for me  on same env
its working in my local but getting issue in kaggle notebook 
I can confirm, I am also receiving this error using Kaggle notebooks, on both 0.8.0 and 0.8.1 of trl. Trying 0.7.11 gave me #1409.

Resolving patch:
diff --git a/trl/__init__.py b/trl/__init__.py
--- a/trl/__init__.py
+++ b/trl/__init__.py
@@ -51,7 +51,7 @@
         "SFTTrainer",
     ],
     "commands": [],
-    "commands.utils": ["SftArgumentParser", "init_zero_verbose", "TrlParser", "DpoArgumentParser"],
+    "commands.cli_utils": ["init_zero_verbose", "SftScriptArguments", "DpoScriptArguments", "TrlParser"],
     "trainer.utils": ["get_kbit_device_map", "get_peft_config", "get_quantization_config", "RichProgressCallback"],
     "multitask_prompt_tuning": [
         "MultitaskPromptEmbedding",
@@ -115,7 +115,7 @@
         SFTTrainer,
     )
     from .trainer.utils import get_kbit_device_map, get_peft_config, get_quantization_config, RichProgressCallback
-    from .commands.utils import init_zero_verbose, SftScriptArguments, DpoScriptArguments, TrlParser
+    from .commands.cli_utils import init_zero_verbose, SftScriptArguments, DpoScriptArguments, TrlParser
 
     try:
         if not is_diffusers_available():


Test patch: