aitech-ium/IUM_10.DVC.ipynb

63 KiB
Raw Blame History

DVC

DVC - Data Version Control

  • dvc.org
  • "Version Control System for Machine Learning Projects" (System kontroli wersji dla projektów uczenia maszynowego)
  • Open Source
  • Umożliwia:
    • wersjonowanie danych i modeli. "Git dla danych i modeli"
    • budowanie potoków ("pipeline") definiujących jak budować/trenować/ewaluować modele. "Makefile dla uczenia maszynowego"
    • śledzeniem, porównywanie metryk i parametrów
  • ściśle zintegowany z gitem
  • działa niezależnie od używanego języka/bibliotek i systemu operacyjnego
  • 5-minutowe wprowadzenie: https://www.youtube.com/watch?v=UbL7VUpv1Bs&t=197s

Instalacja i inicjalizacja

conda install dvc
Collecting package metadata (current_repodata.json): done
Solving environment: failed with initial frozen solve. Retrying with flexible solve.
Solving environment: failed with repodata from current_repodata.json, will retry with next repodata source.
Collecting package metadata (repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/tomek/miniconda3

  added / updated specs:
    - dvc


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    atpublic-1.0               |             py_0           7 KB  conda-forge
    bzip2-1.0.8                |       h7f98852_4         484 KB  conda-forge
    cached-property-1.5.2      |       hd8ed1ab_1           4 KB  conda-forge
    cached_property-1.5.2      |     pyha770c72_1          11 KB  conda-forge
    colorama-0.4.4             |     pyh9f0ad1d_0          18 KB  conda-forge
    commonmark-0.9.1           |             py_0          46 KB  conda-forge
    configobj-5.0.6            |             py_0          31 KB  conda-forge
    dictdiffer-0.8.1           |     pyhd8ed1ab_0          16 KB  conda-forge
    diskcache-5.2.1            |     pyh44b312d_0          36 KB  conda-forge
    distro-1.5.0               |     pyh9f0ad1d_0          20 KB  conda-forge
    dpath-2.0.1                |   py39hf3d152e_0          23 KB  conda-forge
    dulwich-0.20.23            |   py39h3811e60_0         721 KB  conda-forge
    dvc-2.1.0                  |   py39hf3d152e_0         551 KB  conda-forge
    flatten-dict-0.3.0         |     pyh9f0ad1d_0          11 KB  conda-forge
    flufl.lock-3.2             |             py_0          19 KB  conda-forge
    fsspec-0.9.0               |     pyhd8ed1ab_2          75 KB  conda-forge
    ftfy-5.5.1                 |             py_0          47 KB  conda-forge
    funcy-1.16                 |     pyhd8ed1ab_0          30 KB  conda-forge
    future-0.18.2              |   py39hf3d152e_3         718 KB  conda-forge
    grandalf-0.6               |             py_0          42 KB  conda-forge
    jsonpath-ng-1.5.2          |     pyh9f0ad1d_0          26 KB  conda-forge
    libgit2-1.1.0              |       h0b03e73_0         693 KB  conda-forge
    libssh2-1.9.0              |       ha56f1ee_6         226 KB  conda-forge
    mailchecker-4.0.7          |     pyhd8ed1ab_0         206 KB  conda-forge
    nanotime-0.5.2             |             py_0           6 KB  conda-forge
    networkx-2.5               |             py_0         1.2 MB  conda-forge
    pathlib2-2.3.5             |   py39hf3d152e_3          35 KB  conda-forge
    pathspec-0.8.1             |     pyhd3deb0d_0          29 KB  conda-forge
    pcre2-10.35                |       h032f7d1_2         693 KB  conda-forge
    phonenumbers-8.10.14       |             py_0         1.5 MB  conda-forge
    ply-3.11                   |             py_1          44 KB  conda-forge
    pyasn1-0.4.8               |             py_0          53 KB  conda-forge
    pydot-1.2.4                |             py_0          20 KB  conda-forge
    pygit2-1.5.0               |   py39h3811e60_0         213 KB  conda-forge
    pygtrie-2.3.2              |     pyh8c360ce_0          24 KB  conda-forge
    python-benedict-0.24.0     |     pyhd8ed1ab_0          30 KB  conda-forge
    python-fsutil-0.5.0        |     pyhd8ed1ab_0          13 KB  conda-forge
    python-slugify-5.0.2       |     pyhd8ed1ab_0          12 KB  conda-forge
    rich-10.2.2                |   py39hf3d152e_0         337 KB  conda-forge
    ruamel.yaml-0.17.4         |   py39h3811e60_0         160 KB  conda-forge
    ruamel.yaml.clib-0.2.2     |   py39h3811e60_2         173 KB  conda-forge
    shortuuid-1.0.1            |   py39hf3d152e_4          15 KB  conda-forge
    shtab-1.3.6                |     pyhd8ed1ab_0          15 KB  conda-forge
    text-unidecode-1.3         |             py_0          68 KB  conda-forge
    toml-0.10.2                |     pyhd8ed1ab_0          18 KB  conda-forge
    unidecode-1.2.0            |     pyhd8ed1ab_0         155 KB  conda-forge
    voluptuous-0.12.1          |     pyhd3deb0d_0          28 KB  conda-forge
    zc.lockfile-2.0            |             py_0          11 KB  conda-forge
    ------------------------------------------------------------
                                           Total:         8.8 MB

The following NEW packages will be INSTALLED:

  _openmp_mutex      conda-forge/linux-64::_openmp_mutex-4.5-1_gnu
  appdirs            conda-forge/noarch::appdirs-1.4.4-pyh9f0ad1d_0
  atpublic           conda-forge/noarch::atpublic-1.0-py_0
  bzip2              conda-forge/linux-64::bzip2-1.0.8-h7f98852_4
  cached-property    conda-forge/noarch::cached-property-1.5.2-hd8ed1ab_1
  cached_property    conda-forge/noarch::cached_property-1.5.2-pyha770c72_1
  colorama           conda-forge/noarch::colorama-0.4.4-pyh9f0ad1d_0
  commonmark         conda-forge/noarch::commonmark-0.9.1-py_0
  configobj          conda-forge/noarch::configobj-5.0.6-py_0
  dictdiffer         conda-forge/noarch::dictdiffer-0.8.1-pyhd8ed1ab_0
  diskcache          conda-forge/noarch::diskcache-5.2.1-pyh44b312d_0
  distro             conda-forge/noarch::distro-1.5.0-pyh9f0ad1d_0
  dpath              conda-forge/linux-64::dpath-2.0.1-py39hf3d152e_0
  dulwich            conda-forge/linux-64::dulwich-0.20.23-py39h3811e60_0
  dvc                conda-forge/linux-64::dvc-2.1.0-py39hf3d152e_0
  flatten-dict       conda-forge/noarch::flatten-dict-0.3.0-pyh9f0ad1d_0
  flufl.lock         conda-forge/noarch::flufl.lock-3.2-py_0
  fsspec             conda-forge/noarch::fsspec-0.9.0-pyhd8ed1ab_2
  ftfy               conda-forge/noarch::ftfy-5.5.1-py_0
  funcy              conda-forge/noarch::funcy-1.16-pyhd8ed1ab_0
  future             conda-forge/linux-64::future-0.18.2-py39hf3d152e_3
  gitdb              conda-forge/noarch::gitdb-4.0.7-pyhd8ed1ab_0
  gitpython          conda-forge/noarch::gitpython-3.1.17-pyhd8ed1ab_0
  grandalf           conda-forge/noarch::grandalf-0.6-py_0
  jsonpath-ng        conda-forge/noarch::jsonpath-ng-1.5.2-pyh9f0ad1d_0
  libgit2            conda-forge/linux-64::libgit2-1.1.0-h0b03e73_0
  libgomp            conda-forge/linux-64::libgomp-9.3.0-h2828fa1_19
  libssh2            conda-forge/linux-64::libssh2-1.9.0-ha56f1ee_6
  mailchecker        conda-forge/noarch::mailchecker-4.0.7-pyhd8ed1ab_0
  nanotime           conda-forge/noarch::nanotime-0.5.2-py_0
  networkx           conda-forge/noarch::networkx-2.5-py_0
  pathlib2           conda-forge/linux-64::pathlib2-2.3.5-py39hf3d152e_3
  pathspec           conda-forge/noarch::pathspec-0.8.1-pyhd3deb0d_0
  pcre2              conda-forge/linux-64::pcre2-10.35-h032f7d1_2
  phonenumbers       conda-forge/noarch::phonenumbers-8.10.14-py_0
  pip                conda-forge/noarch::pip-21.1.2-pyhd8ed1ab_0
  ply                conda-forge/noarch::ply-3.11-py_1
  pyasn1             conda-forge/noarch::pyasn1-0.4.8-py_0
  pydot              conda-forge/noarch::pydot-1.2.4-py_0
  pygit2             conda-forge/linux-64::pygit2-1.5.0-py39h3811e60_0
  pygtrie            conda-forge/noarch::pygtrie-2.3.2-pyh8c360ce_0
  python-benedict    conda-forge/noarch::python-benedict-0.24.0-pyhd8ed1ab_0
  python-fsutil      conda-forge/noarch::python-fsutil-0.5.0-pyhd8ed1ab_0
  python-slugify     conda-forge/noarch::python-slugify-5.0.2-pyhd8ed1ab_0
  rich               conda-forge/linux-64::rich-10.2.2-py39hf3d152e_0
  ruamel.yaml        conda-forge/linux-64::ruamel.yaml-0.17.4-py39h3811e60_0
  ruamel.yaml.clib   conda-forge/linux-64::ruamel.yaml.clib-0.2.2-py39h3811e60_2
  shortuuid          conda-forge/linux-64::shortuuid-1.0.1-py39hf3d152e_4
  shtab              conda-forge/noarch::shtab-1.3.6-pyhd8ed1ab_0
  smmap              conda-forge/noarch::smmap-3.0.5-pyh44b312d_0
  tabulate           conda-forge/noarch::tabulate-0.8.9-pyhd8ed1ab_0
  text-unidecode     conda-forge/noarch::text-unidecode-1.3-py_0
  toml               conda-forge/noarch::toml-0.10.2-pyhd8ed1ab_0
  typing_extensions  conda-forge/noarch::typing_extensions-3.7.4.3-py_0
  unidecode          conda-forge/noarch::unidecode-1.2.0-pyhd8ed1ab_0
  voluptuous         conda-forge/noarch::voluptuous-0.12.1-pyhd3deb0d_0
  wheel              conda-forge/noarch::wheel-0.36.2-pyhd3deb0d_0
  zc.lockfile        conda-forge/noarch::zc.lockfile-2.0-py_0

The following packages will be UPDATED:

  certifi            pkgs/main::certifi-2020.12.5-py39h06a~ --> conda-forge::certifi-2020.12.5-py39hf3d152e_1
  libgcc-ng           pkgs/main::libgcc-ng-9.1.0-hdf63c60_0 --> conda-forge::libgcc-ng-9.3.0-h2828fa1_19

The following packages will be SUPERSEDED by a higher-priority channel:

  _libgcc_mutex           pkgs/main::_libgcc_mutex-0.1-main --> conda-forge::_libgcc_mutex-0.1-conda_forge
  ca-certificates    pkgs/main::ca-certificates-2021.4.13-~ --> conda-forge::ca-certificates-2020.12.5-ha878542_0
  conda              pkgs/main::conda-4.10.1-py39h06a4308_1 --> conda-forge::conda-4.10.1-py39hf3d152e_0
  openssl              pkgs/main::openssl-1.1.1k-h27cfd23_0 --> conda-forge::openssl-1.1.1k-h7f98852_0



Downloading and Extracting Packages
diskcache-5.2.1      | 36 KB     | ##################################### | 100% 
pathspec-0.8.1       | 29 KB     | ##################################### | 100% 
cached-property-1.5. | 4 KB      | ##################################### | 100% 
networkx-2.5         | 1.2 MB    | ##################################### | 100% 
commonmark-0.9.1     | 46 KB     | ##################################### | 100% 
configobj-5.0.6      | 31 KB     | ##################################### | 100% 
python-fsutil-0.5.0  | 13 KB     | ##################################### | 100% 
fsspec-0.9.0         | 75 KB     | ##################################### | 100% 
dulwich-0.20.23      | 721 KB    | ##################################### | 100% 
funcy-1.16           | 30 KB     | ##################################### | 100% 
bzip2-1.0.8          | 484 KB    | ##################################### | 100% 
ply-3.11             | 44 KB     | ##################################### | 100% 
libgit2-1.1.0        | 693 KB    | ##################################### | 100% 
ftfy-5.5.1           | 47 KB     | ##################################### | 100% 
nanotime-0.5.2       | 6 KB      | ##################################### | 100% 
pyasn1-0.4.8         | 53 KB     | ##################################### | 100% 
unidecode-1.2.0      | 155 KB    | ##################################### | 100% 
dvc-2.1.0            | 551 KB    | ##################################### | 100% 
pydot-1.2.4          | 20 KB     | ##################################### | 100% 
zc.lockfile-2.0      | 11 KB     | ##################################### | 100% 
dpath-2.0.1          | 23 KB     | ##################################### | 100% 
pcre2-10.35          | 693 KB    | ##################################### | 100% 
ruamel.yaml-0.17.4   | 160 KB    | ##################################### | 100% 
flatten-dict-0.3.0   | 11 KB     | ##################################### | 100% 
python-slugify-5.0.2 | 12 KB     | ##################################### | 100% 
shortuuid-1.0.1      | 15 KB     | ##################################### | 100% 
text-unidecode-1.3   | 68 KB     | ##################################### | 100% 
cached_property-1.5. | 11 KB     | ##################################### | 100% 
colorama-0.4.4       | 18 KB     | ##################################### | 100% 
flufl.lock-3.2       | 19 KB     | ##################################### | 100% 
libssh2-1.9.0        | 226 KB    | ##################################### | 100% 
python-benedict-0.24 | 30 KB     | ##################################### | 100% 
distro-1.5.0         | 20 KB     | ##################################### | 100% 
grandalf-0.6         | 42 KB     | ##################################### | 100% 
future-0.18.2        | 718 KB    | ##################################### | 100% 
ruamel.yaml.clib-0.2 | 173 KB    | ##################################### | 100% 
rich-10.2.2          | 337 KB    | ##################################### | 100% 
shtab-1.3.6          | 15 KB     | ##################################### | 100% 
pygtrie-2.3.2        | 24 KB     | ##################################### | 100% 
mailchecker-4.0.7    | 206 KB    | ##################################### | 100% 
voluptuous-0.12.1    | 28 KB     | ##################################### | 100% 
atpublic-1.0         | 7 KB      | ##################################### | 100% 
phonenumbers-8.10.14 | 1.5 MB    | ##################################### | 100% 
pathlib2-2.3.5       | 35 KB     | ##################################### | 100% 
pygit2-1.5.0         | 213 KB    | ##################################### | 100% 
dictdiffer-0.8.1     | 16 KB     | ##################################### | 100% 
toml-0.10.2          | 18 KB     | ##################################### | 100% 
jsonpath-ng-1.5.2    | 26 KB     | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Note: you may need to restart the kernel to use updated packages.

Stwórzmy katalog, w którym będziemy przechowywać nasz projekt:

!mkdir -p IUM_10/sample-ml-project
#Jupyter notebook magic https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-cd
%cd "IUM_10/sample-ml-project"
/home/tomek/AITech/repo/aitech-ium-private/IUM_10/sample-ml-project

Inicjalizujemy puste repozytorium Git (możemy też pominąć ten krok i działać w istniejącym już repozytorium)

!git init
Initialized empty Git repository in /home/tomek/AITech/repo/aitech-ium-private/IUM_10/sample-ml-project/.git/

Teraz inicjalizujemy repozytorium DVC:

!dvc init
Initialized DVC repository.

You can now commit the changes to git.

+---------------------------------------------------------------------+
|                                                                     |
|        DVC has enabled anonymous aggregate usage analytics.         |
|     Read the analytics documentation (and how to opt-out) here:     |
|             <https://dvc.org/doc/user-guide/analytics>              |
|                                                                     |
+---------------------------------------------------------------------+

What's next?
------------
- Check out the documentation: <https://dvc.org/doc>
- Get help and share ideas: <https://dvc.org/chat>
- Star us on GitHub: <https://github.com/iterative/dvc>


Zobaczmy jakie pliki dodał (również do repozytorium git) DVC. Ich opis znajdziemy tutaj: https://dvc.org/doc/user-guide/project-structure/internal-files

!git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
	new file:   .dvc/.gitignore
	new file:   .dvc/config
	new file:   .dvc/plots/confusion.json
	new file:   .dvc/plots/confusion_normalized.json
	new file:   .dvc/plots/default.json
	new file:   .dvc/plots/linear.json
	new file:   .dvc/plots/scatter.json
	new file:   .dvc/plots/smooth.json
	new file:   .dvcignore

Możemy teraz zacommitować zmiany w git:

!git commit -m "Initial commit"
On branch master
nothing to commit, working tree clean

Śledzenie plików za pomocą DVC

  • dużymi plikami, takimi jak plikami z danymi wejściowymi czy plikami modeli, trudno zarządza się za pomocą gita, ze względu na problemy z:
    • wydajnością
    • przestrzenią w repozytorium
  • Git posiada rozszerzenie lfs(Large File Storage), które stanowi pewne rozwiązanie tego problemu. Same pliki przechowywane są na specjalnym zdalnym serwerze, w repozytorium przechowywane są jedynie odnośniki do tych plików i pewne metadane
  • DVC proponuje podobne podejście, ale:
    • pliki mogą być przechowywane na niemal dowolnym serwerze, również lokalnie
    • brak limitu wielkości plików (w Git-LFS najczęściej limit 2GB)
    • DVC zapewnia dodatkowe narzędzie umożliwiające śledzenie plików i ich powiązań z wynikami eksperymentów
    • więcej, patrz tutaj

Przygotujmy przykładowe dane, pobierając je z Kaggle:

!kaggle datasets download -d uciml/iris
!unzip -o iris.zip
!rm database.sqlite iris.zip
!mkdir -p data
!mv Iris.csv data/
Downloading iris.zip to /home/tomek/AITech/repo/aitech-ium-private/IUM_10/sample-ml-project
  0%|                                               | 0.00/3.60k [00:00<?, ?B/s]
100%|██████████████████████████████████████| 3.60k/3.60k [00:00<00:00, 2.63MB/s]
Archive:  iris.zip
  inflating: Iris.csv                
  inflating: database.sqlite         

Teraz dodamy plik(i) z danymi do DVC:

!dvc add data/Iris.csv
Adding...                                                                       
!
  0%|          |.E8dZEGBYoRayYsJLdesNS4.tmp    0.00/5.11k [00:00<?,       ?it/s]
100% Add|██████████████████████████████████████████████|1/1 [00:04,  4.71s/file]

To track the changes with git, run:

	git add data/Iris.csv.dvc data/.gitignore

  • DVC utworzył plik data/Iris.csv.dvc i dadał oryginalny plik do .gitignore
  • W repozytorium będzie obecny tylko plik *.dvc, zawierający odnośnik do prawdziwego pliku
!git status -u
On branch master
Untracked files:
  (use "git add <file>..." to include in what will be committed)
	data/.gitignore
	data/Iris.csv.dvc
	iris.zip

nothing added to commit but untracked files present (use "git add" to track)

Dodajmy pliki data/Iris.csv.dvc data/.gitignore do repozytorium git, zgodnie z sugestią DVC:

!git add data/Iris.csv.dvc data/.gitignore
!git commit -m "Dodano dane IRIS (DVC)"
[master cc0821a] Dodano dane IRIS (DVC)
 2 files changed, 5 insertions(+)
 create mode 100644 data/.gitignore
 create mode 100644 data/Iris.csv.dvc

Plik *.dvc zawiera m.in. hash pliku. Więcej o plikach *.dvc: link

# %load data/Iris.csv.dvc
outs:
- md5: 717820ef0af287ff346c5cabfb4c612c
  size: 5107
  path: Iris.csv

Oryginalny plik Iris.csv został przeniesiony do katalogu ./dvc/cache/{wartość hash pliku) i podlinkowany z powrotem do oryginalnej lokalizacji. Sposób tworzenia linków może być różny w zależności od systemu plików.

!ls -l .dvc/cache/71
total 8
-r--r--r-- 1 tomek tomek 5107 wrz 19  2019 7820ef0af287ff346c5cabfb4c612c

dvc remote

  • żeby wysłać właściwe pliki śledzone przez DVC do zdalnej lokalizacji (z której będą mogłby być pobrane np. przez system CI albo innych użytkowników) musimy mieć skonfigurowaną taką lokazliację
  • służy do tego polecenie dvc remote add
  • użyjemy lokalnego "remote". Tutaj będzie to po prostu utworzony wcześniej katalog /dvcstore. Taki katalog istnieje też na naszym Jenkinsie, oczywiście należy go podmontować w Dockerze
  • w realnych zastosowaniach podalibyśmy tutaj ścieżkę do jakiegoś zasobu dostępnego przez inernet jak np. serwer SFTP, ścieżka do AWS S3 itp.
!dvc remote add -d my_local_remote /dvcstore
Setting 'my_local_remote' as a default remote.

!git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   .dvc/config

no changes added to commit (use "git add" and/or "git commit -a")
!git add .dvc/config
!git commit -m "Added DVC remote"
[master 3ff62b6] Added DVC remote
 1 file changed, 4 insertions(+)

dvc push

Kiedy mamy już skonfigurowany "remote" możemy wypchnąć do niego pliki korzystając z polecenia dvc push:

!dvc push
!tree /dvcstore
/dvcstore
└── 71
    └── 7820ef0af287ff346c5cabfb4c612c

1 directory, 1 file

dvc pull

Żeby pobrać dane z DVC (np. w innej lokalizacji, przez innego użytkownika), musimy:

  • sklonować repozytorium git (żeby m.in. pobrać pliki *.dvc
  • wykonać dvc pull

Dodawanie nowych plików i modyfikacja istniejących wygląda tak podobnie jak przy zwykłych plikach śledzonych przez git, tylko zamiast git używamy polecenia dvc a dodatkowo pamiętamy o zarządzaniu plikami *.dvc za pomocą gita:

!head -n -1 data/Iris.csv | sponge data/Iris.csv
!git status
On branch master
nothing to commit, working tree clean
!dvc status
data/Iris.csv.dvc:                                                    core>
	changed outs:
		modified:           data/Iris.csv

!dvc add data/Iris.csv
Adding...                                                                       
!
  0%|          |.TatTHknArFHCT9iDCtxHzh.tmp    0.00/5.07k [00:00<?,       ?it/s]
100% Add|██████████████████████████████████████████████|1/1 [00:00,  2.68file/s]

To track the changes with git, run:

	git add data/Iris.csv.dvc

!git add data/Iris.csv.dvc
!git commit -m "Removed last line from Iris dataset"
[master e38c244] Removed last line from Iris dataset
 1 file changed, 2 insertions(+), 2 deletions(-)

dvc checkout

  • Polecenia dvc checkout używamy razem z git checkout, żeby zmienić branch, na którym pracujemy.
  • DVC podmieni wersje plików śledzonych przez siebie na pochodzące z innego brancha (o ile pliki te się różnią i różnią się pliki *.dvc w odpowiednich branchach
  • zmiana brancha przez git powoduje (ewentualną) zmianę plików *.dvc a dvc checkout kopiuje/linkuje pliki z katalogu .dvc/cache o wartościach hash odpowiadających tym z plików *.dvc

Wymiana danych między projektami

  • za pomocą poleceń dvc import i dvc update możemy dodać i później aktualizować pliki śledzone przez DVC w innym repozytorium
!dvc import https://github.com/iterative/dataset-registry \
             get-started/data.xml -o data/data.xml
Importing 'get-started/data.xml (https://github.com/iterative/dataset-registry)' -> 'data/data.xml'
  0% Downloading|                                    |0/1 [00:00<?,     ?file/s]
!
  0%|          |get-started/data.xml           0.00/37.9M [00:00<?,       ?it/s]
  0%|          |get-started/data.xml      64.0k/36.1M [00:00<02:12,     286kB/s]
  0%|          |get-started/data.xml       128k/36.1M [00:00<01:33,     403kB/s]
  1%|          |get-started/data.xml       256k/36.1M [00:00<00:57,     658kB/s]
  1%|          |get-started/data.xml       384k/36.1M [00:00<00:45,     818kB/s]
  1%|▏         |get-started/data.xml       512k/36.1M [00:00<00:53,     693kB/s]
  2%|▏         |get-started/data.xml       640k/36.1M [00:01<00:57,     644kB/s]
  2%|▏         |get-started/data.xml       768k/36.1M [00:01<00:59,     619kB/s]
  2%|▏         |get-started/data.xml       896k/36.1M [00:01<00:51,     718kB/s]
  3%|▎         |get-started/data.xml      1.00M/36.1M [00:01<00:55,     666kB/s]
  3%|▎         |get-started/data.xml      1.12M/36.1M [00:01<00:57,     633kB/s]
  3%|▎         |get-started/data.xml      1.25M/36.1M [00:02<00:57,     638kB/s]
  4%|▍         |get-started/data.xml      1.38M/36.1M [00:02<00:52,     698kB/s]
  4%|▍         |get-started/data.xml      1.50M/36.1M [00:02<00:55,     656kB/s]
  4%|▍         |get-started/data.xml      1.62M/36.1M [00:02<00:57,     628kB/s]
  5%|▍         |get-started/data.xml      1.69M/36.1M [00:02<00:58,     618kB/s]
  5%|▌         |get-started/data.xml      1.81M/36.1M [00:02<00:53,     675kB/s]
  5%|▌         |get-started/data.xml      1.94M/36.1M [00:03<00:53,     672kB/s]
  6%|▌         |get-started/data.xml      2.06M/36.1M [00:03<00:55,     642kB/s]
  6%|▌         |get-started/data.xml      2.12M/36.1M [00:03<00:56,     628kB/s]
  6%|▌         |get-started/data.xml      2.19M/36.1M [00:03<00:57,     616kB/s]
  6%|▌         |get-started/data.xml      2.25M/36.1M [00:03<00:58,     606kB/s]
  7%|▋         |get-started/data.xml      2.38M/36.1M [00:03<00:48,     732kB/s]
  7%|▋         |get-started/data.xml      2.50M/36.1M [00:04<00:52,     666kB/s]
  7%|▋         |get-started/data.xml      2.62M/36.1M [00:04<00:55,     636kB/s]
  8%|▊         |get-started/data.xml      2.75M/36.1M [00:04<00:56,     614kB/s]
  8%|▊         |get-started/data.xml      2.88M/36.1M [00:04<00:49,     711kB/s]
  8%|▊         |get-started/data.xml      3.00M/36.1M [00:04<00:52,     663kB/s]
  9%|▊         |get-started/data.xml      3.12M/36.1M [00:05<00:54,     637kB/s]
  9%|▉         |get-started/data.xml      3.25M/36.1M [00:05<00:55,     623kB/s]
  9%|▉         |get-started/data.xml      3.38M/36.1M [00:05<00:48,     710kB/s]
 10%|▉         |get-started/data.xml      3.50M/36.1M [00:05<00:51,     664kB/s]
 10%|█         |get-started/data.xml      3.62M/36.1M [00:05<00:45,     751kB/s]
 10%|█         |get-started/data.xml      3.75M/36.1M [00:05<00:49,     691kB/s]
 11%|█         |get-started/data.xml      3.88M/36.1M [00:06<00:43,     777kB/s]
 11%|█         |get-started/data.xml      4.00M/36.1M [00:06<00:47,     705kB/s]
 11%|█▏        |get-started/data.xml      4.12M/36.1M [00:06<00:42,     790kB/s]
 12%|█▏        |get-started/data.xml      4.25M/36.1M [00:06<00:46,     716kB/s]
 12%|█▏        |get-started/data.xml      4.38M/36.1M [00:06<00:44,     749kB/s]
 12%|█▏        |get-started/data.xml      4.50M/36.1M [00:07<00:45,     734kB/s]
 13%|█▎        |get-started/data.xml      4.62M/36.1M [00:07<00:40,     810kB/s]
 13%|█▎        |get-started/data.xml      4.75M/36.1M [00:07<00:42,     773kB/s]
 13%|█▎        |get-started/data.xml      4.88M/36.1M [00:07<00:41,     795kB/s]
 14%|█▍        |get-started/data.xml      5.00M/36.1M [00:07<00:37,     870kB/s]
 14%|█▍        |get-started/data.xml      5.12M/36.1M [00:07<00:34,     932kB/s]
 15%|█▍        |get-started/data.xml      5.25M/36.1M [00:07<00:35,     916kB/s]
 15%|█▍        |get-started/data.xml      5.38M/36.1M [00:08<00:35,     898kB/s]
 15%|█▌        |get-started/data.xml      5.50M/36.1M [00:08<00:33,     962kB/s]
 16%|█▌        |get-started/data.xml      5.62M/36.1M [00:08<00:33,     949kB/s]
 16%|█▌        |get-started/data.xml      5.75M/36.1M [00:08<00:31,    1.00MB/s]
 16%|█▋        |get-started/data.xml      5.88M/36.1M [00:08<00:30,    1.04MB/s]
 17%|█▋        |get-started/data.xml      6.06M/36.1M [00:08<00:26,    1.19MB/s]
 17%|█▋        |get-started/data.xml      6.19M/36.1M [00:08<00:26,    1.19MB/s]
 17%|█▋        |get-started/data.xml      6.31M/36.1M [00:08<00:26,    1.19MB/s]
 18%|█▊        |get-started/data.xml      6.50M/36.1M [00:08<00:23,    1.31MB/s]
 18%|█▊        |get-started/data.xml      6.62M/36.1M [00:09<00:23,    1.30MB/s]
 19%|█▉        |get-started/data.xml      6.81M/36.1M [00:09<00:21,    1.41MB/s]
 19%|█▉        |get-started/data.xml      7.00M/36.1M [00:09<00:20,    1.48MB/s]
 20%|█▉        |get-started/data.xml      7.19M/36.1M [00:09<00:19,    1.54MB/s]
 20%|██        |get-started/data.xml      7.38M/36.1M [00:09<00:18,    1.60MB/s]
 21%|██        |get-started/data.xml      7.56M/36.1M [00:09<00:18,    1.62MB/s]
 21%|██▏       |get-started/data.xml      7.75M/36.1M [00:09<00:17,    1.68MB/s]
 22%|██▏       |get-started/data.xml      7.94M/36.1M [00:09<00:17,    1.70MB/s]
 22%|██▏       |get-started/data.xml      8.12M/36.1M [00:10<00:17,    1.72MB/s]
 23%|██▎       |get-started/data.xml      8.38M/36.1M [00:10<00:15,    1.88MB/s]
 24%|██▎       |get-started/data.xml      8.56M/36.1M [00:10<00:15,    1.84MB/s]
 24%|██▍       |get-started/data.xml      8.81M/36.1M [00:10<00:14,    1.96MB/s]
 25%|██▌       |get-started/data.xml      9.06M/36.1M [00:10<00:13,    2.06MB/s]
 26%|██▌       |get-started/data.xml      9.31M/36.1M [00:10<00:13,    2.14MB/s]
 27%|██▋       |get-started/data.xml      9.62M/36.1M [00:10<00:11,    2.32MB/s]
 27%|██▋       |get-started/data.xml      9.88M/36.1M [00:10<00:11,    2.33MB/s]
 28%|██▊       |get-started/data.xml      10.2M/36.1M [00:10<00:11,    2.46MB/s]
 29%|██▉       |get-started/data.xml      10.4M/36.1M [00:11<00:10,    2.45MB/s]
 30%|██▉       |get-started/data.xml      10.8M/36.1M [00:11<00:10,    2.57MB/s]
 31%|███       |get-started/data.xml      11.1M/36.1M [00:11<00:09,    2.67MB/s]
 32%|███▏      |get-started/data.xml      11.4M/36.1M [00:11<00:09,    2.84MB/s]
 33%|███▎      |get-started/data.xml      11.8M/36.1M [00:11<00:08,    2.85MB/s]
 34%|███▎      |get-started/data.xml      12.1M/36.1M [00:11<00:08,    3.01MB/s]
 35%|███▍      |get-started/data.xml      12.5M/36.1M [00:11<00:07,    3.12MB/s]
 36%|███▌      |get-started/data.xml      12.9M/36.1M [00:11<00:07,    3.22MB/s]
 37%|███▋      |get-started/data.xml      13.2M/36.1M [00:11<00:07,    3.31MB/s]
 38%|███▊      |get-started/data.xml      13.7M/36.1M [00:12<00:06,    3.49MB/s]
 39%|███▉      |get-started/data.xml      14.1M/36.1M [00:12<00:06,    3.62MB/s]
 40%|████      |get-started/data.xml      14.6M/36.1M [00:12<00:06,    3.74MB/s]
 42%|████▏     |get-started/data.xml      15.0M/36.1M [00:12<00:05,    3.82MB/s]
 43%|████▎     |get-started/data.xml      15.4M/36.1M [00:12<00:05,    3.97MB/s]
 44%|████▍     |get-started/data.xml      15.9M/36.1M [00:12<00:05,    4.08MB/s]
 45%|████▌     |get-started/data.xml      16.4M/36.1M [00:12<00:04,    4.23MB/s]
 47%|████▋     |get-started/data.xml      17.0M/36.1M [00:12<00:04,    4.44MB/s]
 48%|████▊     |get-started/data.xml      17.5M/36.1M [00:12<00:04,    4.52MB/s]
 50%|████▉     |get-started/data.xml      18.1M/36.1M [00:13<00:04,    4.69MB/s]
 52%|█████▏    |get-started/data.xml      18.6M/36.1M [00:13<00:03,    4.84MB/s]
 53%|█████▎    |get-started/data.xml      19.2M/36.1M [00:13<00:03,    5.05MB/s]
 55%|█████▍    |get-started/data.xml      19.8M/36.1M [00:13<00:03,    5.16MB/s]
 57%|█████▋    |get-started/data.xml      20.4M/36.1M [00:13<00:03,    5.35MB/s]
 58%|█████▊    |get-started/data.xml      21.1M/36.1M [00:13<00:02,    5.49MB/s]
 60%|██████    |get-started/data.xml      21.8M/36.1M [00:13<00:02,    5.66MB/s]
 62%|██████▏   |get-started/data.xml      22.4M/36.1M [00:13<00:02,    5.83MB/s]
 64%|██████▍   |get-started/data.xml      23.2M/36.1M [00:14<00:02,    6.05MB/s]
 66%|██████▌   |get-started/data.xml      23.9M/36.1M [00:14<00:02,    6.20MB/s]
 68%|██████▊   |get-started/data.xml      24.6M/36.1M [00:14<00:01,    6.40MB/s]
 70%|███████   |get-started/data.xml      25.4M/36.1M [00:14<00:01,    6.51MB/s]
 72%|███████▏  |get-started/data.xml      26.0M/36.1M [00:14<00:01,    5.75MB/s]
 74%|███████▎  |get-started/data.xml      26.6M/36.1M [00:14<00:02,    4.26MB/s]
 75%|███████▍  |get-started/data.xml      27.1M/36.1M [00:14<00:02,    3.53MB/s]
 76%|███████▌  |get-started/data.xml      27.5M/36.1M [00:15<00:02,    3.26MB/s]
 77%|███████▋  |get-started/data.xml      27.9M/36.1M [00:15<00:02,    3.00MB/s]
 78%|███████▊  |get-started/data.xml      28.2M/36.1M [00:15<00:02,    2.95MB/s]
 79%|███████▉  |get-started/data.xml      28.5M/36.1M [00:15<00:02,    2.91MB/s]
 80%|███████▉  |get-started/data.xml      28.8M/36.1M [00:15<00:02,    2.88MB/s]
 81%|████████  |get-started/data.xml      29.1M/36.1M [00:15<00:02,    2.86MB/s]
 81%|████████▏ |get-started/data.xml      29.4M/36.1M [00:15<00:02,    2.84MB/s]
 82%|████████▏ |get-started/data.xml      29.8M/36.1M [00:16<00:02,    2.83MB/s]
 83%|████████▎ |get-started/data.xml      30.1M/36.1M [00:16<00:02,    2.83MB/s]
 84%|████████▍ |get-started/data.xml      30.4M/36.1M [00:16<00:02,    2.83MB/s]
 85%|████████▍ |get-started/data.xml      30.7M/36.1M [00:16<00:02,    2.83MB/s]
 86%|████████▌ |get-started/data.xml      31.0M/36.1M [00:16<00:01,    2.83MB/s]
 87%|████████▋ |get-started/data.xml      31.3M/36.1M [00:16<00:01,    2.83MB/s]
 88%|████████▊ |get-started/data.xml      31.6M/36.1M [00:16<00:01,    2.83MB/s]
 88%|████████▊ |get-started/data.xml      31.9M/36.1M [00:16<00:01,    2.84MB/s]
 89%|████████▉ |get-started/data.xml      32.2M/36.1M [00:16<00:01,    2.85MB/s]
 90%|█████████ |get-started/data.xml      32.6M/36.1M [00:17<00:01,    2.85MB/s]
 91%|█████████ |get-started/data.xml      32.9M/36.1M [00:17<00:01,    2.86MB/s]
 92%|█████████▏|get-started/data.xml      33.2M/36.1M [00:17<00:01,    2.86MB/s]
 93%|█████████▎|get-started/data.xml      33.5M/36.1M [00:17<00:00,    2.87MB/s]
 94%|█████████▎|get-started/data.xml      33.8M/36.1M [00:17<00:00,    2.87MB/s]
 94%|█████████▍|get-started/data.xml      34.1M/36.1M [00:17<00:00,    2.87MB/s]
 95%|█████████▌|get-started/data.xml      34.4M/36.1M [00:17<00:00,    2.87MB/s]
 96%|█████████▌|get-started/data.xml      34.8M/36.1M [00:17<00:00,    2.87MB/s]
 97%|█████████▋|get-started/data.xml      35.1M/36.1M [00:17<00:00,    2.87MB/s]
 98%|█████████▊|get-started/data.xml      35.4M/36.1M [00:18<00:00,    2.87MB/s]
 99%|█████████▉|get-started/data.xml      35.7M/36.1M [00:18<00:00,    2.88MB/s]
100%|█████████▉|get-started/data.xml      36.0M/36.1M [00:18<00:00,    2.87MB/s]
                                                                                
To track the changes with git, run:

	git add data/.gitignore data/data.xml.dvc

!dvc status
Data and pipelines are up to date.                                              

ls -l data
total 37020
-rw-rw-r-- 1 tomek tomek 37891850 maj 31 11:10 data.xml
-rw-rw-r-- 1 tomek tomek      284 maj 31 11:10 data.xml.dvc
-rw-rw-r-- 1 tomek tomek     5072 maj 31 11:01 Iris.csv
-rw-rw-r-- 1 tomek tomek       76 maj 31 11:01 Iris.csv.dvc
# %load data/data.xml.dvc
md5: a7cd139231cc35ed63541ce3829b96db
frozen: true
deps:
- path: get-started/data.xml
  repo:
    url: https://github.com/iterative/dataset-registry
    rev_lock: ba014f40e29670421a67cb1c47543f402348aa13
outs:
- md5: a304afb96060aad90176268345e10355
  size: 37891850
  path: data.xml

DVC pipelines

  • wprowadzenie: https://youtu.be/71IGzyH95UY
  • Getting started: https://dvc.org/doc/start/data-pipelines
  • dvc pipelines pozwala nam zbudować (za pomocą polecenie dvc run) lub zdefiniować (edytując plik dvc.yaml) graf zależności między krokami wykonywanymi w naszym projekcie (takimi jak "przygotowanie danych", "trenowanie", "ewaluacja")
  • tak zdefiniowany pipeline można potem uruchomić za pomocą polecenia dvc reproduce

Zadania [15pkt]

  1. Zainicjalizuj repozytorium DVC wewnątrz Twojego repozytorium z projektem [1pkt]
  2. Dodaj plik(i) z danymi w Twoim projekcie do DVC [1pkt]
  3. Skonfiguruj remote (dane do konfiguracji będą podane niebawem) [1pkt]
  4. Stwórz/zdefiniuj i dodaj do repozytorium plik dvc.yaml opisujący kroki wykonywane w Twoim projekcie. Wydziel przynajmniej 2 kroki (np. przygotowanie danych/trenowanie) powiązane ze sobą za pomocą zależności (skorzystaj z materiałów "Getting started", link powyżej) [6pkt]
  5. Stwórz projekt na Jenkinsie (s1233456-dvc), w którym sklonujesz repozytorium, ściągniesz pliki dvc (za pomocą dvc pull) i uruchomisz pipeline (za pomocą dvc reproduce) [6pkt]

SSH remote

Jednym z remote obsługiwanych przez DVC jest SFTP/SSH. W celu jego wykorzystania na serwerze tzietkiewicz.vm.wmi.amu.edu.pl utworzony został użytkownik ium-sftp i skonfigurowany serwer SFTP. Został też dla niego wygenerowany klucz ssh, który został dodany jako "Jenkins credential" (patrz opis konfiguracji na Jenkins poniżej)

Lokalnie

Będziemy potrzebować zależności :

conda install dvc-ssh

albo

pip install dvc[ssh] paramiko

conda install -c conda-forge dvc-ssh
Collecting package metadata (current_repodata.json): done
Solving environment: done

## Package Plan ##

  environment location: /home/tomek/miniconda3

  added / updated specs:
    - dvc-ssh


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    bcrypt-3.2.0               |   py39h3811e60_1          44 KB  conda-forge
    ca-certificates-2021.5.30  |       ha878542_0         136 KB  conda-forge
    certifi-2021.5.30          |   py39hf3d152e_0         141 KB  conda-forge
    dvc-2.3.0                  |   py39hf3d152e_0         542 KB  conda-forge
    dvc-ssh-2.3.0              |   py39hf3d152e_0           9 KB  conda-forge
    fsspec-2021.5.0            |     pyhd8ed1ab_0          77 KB  conda-forge
    invoke-1.5.0               |     pyhd3deb0d_0         137 KB  conda-forge
    paramiko-2.7.2             |     pyh9f0ad1d_0         135 KB  conda-forge
    pynacl-1.4.0               |   py39h3811e60_2         1.3 MB  conda-forge
    ------------------------------------------------------------
                                           Total:         2.5 MB

The following NEW packages will be INSTALLED:

  bcrypt             conda-forge/linux-64::bcrypt-3.2.0-py39h3811e60_1
  dvc-ssh            conda-forge/linux-64::dvc-ssh-2.3.0-py39hf3d152e_0
  invoke             conda-forge/noarch::invoke-1.5.0-pyhd3deb0d_0
  paramiko           conda-forge/noarch::paramiko-2.7.2-pyh9f0ad1d_0
  pynacl             conda-forge/linux-64::pynacl-1.4.0-py39h3811e60_2

The following packages will be UPDATED:

  ca-certificates                      2020.12.5-ha878542_0 --> 2021.5.30-ha878542_0
  certifi                          2020.12.5-py39hf3d152e_1 --> 2021.5.30-py39hf3d152e_0
  dvc                                  2.1.0-py39hf3d152e_0 --> 2.3.0-py39hf3d152e_0
  fsspec                                 0.9.0-pyhd8ed1ab_2 --> 2021.5.0-pyhd8ed1ab_0



Downloading and Extracting Packages
certifi-2021.5.30    | 141 KB    | ##################################### | 100% 
fsspec-2021.5.0      | 77 KB     | ##################################### | 100% 
dvc-2.3.0            | 542 KB    | ##################################### | 100% 
invoke-1.5.0         | 137 KB    | ##################################### | 100% 
paramiko-2.7.2       | 135 KB    | ##################################### | 100% 
bcrypt-3.2.0         | 44 KB     | ##################################### | 100% 
pynacl-1.4.0         | 1.3 MB    | ##################################### | 100% 
dvc-ssh-2.3.0        | 9 KB      | ##################################### | 100% 
ca-certificates-2021 | 136 KB    | ##################################### | 100% 
Preparing transaction: done
Verifying transaction: done
Executing transaction: done

Note: you may need to restart the kernel to use updated packages.
!dvc remote add -f -d ium_ssh_remote ssh://ium-sftp@tzietkiewicz.vm.wmi.amu.edu.pl/ium-sftp
Setting 'ium_ssh_remote' as a default remote.

!dvc remote list
my_local_remote	/dvcstore
ium_ssh_remote	ssh://ium-sftp@tzietkiewicz.vm.wmi.amu.edu.pl/ium-sftp

!dvc remote modify --local ium_ssh_remote password [hasło takie jak do serwera MLflow (patrz MSTeams)]

!dvc push
  0% Uploading|                                      |0/1 [00:00<?,     ?file/s]
!
  0%|          |data/Iris.csv                  0.00/4.95k [00:00<?,        ?B/s]
1 file pushed                                                                   


Jenkins

W Jenkins można użyć mechanizmu "Credentials", żeby w bezpieczny sposób przekazać hasło albo klucz prywatny.

Takie dane dla użytkownika ium-sftp zostały stworzone na Jenkinsie:

Opis używania "Credentials" w Jenkinsfile: https://www.jenkins.io/doc/book/pipeline/jenkinsfile/#for-other-credential-types

Klucza ssh można użyć tak:

withCredentials(
    [sshUserPrivateKey(credentialsId: '48ac7004-216e-4260-abba-1fe5db753e18', keyFileVariable: 'IUM_SFTP_KEY', passphraseVariable: '', usernameVariable: '')]) {
                sh "dvc init -f"
                sh "dvc remote add -d ium_ssh_remote ssh://ium-sftp@tzietkiewicz.vm.wmi.amu.edu.pl/ium-sftp"
                sh "dvc remote modify --local ium_ssh_remote keyfile $IUM_SFTP_KEY"
                sh "dvc pull"}

Secret text tak:

    withCredentials([string(credentialsId: 'ium-sftp-password', variable: 'IUM_SFTP_PASS')]) {
                sh "dvc init -f"
                sh "dvc remote add -d ium_ssh_remote ssh://ium-sftp@tzietkiewicz.vm.wmi.amu.edu.pl/ium-sftp"
                sh "dvc remote modify --local ium_ssh_remote password $IUM_SFTP_KEY"
                sh "dvc pull"
    }

Przykład kongiguracji: