Repository navigation
Conversation
Files that are already cached (`increase_tqdm`) or copied through `tf.io.gfile` (`_sync_file_copy`) were added to the `Dl Size...` bar in bytes, while HTTP downloads are counted in MiB. Once some files were cached, `tfds build` showed sizes such as `157286400/157286400 MiB`. The HTTP path also dropped a final MiB that ended exactly on a chunk boundary, so a 3 MiB download stopped at 2/3. It now reports `size // MiB`, which matches the `Content-length // MiB` total. Fixes tensorflow#3759
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3759.
Description
The
Dl Size...bar created in_Downloader.tqdm()counts MiB (unit=' MiB'), but two of the three paths that feed it add bytes:increase_tqdm(), called for files that are already cached (DownloadManager._log_skip_download), addedurl_info.sizein bytes._sync_file_copy(), used for non-HTTP URLs copied throughtf.io.gfile, also addedurl_info.sizein bytes._sync_download()(HTTP/FTP) converts to MiB, but its modulo bookkeeping never flushed the last MiB when a download ended exactly on a MiB boundary. A 3 MiB file read in 64 KiB chunks stops at2/3.This PR routes the first two paths through one helper,
_update_dl_size_pbar(size_in_bytes), which converts with// units.MiBthe same way_sync_downloadcomputes its total._sync_downloadnow reportssize // units.MiBas it grows, so the progress always matches theContent-length // MiBtotal. Files smaller than 1 MiB count as 0 MiB on every path, which is what the HTTP path already did.UrlInfo.sizeand checksums are unchanged.If you would rather review the HTTP last-MiB change separately, I can split it into its own PR.
flowchart LR subgraph Before A1["cached file<br>increase_tqdm()"] -->|"+157286400 (bytes)"| B1[("Dl Size bar<br>unit: MiB")] A2["gfile copy<br>_sync_file_copy()"] -->|"+2097152 (bytes)"| B1 A3["HTTP<br>_sync_download()"] -->|"+2 of 3 MiB"| B1 end subgraph After C1["cached file<br>increase_tqdm()"] --> H["_update_dl_size_pbar()<br>bytes // MiB"] C2["gfile copy<br>_sync_file_copy()"] --> H H -->|"+150, +2"| B2[("Dl Size bar<br>unit: MiB")] C3["HTTP<br>_sync_download()<br>size // MiB"] -->|"+3"| B2 endBefore / after
One cached 150 MiB file, then a 2 MiB local file copy, then a 3 MiB HTTP download (mocked, 64 KiB chunks). The expected bar is
155/155 MiB.Before (master at
7b86414c):After:
Repro script
Tests
Three regression tests in
downloader_test.py, one per path: cached file, gfile copy, and HTTP with a final MiB on a chunk boundary. On master they fail with:With this change,
pytest tensorflow_datasets/core/downloadgives 81 passed, 5 skipped, 7 failed (master: 78 passed, 5 skipped, 7 failed). The 7 failures are the sameextractor_test.pycases on both runs and are unrelated to this PR. On a Git-for-Windows checkout withcore.autocrlf=true,testing/test_data/foo.csvis converted to CRLF and no longer matches the LF copy inside the test archives. I can send a separate.gitattributesfix if that is welcome.Validated on Windows 11 with CPU TensorFlow (Python 3.11, tensorflow-cpu 2.21.0, tqdm 4.70.1). Not run on Linux; CI will confirm there on Python 3.10-3.12.
Checklist
pylint --rcfile=.pylintrcreports no new messages beyondprotected-accesson_pbar_dl_sizein the new test helper, the same accesssetUpalready makes.download_and_prepare): not applicable, this is a library fix.