Open
Conversation
added 2 commits
May 13, 2022 12:28
Contributor
|
This can be archived with existing nfiles = 100
testdata = "hello, world"
dest = os.path.join(self.temp_dir.name, "testdata")
with open(dest, "w") as stream:
stream.write(testdata)
dp = IterableWrapper([dest] * nfiles)
def _noop(x):
return x
dp = dp.on_disk_cache(filepath_fn=_noop)
# This could be download, for for sake of example
# # I just writing text into the file
def _write(filename):
with open(filename, 'w') as fh:
fh.write(testdata)
dp = dp.map(lambda filename: _write(filename))
dp = dp.end_caching(mode="t", filepath_fn=_noop, timeout=120)
dp = FileOpener(dp)
count = 0
for path, stream in dp:
data = stream.read()
count += 1
assert data == testdata
assert count == nfiles |
Contributor
Author
|
I'm not particularly attached to my implementation, but I think file caching is something that people should be able to add very easily to a pipeline with just "dp.filecache(dirname)". (In fact, it might be a good idea to just have it default to the environment variable and not cache if the environment variable is unset.) I haven't seen use cases for the generality that the current cache implementation provides and think that it will discourage the use of caching. Also, it looks like your caching implementation may mix downloading with caching, whereas the .popen/.filecache combo separates it, making it easier to make training pipelines location transparent. |
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.
This PR adds a file caching filter. The filter receives (fname, stream) pairs; if necessary, it will download all the data in the stream to a local file based on the filename. Then it will pass an (fname, stream) pair to the next state.
This is particularly useful with WebDataset, where FileCache can be used to cache shards incrementally as they are downloaded from remote locations, but the filter works with arbitrary (fname, stream) pairs.