feat: support indivisible shards for TP model loading and TPlizing.
Author: kmehant
Pull request: yes

# What does this PR do?

Fixes https://github.com/huggingface/transformers/issues/37051

Approach is to support uneven sharding and seek segments of data that mimics torch.chunk since torch.chunk is the style of sharding adopted by torch `Shard` placements API for both even and uneven sharding. Finally we pass stride and shape to `from_local` to allow for uneven sharding.

```python
from transformers import AutoModelForCausalLM
import torch

m2 = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0", tp_plan=None)
m = AutoModelForCausalLM.from_pretrained("TinyLlama/TinyLlama-1.1B-Chat-v1.0", tp_plan="auto")

print(m.model.layers[0].self_attn.q_proj.weight)
print(m.model.layers[0].self_attn.q_proj.weight.shape)
ft = m.model.layers[0].self_attn.q_proj.weight.full_tensor().to("cpu")
assert torch.equal(ft, m2.model.layers[0].self_attn.q_proj.weight.to("cpu"))
# assert should pass
```

## 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?
- [x] 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. https://github.com/huggingface/transformers/issues/37051
- [ ] 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.

 @ArthurZucker @SunMarc @muellerzr 



Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers and trigger CI.

@ArthurZucker previous tests pass as well. Can you review the updated implementation?

<img width="869" alt="Screenshot 2025-04-11 at 2 16 02 PM" src="https://github.com/user-attachments/assets/b0e60997-f0a0-4236-a120-0339c59f706a" />


<img width="859" alt="Screenshot 2025-04-11 at 9 20 07 PM" src="https://github.com/user-attachments/assets/bd99ee8a-3a7d-4667-85d0-f53c2ad242ac" />

@ArthurZucker have added the test case.  PR is ready for merge.


(not related to this PR) Could not do TP 3 on llama 1B since q_proj (https://github.com/huggingface/transformers/blob/bf46e44878bd86aebcfa1eceb4a93a6e5b20e863/src/transformers/models/llama/modeling_llama.py#L230) undergoes colwise instead of colwise_rep due to which the sharded output of q_proj wont be readily consumable here - https://github.com/huggingface/transformers/blob/bf46e44878bd86aebcfa1eceb4a93a6e5b20e863/src/transformers/models/llama/modeling_llama.py#L255

Its more of a tradeoff if we wish to do colwise_rep and get it working for any tp_size compromising on performance vs only on multiples of 2 (precisely head_dim to support view) 

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

Rebased the PR.

@ArthurZucker @SunMarc Requesting review and merge, all conflicts resolved!

@ArthurZucker @SunMarc The PR is ready! Thank you.

cc @ArthurZucker 

@ArthurZucker requesting review on this PR.

Sorry all I was off for 2 weeks time to catchup

@ArthurZucker thanks for circling back to this, I have rebased the PR and fixed the quality check that was failing.

@ArthurZucker any update on this? We are holding to a fork, merging this PR, would help us (other TP users) to pivot on the HF transformers main repo. Thank you.