Add xcodec2 model
Author: ebezzam
Pull request: yes

# What does this PR do?

Re-opening https://github.com/huggingface/transformers/pull/37868

TODO
- [x] recompute expected outputs
- [x] passthrough code given new conventions
- [x] check for unused code paths / configuration parameters

Original checkpoint: https://huggingface.co/HKUSTAudio/xcodec2
Original modeling code: https://huggingface.co/HKUSTAudio/xcodec2/blob/main/modeling_xcodec2.py

Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_44178). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

run-slow: xcodec2

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/23259446304)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/xcodec2"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/23259446304)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [6fd5f248](https://github.com/huggingface/transformers/commit/6fd5f2480f8b3ff93a3245b8dd322dd9d9ac19eb) | workflow commit (merge commit) |
| PR | [1fbe78dc](https://github.com/ebezzam/transformers/commit/1fbe78dc16ff3f980fc36d12696719fcfff9822e) | branch commit (from PR) |
| main | [24a4dc22](https://github.com/huggingface/transformers/commit/24a4dc22b986a35fa5920bb080fddea49f4299d3) | base commit (on `main`) |

✅ No failing test specific to this PR 🎉 👏 !


run-slow: dac, encodec, higgs_audio_v2_tokenizer, mimi, pe_audio, qwen2_5_omni, qwen3_omni_moe, seamless_m4t, wav2vec2_bert, xcodec, xcodec2

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28027596269)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/dac", "models/encodec", "models/higgs_audio_v2_tokenizer", "models/mimi", "models/pe_audio", "models/qwen2_5_omni", "models/qwen3_omni_moe", "models/seamless_m4t", "models/wav2vec2_bert", "models/xcodec", "models/xcodec2"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28027596269)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [caea5740](https://github.com/huggingface/transformers/commit/caea574058edd67c983536313194a1de93d06f2f) | workflow commit (merge commit) |
| PR | [dc3378df](https://github.com/ebezzam/transformers/commit/dc3378df89d581cb059e9e6ecd136bae7c338715) | branch commit (from PR) |
| main | [c2fafabb](https://github.com/huggingface/transformers/commit/c2fafabbebd83cd6062c809ab602bbeafab639b9) | base commit (on `main`) |

### Model CI Report

❌ **[3 new failed tests from this PR](https://huggingface.co/datasets/hf-internal-testing/transformers_pr_ci/raw/11bef1269ee90b4a312d5270b101245e66c398dd/2026-06-23/runs/36769-28027596269/ci_results_run_models_gpu/new_failures_with_bad_commit.json)** 😭

- [wav2vec2_bert](https://github.com/huggingface/transformers/actions/runs/28027596269/job/82959712719):
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_cpu_offload (✅ ⟹ ❌)
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_disk_offload_bin (✅ ⟹ ❌)
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_disk_offload_safetensors (✅ ⟹ ❌)



run-slow: wav2vec2_bert

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28041468794)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/wav2vec2_bert", "models/xcodec2"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28041468794)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [e75260e4](https://github.com/huggingface/transformers/commit/e75260e49eb9f6c5dc015b87ff570f6c96b4ff2a) | workflow commit (merge commit) |
| PR | [512c681c](https://github.com/ebezzam/transformers/commit/512c681cee5e5c3756204488e592ba80c4ca369f) | branch commit (from PR) |
| main | [612c371a](https://github.com/huggingface/transformers/commit/612c371ac6e4f9e86baf9b5cf4b8048f5ca80774) | base commit (on `main`) |

### Model CI Report

❌ **[2 new failed tests from this PR](https://huggingface.co/datasets/hf-internal-testing/transformers_pr_ci/raw/6a5df71b922a51d1265095e14304baf206ec3efd/2026-06-23/runs/36791-28041468794/ci_results_run_models_gpu/new_failures_with_bad_commit.json)** 😭

- [wav2vec2_bert](https://github.com/huggingface/transformers/actions/runs/28041468794/job/83010727080):
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_disk_offload_safetensors (✅ ⟹ ❌)
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_num_layers_is_small (✅ ⟹ ❌)



run-slow: wav2vec2_bert

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28087702533)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/wav2vec2_bert", "models/xcodec2"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28087702533)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [2f3e7a72](https://github.com/huggingface/transformers/commit/2f3e7a72afc232d1148fb2aa05fd7e8e42d33aa1) | workflow commit (merge commit) |
| PR | [a31ed1c3](https://github.com/ebezzam/transformers/commit/a31ed1c37a39c7e98a467f4af55277350d757346) | branch commit (from PR) |
| main | [d87f670d](https://github.com/huggingface/transformers/commit/d87f670d5b23860b5937473a5fddbba9d675780a) | base commit (on `main`) |

### Model CI Report

❌ **[2 new failed tests from this PR](https://huggingface.co/datasets/hf-internal-testing/transformers_pr_ci/raw/c42951671af2bab3277d89b71f9af175ba216271/2026-06-24/runs/36814-28087702533/ci_results_run_models_gpu/new_failures_with_bad_commit.json)** 😭

- [wav2vec2_bert](https://github.com/huggingface/transformers/actions/runs/28087702533/job/83158008161):
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_cpu_offload (✅ ⟹ ❌)
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_disk_offload_safetensors (✅ ⟹ ❌)



run-slow: wav2vec2_bert

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28118336880)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/wav2vec2_bert", "models/xcodec2"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28118336880)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [a8c493b2](https://github.com/huggingface/transformers/commit/a8c493b2838656c32fbd049a73232302da50bc0d) | workflow commit (merge commit) |
| PR | [78c3ed98](https://github.com/ebezzam/transformers/commit/78c3ed98a69aaeb56768621ab8b4cacfae1f87d5) | branch commit (from PR) |
| main | [353b1532](https://github.com/huggingface/transformers/commit/353b1532ab635b8e4729f9c320f73591416d007f) | base commit (on `main`) |

✅ No failing test specific to this PR 🎉 👏 !


run-slow: wav2vec2_bert

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28128428319)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/wav2vec2_bert", "models/xcodec2"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28128428319)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [6f8a7fad](https://github.com/huggingface/transformers/commit/6f8a7fad1f80e780d194ee83ab44b74d3039b6ca) | workflow commit (merge commit) |
| PR | [6d9c51c1](https://github.com/ebezzam/transformers/commit/6d9c51c17363b14935e67f7c611ef35d0737c621) | branch commit (from PR) |
| main | [c21da1b5](https://github.com/huggingface/transformers/commit/c21da1b58819a597e4a250622819d1f15e14d771) | base commit (on `main`) |

### Model CI Report

❌ **[1 new failed tests from this PR](https://huggingface.co/datasets/hf-internal-testing/transformers_pr_ci/raw/634756d17502214b1f60c19f30b66cb558287f11/2026-06-24/runs/36861-28128428319/ci_results_run_models_gpu/new_failures_with_bad_commit.json)** 😭

- [wav2vec2_bert](https://github.com/huggingface/transformers/actions/runs/28128428319/job/83299146136):
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_labels_out_of_vocab (✅ ⟹ ❌)



run-slow: wav2vec2_bert

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28129882173)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/wav2vec2_bert", "models/xcodec2"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28129882173)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [7bb5864a](https://github.com/huggingface/transformers/commit/7bb5864a9eb46bfd1d936343c607686ebddeb993) | workflow commit (merge commit) |
| PR | [2fe0150a](https://github.com/ebezzam/transformers/commit/2fe0150a22a671b00ed33ca4fdd52121db8672c6) | branch commit (from PR) |
| main | [c21da1b5](https://github.com/huggingface/transformers/commit/c21da1b58819a597e4a250622819d1f15e14d771) | base commit (on `main`) |

### Model CI Report

❌ **[1 new failed tests from this PR](https://huggingface.co/datasets/hf-internal-testing/transformers_pr_ci/raw/771bf11ab81b49d313565d14196318d662f908cb/2026-06-24/runs/36863-28129882173/ci_results_run_models_gpu/new_failures_with_bad_commit.json)** 😭

- [wav2vec2_bert](https://github.com/huggingface/transformers/actions/runs/28129882173/job/83303547607):
    tests/models/wav2vec2_bert/test_modeling_wav2vec2_bert.py::Wav2Vec2BertModelTest::test_labels_out_of_vocab (✅ ⟹ ❌)



run-slow: wav2vec2_bert

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: auto, dac, encodec, higgs_audio_v2_tokenizer, mimi, pe_audio, qwen2_5_omni, qwen3_omni_moe, seamless_m4t, wav2vec2_bert, xcodec, xcodec2

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28153824640)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/wav2vec2_bert", "models/xcodec2"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28153824640)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [3779e738](https://github.com/huggingface/transformers/commit/3779e73872f520776e0eea69ed2b25940c6079d3) | workflow commit (merge commit) |
| PR | [975813f5](https://github.com/ebezzam/transformers/commit/975813f5b14001205f9538a2ef7bbcd1eddfcfec) | branch commit (from PR) |
| main | [c21da1b5](https://github.com/huggingface/transformers/commit/c21da1b58819a597e4a250622819d1f15e14d771) | base commit (on `main`) |

✅ No failing test specific to this PR 🎉 👏 !