Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix loading from HF GCP cache #5321

Merged
merged 2 commits into from
Dec 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/datasets/arrow_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import re
import shutil
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING, List, Optional, Union

import pyarrow as pa
Expand Down Expand Up @@ -294,11 +295,12 @@ def download_from_hf_gcs(self, download_config: DownloadConfig, relative_data_di
split_infos=self._info.splits.values(),
)
for file_instruction in file_instructions:
remote_prepared_filename = os.path.join(remote_cache_dir, file_instruction["filename"])
file_to_download = str(Path(file_instruction["filename"]).relative_to(self._path))
remote_prepared_filename = os.path.join(remote_cache_dir, file_to_download)
downloaded_prepared_filename = cached_path(
remote_prepared_filename.replace(os.sep, "/"), download_config=download_config
)
shutil.move(downloaded_prepared_filename, os.path.join(self._path, file_instruction["filename"]))
shutil.move(downloaded_prepared_filename, file_instruction["filename"])
except FileNotFoundError as err:
raise MissingFilesOnHfGcsError(err) from None

Expand Down
21 changes: 21 additions & 0 deletions tests/test_hf_gcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from tempfile import TemporaryDirectory
from unittest import TestCase

import pytest
from absl.testing import parameterized

from datasets import config
Expand Down Expand Up @@ -67,3 +68,23 @@ def test_dataset_info_available(self, dataset, config_name):
).replace(os.sep, "/")
datset_info_path = cached_path(dataset_info_url, cache_dir=tmp_dir)
self.assertTrue(os.path.exists(datset_info_path))


@pytest.mark.integration
def test_wikipedia_frr(tmp_path_factory):
tmp_dir = tmp_path_factory.mktemp("test_hf_gcp") / "test_wikipedia_simple"
dataset_module = dataset_module_factory("wikipedia", cache_dir=tmp_dir)

builder_cls = import_main_class(dataset_module.module_path, dataset=True)

builder_instance: DatasetBuilder = builder_cls(
cache_dir=tmp_dir,
config_name="20220301.frr",
hash=dataset_module.hash,
)

# use the HF cloud storage, not the original download_and_prepare that uses apache-beam
builder_instance._download_and_prepare = None
builder_instance.download_and_prepare()
ds = builder_instance.as_dataset()
assert ds is not None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is a regression test?

Before your fix, this test was not raising the reported MissingBeamOptions error, but a TypeError:

TypeError: 'NoneType' object is not callable

in relation with builder_instance._download_and_prepare = None in your test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should not call builder_instance._download_and_prepare since it should download from the HF cache.

If it raises TypeError, it means it tried to download the dataset normally instead of using the HF cache