DVC 快取與暫存檔

使用 DVC 進行資料版本控管入門

Ravi Bhadauria

Machine Learning Engineer

DVC 快取

  • 受追蹤資料檔與版本的隱藏儲存區
  • 在提交前暫存檔案
    • 適合大型資料集與二進位檔
  • 位於工作區的 .dvc 目錄內
    • 可設定位置
      $ dvc cache dir ~/mycache
      

工作區內 DVC 結構示意圖

使用 DVC 進行資料版本控管入門

新增檔案至快取

  • 將資料檔加入 dvc
$ dvc add data.csv
100% Adding...|====================|1/1 [00:00, 53.55file/s]

To track the changes with git, run:
    git add data.csv.dvc
To enable auto staging, run:
    dvc config core.autostage true
使用 DVC 進行資料版本控管入門

.dvc 檔

  • 每個 DVC 追蹤的檔案都有對應的 .dvc

    • data.csv -> data.csv.dvc
  • 要為資料檔建版,執行 git commit -m "data.csv.dvc"

  • .dvc 檔內容

outs:

- md5: f38a850818377e97155d22755caa39d0
size: 16
hash: md5
path: data.csv
使用 DVC 進行資料版本控管入門

與 DVC 快取互動

  • 快取檔路徑以 MD5 值命名
$ find .dvc/cache -type f
.dvc/cache/f3/8a850818377e97155d22755caa39d0
  • 計算資料集的 MD5
$ md5 data.csv
MD5 (data.csv) = f38a850818377e97155d22755caa39d0
使用 DVC 進行資料版本控管入門

與 DVC 快取互動

  • 使用 dvc add -v 顯示詳細輸出

執行 dvc add 搭配 -v 旗標的輸出畫面

使用 DVC 進行資料版本控管入門

移除與清理快取

  • dvc remove 移除已加入的檔案
$ dvc remove data.csv.dvc
  • 要清理快取,使用 dvc gc
    • 搭配 -w 旗標可移除工作區快取
$ dvc gc -w
WARNING: This will remove all cache except items used in the workspace of the current repo.
Are you sure you want to proceed? [y/n]: y
Removed 1 objects from repo cache.
使用 DVC 進行資料版本控管入門

重點整理

  • DVC 快取會在提交前暫存資料檔
  • 設定快取位置
    • dvc cache dir ~/mycache
  • 將檔案加入快取
    • dvc add data.csv
    • 會建立含中繼資料的 .dvc
  • 移除已加入檔案 dvc remove data.csv.dvc
    • dvc gc -w 清理工作區快取
使用 DVC 進行資料版本控管入門

一起來練習吧!

使用 DVC 進行資料版本控管入門

Preparing Video For Download...