Repository: pytorch
Issue: Torchrun arguments shadowing script arguments
Labels: triaged,module: regression,module: intel

### 🐛 Describe the bug

Consider a minimalistic script as follows:
``` python
import transformers
from dataclasses import dataclass

@dataclass
class LoraConfig:
    r: int = 8
    lora_alpha: int = 32
    bias = "none"
    lora_dropout: float = 0.05

parser = transformers.HfArgumentParser(dataclass_types=(LoraConfig))
lora_config, _ = parser.parse_args_into_dataclasses(return_remaining_strings=True)

print(lora_config)
```

Running it directly gives the following:
```
$ python main.py --r=16
LoraConfig(r=16, lora_alpha=32, lora_dropout=0.05)
```
(see the default r value now being updated to 16)

Running it using torchrun:
```
$ torchrun main.py --r=16
usage: torchrun [-h] [--nnodes NNODES] [--nproc-per-node NPROC_PER_NODE]
                [--rdzv-backend RDZV_BACKEND] [--rdzv-endpoint RDZV_ENDPOINT] [--rdzv-id RDZV_ID]
                [--rdzv-conf RDZV_CONF] [--standalone] [--max-restarts MAX_RESTARTS]
                [--monitor-interval MONITOR_INTERVAL] [--start-method {spawn,fork,forkserver}]
                [--role ROLE] [-m] [--no-python] [--run-path] [--log-dir LOG_DIR] [-r REDIRECTS]
                [-t TEE] [--node-rank NODE_RANK] [--master-addr MASTER_ADDR]
                [--master-port MASTER_PORT] [--local-addr LOCAL_ADDR]
                training_script ...
torchrun: error: ambiguous option: --r=16 could match --rdzv-backend, --rdzv_backend, --rdzv-endpoint, --rdzv_endpoint, --rdzv-id, --rdzv_id, --rdzv-conf, --rdzv_conf, --role, --run-path, --run_path, --redirects
```

The reason for this is argparse's [abbrevation handling](https://docs.python.org/3/library/argparse.html#allow-abbrev) which shadows any argument with the prefix of an existing torchrun argument. For example, with "--n" which matches all torchrun flags which starts with n and so on. This behaviour exists on the current main.

The fix is straightforward: set "allow_abbrev" to False when creating the torchrun ArgumentParser. I have tested this locally and found it to work and can open a PR if there is consensus that this is a bug and no existing workflow will be broken due to this.

### Versions

Collecting environment information...
PyTorch version: 2.2.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Fedora release 39 (Thirty Nine) (x86_64)
GCC version: (GCC) 13.2.1 20230918 (Red Hat 13.2.1-3)
Clang version: Could not collect
CMake version: version 3.27.7
Libc version: glibc-2.38

Python version: 3.12.0 (main, Oct  2 2023, 00:00:00) [GCC 13.2.1 20230918 (Red Hat 13.2.1-3)] (64-bit runtime)
Python platform: Linux-6.5.6-300.fc39.x86_64-x86_64-with-glibc2.38
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Address sizes:                      39 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             8
On-line CPU(s) list:                0-7
Vendor ID:                          GenuineIntel
Model name:                         11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz
CPU family:                         6
Model:                              140
Thread(s) per core:                 2
Core(s) per socket:                 4
Socket(s):                          1
Stepping:                           1
CPU(s) scaling MHz:                 82%
CPU max MHz:                        4700.0000
CPU min MHz:                        400.0000
BogoMIPS:                           5606.40
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l2 invpcid_single cdp_l2 ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves split_lock_detect dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid movdiri movdir64b fsrm avx512_vp2intersect md_clear ibt flush_l1d arch_capabilities
Virtualization:                     VT-x
L1d cache:                          192 KiB (4 instances)
L1i cache:                          128 KiB (4 instances)
L2 cache:                           5 MiB (4 instances)
L3 cache:                           12 MiB (1 instance)
NUMA node(s):                       1
NUMA node0 CPU(s):                  0-7
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        Not affected
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Not affected
Vulnerability Retbleed:             Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced / Automatic IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] torch==2.2.0
[pip3] triton==2.2.0
[conda] Could not collect

cc @frank-wei @jgong5 @mingfeima @XiaobingSuper @sanchitintel @ashokei @jingxu10