Compatability with `torchcodec`
Author: Samoed
Pull request: no
Labels: name: bug

### System Info

```
- `transformers` version: 4.57.1
- Platform: Linux-6.12.48-1-MANJARO-x86_64-with-glibc2.42
- Python version: 3.13.5
- Huggingface_hub version: 0.36.0
- Safetensors version: 0.5.3
- Accelerate version: not installed
- Accelerate config: not found
- DeepSpeed version: not installed
- PyTorch version (accelerator?): 2.9.0+cu128 (CUDA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: <fill in>
- Using GPU in script?: <fill in>
- GPU type: NVIDIA GeForce RTX 3050 Laptop GPU
```
```
aiohappyeyeballs==2.6.1
aiohttp==3.12.14
aiosignal==1.4.0
annotated-types==0.7.0
anyio==4.10.0
attrs==25.3.0
babel==2.17.0
backrefs==5.9
bibtexparser==1.4.3
certifi==2025.7.14
cfgv==3.4.0
charset-normalizer==3.4.2
click==8.2.1
colorama==0.4.6
coverage==7.10.0
datasets==4.4.1
dill==0.3.8
distlib==0.4.0
execnet==2.1.1
filelock==3.18.0
frozenlist==1.7.0
fsspec==2025.3.0
ghp-import==2.1.0
gitdb==4.0.12
gitpython==3.1.45
griffe==1.14.0
h11==0.16.0
hf-xet==1.1.5
httpcore==1.0.9
httpx==0.27.2
huggingface-hub==0.36.0
identify==2.6.12
idna==3.10
iniconfig==2.1.0
iso639==0.1.4
jinja2==3.1.6
joblib==1.5.1
latexcodec==3.0.1
markdown==3.9
markdown-it-py==3.0.0
markupsafe==3.0.2
mdurl==0.1.2
mergedeep==1.3.4
mkdocs==1.6.1
mkdocs-autorefs==1.4.3
mkdocs-bibtex==4.4.0
mkdocs-exclude==1.0.2
mkdocs-get-deps==0.2.0
mkdocs-include-dir-to-nav==1.2.0
mkdocs-material==9.6.21
mkdocs-material-extensions==1.3.1
mkdocstrings==0.30.1
mkdocstrings-python==1.18.2
mpmath==1.3.0
-e file:///home/samoed/Desktop/mteb
multidict==6.6.3
multiprocess==0.70.16
mypy==1.18.2
mypy-extensions==1.1.0
networkx==3.5
nodeenv==1.9.1
numpy==2.3.2
nvidia-cublas-cu12==12.8.4.1
nvidia-cuda-cupti-cu12==12.8.90
nvidia-cuda-nvrtc-cu12==12.8.93
nvidia-cuda-runtime-cu12==12.8.90
nvidia-cudnn-cu12==9.10.2.21
nvidia-cufft-cu12==11.3.3.83
nvidia-cufile-cu12==1.13.1.3
nvidia-curand-cu12==10.3.9.90
nvidia-cusolver-cu12==11.7.3.90
nvidia-cusparse-cu12==12.5.8.93
nvidia-cusparselt-cu12==0.7.1
nvidia-nccl-cu12==2.27.5
nvidia-nvjitlink-cu12==12.8.93
nvidia-nvshmem-cu12==3.3.20
nvidia-nvtx-cu12==12.8.90
packaging==25.0
paginate==0.5.7
pandas==2.3.1
pathspec==0.12.1
pillow==11.3.0
platformdirs==4.3.8
pluggy==1.6.0
polars==1.34.0
polars-runtime-32==1.34.0
pre-commit==4.2.0
propcache==0.3.2
pyarrow==21.0.0
pybtex==0.25.1
pydantic==2.11.7
pydantic-core==2.33.2
pygments==2.19.2
pymdown-extensions==10.16.1
pypandoc==1.15
pyparsing==3.2.3
pytest==8.3.5
pytest-cov==6.2.1
pytest-cover==3.0.0
pytest-coverage==0.0
pytest-rerunfailures==15.1
pytest-xdist==3.6.1
python-dateutil==2.9.0.post0
pytrec-eval-terrier==0.5.7
pytz==2025.2
pyyaml==6.0.2
pyyaml-env-tag==1.1
regex==2024.11.6
requests==2.32.4
responses==0.25.8
rich==14.0.0
ruff==0.14.0
safetensors==0.5.3
scikit-learn==1.7.1
scipy==1.16.0
sentence-transformers==5.1.2
setuptools==80.9.0
six==1.17.0
smmap==5.0.2
sniffio==1.3.1
sympy==1.14.0
tabulate==0.9.0
threadpoolctl==3.6.0
tokenizers==0.22.1
torch==2.9.0
torchaudio==2.9.0
torchcodec==0.8.1
torchvision==0.24.0
tqdm==4.67.1
transformers==4.57.1
triton==3.5.0
types-cachetools==6.2.0.20250827
types-protobuf==6.32.1.20250918
types-pysocks==1.7.1.20251001
types-pyyaml==6.0.12.20250915
types-requests==2.32.4.20250913
types-simplejson==3.20.0.20250822
types-tensorflow==2.18.0.20251008
types-tqdm==4.67.0.20250809
typing-extensions==4.14.1
typing-inspection==0.4.1
tzdata==2025.2
urllib3==2.5.0
validators==0.35.0
virtualenv==20.32.0
watchdog==6.0.0
xxhash==3.5.0
yarl==1.20.1
```

### Who can help?

@eustlb @ebezzam @vasqu

### Information

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

### Tasks

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

### Reproduction

Since datasets, `v4` it includes `torchcodec` as audio dependency, but it is not compatible with transformers. 
When I'm executing 
```python
from transformers import ASTFeatureExtractor, ASTModel

from torchcodec._core.ops import load_torchcodec_shared_libraries
load_torchcodec_shared_libraries()
```
I'm getting error `RuntimeError: Could not load libtorchcodec. Likely cause...`, but when I change
```python
from torchcodec._core.ops import load_torchcodec_shared_libraries

from transformers import ASTFeatureExtractor, ASTModel
load_torchcodec_shared_libraries()
```
This works fine. Ref https://github.com/meta-pytorch/torchcodec/issues/1030

### Expected behavior

Successfull import

Comments:
I want to take up 

I have faced this issue before. It was caused because _torchcodec_ initializes the libraries that are shared with _tranformers_ in a conflicting manner. For me, importing the _torchcodec_ libraries before importing the _tranformers_ based audio libraries fixed the issue. Try this.

Yes, it will work as I give in example

we'll look into that, thanks for raising this issue! In the meantine @pranavabhat-5204 solution is a hot fix! 

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

Tried to run from current main, and it seems that problem was resolved

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.