# Cache duplication for external dataset

**URL:** <https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100>\
**Category:** Questions\
**Created:** [March 7, 2022, 7:20am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100 "2022-03-07T07:20:33Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![schakal](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@schakal](https://discuss.dvc.org/u/schakal)\
**Post date:** [March 7, 2022, 7:20am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/1 "2022-03-07T07:20:33Z")

</div>

Hello, I have questions about the DVC cache duplication when I have an external dataset.

There are two cases I’ve tried to figure out according to the location of cache, dataset:

(Assume there are two datasets to version control, i.e., dataset 1 & dataset 2. The size of dataset 1 = 10M, the size of dataset 2 = 10M, and there is 5M duplication between dataset 1 & dataset 2.)

**[Case 1]** Cache and both datasets are in the same storage as the DVC workspace.  
In this case, after I dvc add dataset1 and then dvc add dataset1 + dataset2, the size of the cache dir is 15M(10M + 5M). It seems ok.

**[Case 2]** Datasets are in the external storage with respect to the DVC workspace. (Cache is in or out of the storage where the DVC workspace is.)  
In this case, after I dvc add datset1 and then dvc add dataset1 + dataset2, the size of the cache dir is 25M.(10M + 15M) So, the feature DVC provides for eliminating the cache duplication doesn’t work fine for external dataset.

I checked the size of the folders using du -hs in my Ubuntu environment.  
Can I use that DVC feature to eliminate cache duplication when I have an external dataset?

Thank you.

---

<div class="post-metadata">

**Author:** ![Paffciu](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@Paffciu](https://discuss.dvc.org/u/Paffciu)\
**Post date:** [March 7, 2022, 8:58am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/2 "2022-03-07T08:58:57Z")

</div>

Hello, @schakal!  
What format is you dataset in? Is it a directory with files?  
What is you `dvc version`?

---

<div class="post-metadata">

**Author:** ![schakal](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@schakal](https://discuss.dvc.org/u/schakal)\
**Post date:** [March 7, 2022, 9:26am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/3 "2022-03-07T09:26:01Z")

</div>

Hello, @Paffciu  
Yes, each dataset folder is consisted as follows. For instance,

dataset1(folder) - cats(folder) - image files (.jpg)  
- dogs(folder) - image files (.jpg)

And my environment is:

DVC version : 2.8.1 (pip)  
Python 3.6.9 on Linux-5.4.0-81-generic-x86\_64-with-Ubuntu-18.04-bionic

Thank you.

---

<div class="post-metadata">

**Author:** ![Paffciu](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@Paffciu](https://discuss.dvc.org/u/Paffciu)\
**Post date:** [March 7, 2022, 10:40am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/4 "2022-03-07T10:40:06Z")

</div>

Thank you. Is the dataset that you are using some public one, so that I could try to reproduce it?

---

<div class="post-metadata">

**Author:** ![schakal](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@schakal](https://discuss.dvc.org/u/schakal)\
**Post date:** [March 8, 2022, 12:08am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/5 "2022-03-08T00:08:43Z")

</div>

Sure. I just used the cats&dogs dataset in the tutorial “[https://dvc.org/doc/use-cases/versioning-data-and-model-files/tutorial](https://dvc.org/doc/use-cases/versioning-data-and-model-files/tutorial)”.

I downloaded it using

```auto
dvc get https://github.com/iterative/dataset-registry \
          tutorials/versioning/data.zip

```

and from the first 500 images(i.e., cats 1~-500.jpg, dogs 1~500.jpg) I splitted into two sets:  
dataset1: cats 1~300.jpg & dogs 1~300.jpg  
dataset2: cats 201~500.jpg & dogs 201~500.jpg

And I located them in the same or out of the storage as the workspace and experimented it.

So the exact size of the folders is not same as the above case I described, but the overall situation is same. The above was just the example to make it simple.

Thank you.

---

<div class="post-metadata">

**Author:** ![schakal](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@schakal](https://discuss.dvc.org/u/schakal)\
**Post date:** [March 8, 2022, 12:47am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/6 "2022-03-08T00:47:08Z")

</div>

I just rerun the whole thing again, and it seems that if the dataset is outside of the workspace and I use “dvc add -o”, then the cache doesn’t consider the duplication in the dataset.

That is, even though dataset1 and dataset2 has duplication of 5M, the size of cache is 29M, not 25M, and it’s unreasonable.

---

<div class="post-metadata">

**Author:** ![Paffciu](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@Paffciu](https://discuss.dvc.org/u/Paffciu)\
**Post date:** [March 8, 2022, 10:38am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/7 "2022-03-08T10:38:27Z")

</div>

That is indeed unreasonable, let me try to reproduce that.

---

<div class="post-metadata">

**Author:** ![Paffciu](https://avatars.discourse-cdn.com/v4/letter/p/d07c76/32.png) [@Paffciu](https://discuss.dvc.org/u/Paffciu)\
**Post date:** [March 8, 2022, 12:51pm UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/8 "2022-03-08T12:51:10Z")

</div>

@schakal  
I cannot reproduce, for me the behavior is as expected, after adding second dataset the cache size is (size\_1 + size\_2) (and not 2 \* size\_1 + size\_2)  
Could you provide me with some more info about `Case 2`?

> Datasets are in the external storage with respect to the DVC workspace.

Data resides in a separate folder, or for example, an external drive?

> Cache is in or out of the storage where the DVC workspace is.

I checked both the “default” cache (`.dvc/cache`) and external dir (cache outside of dvc repo).

In both cases I get consistent results, cache size grows as expected.

---

<div class="post-metadata">

**Author:** ![schakal](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@schakal](https://discuss.dvc.org/u/schakal)\
**Post date:** [March 10, 2022, 6:09am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/9 "2022-03-10T06:09:45Z")

</div>

@Paffciu  
Ah, thank you for checking. Let me explain how I executed it and the results I’ve got.

\*data\_v1: cats&dogs dataset (1~300.jpg, respectively) - 15M (size)  
\*data\_v2: cats&dogs dataset (201~500.jpg, respectively) - 15M (size)  
Therefore, there is 5M duplication between data\_v1 and data\_v2. (201~300.jpg)

\*workspace(denoted as WS below) path: /home/work/dvc\_expm/

Our NAS is mounted on /home/work/nas/.  
So I set the path for dataset as /home/work/nas/outer\_data (denoted as OD below) and  
for remote cache as /home/work/nas/outer\_remote (denoted as REM below).

The size of all folders is computed through du -hs.

To reproduce the results, I executed as follows:  
(1) In the WS,

> [@](#):
>
> git init  
> dvc init  
> dvc config cache.type “reflink,symlink”  
> git add .dvc  
> git remote add origin “my GitLab project”  
> git commit -m “initialize DVC”

(2) Copy “data\_v1” to the OD using cp -r.

(3) In the WS,

> [@](#):
>
> dvc add /home/work/nas/outer\_data -o . # use -o option since the dataset is outside of the WS.  
> git add outer\_data.dvc  
> git commit -m “1st version”  
> git tag -a “v1.0” -m "1st version“
> 
> git push origin master --tags
> 
> dvc remote add --default shared\_remote /home/work/nas/outer\_remote  
> dvc push -r shared\_remote

Then, the size of the REM is 15M.  
And the size of /home/work/dvc\_expm/.dvc/cache is 16M. (since I didn’t set cache dir here.)  
(Everything is ok here)

(4) Copy “data\_v2” to the OD using cp -r. Now the size of OD is 30M. (data\_v1 & data\_v2 are separate folders.)

(5) In the WS,

> [@](#):
>
> rm –rf outer\_data # since I can’t make outer\_data again in WS if I don’t erase it. See right below.  
> dvc add /home/work/nas/outer\_data -o .  
> git add outer\_data.dvc  
> git commit -m “2nd version"  
> git tag -a “v2.0” -m “2nd version“
> 
> git push origin master --tags
> 
> dvc push -r shared\_remote

Now the size of the related folders is as follows:

> [@](#):
>
> du -hs /home/work/dvc\_expm/.dvc/cache \>\> 44M  
> du -hs /home/work/nas/outer\_data \>\> 29M  
> du -hs /home/work/nas/outer\_remote \>\> 24M

So it seems that, in my case, only the cache of remote eliminates the duplication. (it should be 24M.)  
And the phenomenon of overlapping cache (44M) is same when I set ‘cache dir’ in my NAS (ex. dvc cache dir /home/work/nas/outer\_cache in the first place.)

Do you mean you can’t reproduce this scenario?

Thank you.

---

<div class="post-metadata">

**Author:** ![schakal](https://avatars.discourse-cdn.com/v4/letter/s/59ef9b/32.png) [@schakal](https://discuss.dvc.org/u/schakal)\
**Post date:** [March 14, 2022, 5:08am UTC](https://discuss.dvc.org/t/cache-duplication-for-external-dataset/1100/10 "2022-03-14T05:08:05Z")

</div>

@Paffciu Could I ask if the reproducing is going on?
