Pull requests / #470

#470 setup: a download stopped before its rename is finished without a request (no 5-minute 416 retry loop)

closed · @homeofe · 0 Kommentare · Auf GitHub

Setup & installAMD / HIPNVIDIA / CUDAWindowsLinux

Beschreibung

This is the part of #435 that 0.1.34 doesn't cover. 0.1.34 fixed the free-space check for a resumed download (#425), but this resume bug is still on `main`.

## Problem

Suppose setup is stopped after the last byte of a shard has been written to `<shard>.part` but before `part.replace(dst)`: Ctrl+C, a closed window, a reboot. On the next run, `download()`:

1. sends a HEAD and gets `Content-Length = N`;
2. reads `have = N` from the `.part`;
3. sends `GET` with `Range: bytes=N-`, a range past the end. The server answers **416 Range Not Satisfiable**;
4. `urllib` raises `HTTPError`, an `OSError`, so it prints "download interrupted … retrying in 10 s" and tries again, **30 times, about 5 minutes**;
5. only after the loop does it find `part.stat().st_size == total` and rename the complete file.

## Change (`setup.py`, `download()`)

```python
    for attempt in range(30):
        if total and have >= total:                    # stopped after the last byte, before the rename: nothing to
            break                                      # ask for (a range past the end is a 416, retried 30 times)
```

The existing code after the loop then renames and marks the file, as it already did after those 5 minutes. When the server sends no `Content-Length` (`total == 0`), the behaviour is unchanged.

## Test (`tools/test_setup_pins.py`, next to the other `download()` tests)

`test_a_complete_part_is_finished_without_a_request` uses a mocked server: HEAD gives `Content-Length: 11`, and every GET gets 416. A `.part` with all 11 bytes must end up as the marked file after a HEAD only.

| | result |
|---|---|
| `main` (0.1.34) | **FAIL**: `[('HEAD', None), ('GET', 'bytes=11-'), ('GET', 'bytes=11-'), …]` (30 GETs) `!= [('HEAD', None)]` |
| this PR | pass |

```
python3 -m unittest tools.test_setup_choices tools.test_setup_draft_vocab tools.test_setup_lowram tools.test_setup_pins \
    tools.test_setup_prompts tools.test_setup_risk tools.test_setup_rope tools.test_setup_unsloth      # OK
```

Two failures on Linux are the same with and without this change:
- `tools.test_setup_amd`: `WindowsDetection.test_prebuilt_hip_zip`, new in 0.1.34.
- `tools.test_setup_golden`: fixed in #428.

### Test machine

Ubuntu 24.04.4 (kernel 6.8), Python 3.12.3, AMD Ryzen Threadripper 3960X, 128 GB DDR4, RTX 2080 Ti 11 GB. The test is fully mocked: no network and no downloads.

Mehr auf der Site

Links zu Install, Modellen, Releases.