Use inspect.getsource instead of open() for source-reading in _can_set_*_implementation
Author: rasmi
Pull request: yes

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

# What does this PR do?

Avoid `open()`-reading transformers' own `.py` source in `modeling_utils.py` (alongside #46152). This is helpful for hermetic Python builds (e.g. with Bazel) and other non-standard environments (as opposed to `open()` which can vary based on the precise environment and filesystem).

## Changes

- Adds `_nn_classes_in_defining_module` helper on `PreTrainedModel`; rewrites the two `_can_set_attn_implementation` / `_can_set_experts_implementation` checks to use it. The new checks test the same property as before (does this model use the modern attention / experts interface?) but inspect live `nn.Module` subclasses instead of grepping the file text.


## 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).
- [X] 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.


@zucchini-nlp @Rocketknight1 @Cyrilvallez

<!-- 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=46207)
**Latest run:** [28355613380](https://github.com/huggingface/transformers/actions/runs/28355613380)
**Result:** `failure` | Grafana metrics are not available yet.

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

Comments:
Thanks for cleaning this up @Cyrilvallez!!