fix: add pickle support to _LazyConfigMapping for spawn multiprocessing
Author: kfojcik-intel
Pull request: yes

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=46026)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46026)
<!-- ci-dashboard-badge:end -->

# What does this PR do?

Adds pickle serialization support to `_LazyConfigMapping` (and _LazyAutoMapping) in transformers/models/auto/configuration_auto.py.

Currently, `_LazyConfigMapping` cannot be pickled because its `__init__ `requires a positional `mapping` argument. When Python's pickle protocol attempts to reconstruct the object, it calls cls() with no arguments, resulting in:

`TypeError: _LazyConfigMapping.__init__() missing 1 required positional argument: 'mapping'`

This breaks any downstream library that uses `spawn` multiprocessing and needs to serialize objects referencing `CONFIG_MAPPING` or similar auto-mapping globals. In particular, this affects vLLM on Intel XPU (and potentially other accelerators), where `spawn` is the only supported multiprocessing method.

Changes
Add `__reduce__` method to `_LazyConfigMapping` that serializes the mapping as a plain dict

## Code Agent Policy

The Transformers repo is currently being overwhelmed by a large number of PRs and issue comments written by
code agents. We are currently bottlenecked by our ability to review and respond to them. As a result, 
**we ask that new users do not submit pure code agent PRs** at this time. 
You may use code agents in drafting or to help you diagnose issues. We'd also ask autonomous "OpenClaw"-like agents
not to open any PRs or issues for the moment.

PRs that appear to be fully agent-written will probably be closed without review, and we may block users who do this
repeatedly or maliciously. 

This is a rapidly-evolving situation that's causing significant shockwaves in the open-source community. As a result, 
this policy is likely to be updated regularly in the near future. For more information, please read [`CONTRIBUTING.md`](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md).

- [x] I confirm that this is not a pure code agent PR.

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


## Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @

 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- text models: @ArthurZucker @Cyrilvallez
- vision models: @yonigozlan @molbap
- audio models: @eustlb @ebezzam @vasqu
- multimodal models: @zucchini-nlp
- graph models: @clefourrier

Library:

- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- continuous batching: @remi-or @ArthurZucker @McPatate
- pipelines: @Rocketknight1
- tokenizers: @ArthurZucker and @itazap
- trainer: @SunMarc
- attention: @vasqu @ArthurZucker @CyrilVallez
- model loading (from pretrained, etc): @CyrilVallez
- distributed: @3outeille @ArthurZucker
- CIs: @ydshieh

Integrations:

- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization: @SunMarc
- kernels: @drbh
- peft: @BenjaminBossan @githubnemo

Devices/Backends:

- AMD ROCm: @ivarflakstad
- Intel XPU: @IlyasMoutawwakil
- Ascend NPU: @ivarflakstad 

Documentation: @stevhliu

Research projects are not maintained and should be taken as is.

 -->

Comments:
Hmmn, I see the need here, but I'm a bit worried because this drops things like the `_extra_content` attribute, used for registering custom code models. I feel like this might also have some other weird side effects, but it'll need a deep dive to figure out exactly which ones

cc @hmellor maybe since it affects vLLM, but it might be more of a weird core issue that needs a deep dive and a few finicky dunder methods

I've not heard about issues with this with CUDA in vLLM so I suppose they mustn't be using `spawn`.

I agree with @Rocketknight1 that since these mappings are stateful we should also include the state so that they can be properly rebuilt in the new process. vLLM supports many custom models whose configs will be registered to this mapping and IIUC they would not survive the pickling process.

Thanks for the feedback @Rocketknight1 @hmellor, and apologies for the delayed response!

**On CUDA**: This issue actually affects CUDA as well. We reproduced it with `h2oai/h2ovl-mississippi-800m` on GPU using vLLM. vLLM's V1 engine uses `spawn` for the engine core process, so it's not XPU-specific — any platform where subprocess pickling occurs will hit this.

**On `_extra_content`**: Good catch — I've updated the PR to preserve `_extra_content` (registered custom models) through the pickle round-trip using a `_from_pickle` classmethod as the reconstructor. The `_modules` cache is intentionally excluded since it's a lazy-load cache that gets repopulated on access, and module objects shouldn't be pickled across processes anyway.

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

run-slow: auto

<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46026)
**Latest run:** [28500547375:2](https://github.com/huggingface/transformers/actions/runs/28500547375)
**Result:** `success` | **Jobs:** 14 | **Tests:** 40,789 | **Failures:** 0 | **Duration:** 18h 33m

<!-- ci-dashboard-recap:end -->

Hi @Rocketknight1 @hmellor,
Could you check the latest update?

@sywangyi , could you take a look at this? Thx.