/
data-science-stack
executable file
·1447 lines (1211 loc) · 37.3 KB
/
data-science-stack
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
# Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved.
# Global Paramaters
STACK_VERSION=2.11.0
NOTEBOOKS_VERSION=23.02
MIN_DRIVER=530.30.02
MIN_CUDA=12.1.0
MIN_DOCKER=20.10.23
MIN_CONDA=23.3.1-0
SCRIPT_NAME=$(basename $0)
RUNFROM=$(dirname $(readlink -f $0))
DEFAULT_ENVIRONMENT="data-science-stack"
LOGFILE=data-science-stack.log
CONDA_ROOT=${HOME}/.conda
DEFAULT_NOTEBOOKS_DIR=${HOME}/data-science-stack-${STACK_VERSION}
NOTEBOOKS_DIR=${NOTEBOOKS_DIR:-$DEFAULT_NOTEBOOKS_DIR}
KAGGLE_DOCKER_IMAGE=gcr.io/kaggle-gpu-images/python
AWS_DOCKER_IMAGE=amazon/aws-cli
WSL=false
_tmp=`uname -a | grep microsoft`
if [ ! -z "$_tmp" ]
then
WSL=true
echo "WARNING: WSL detected. Support for WSL is alpha only."
fi
. /etc/os-release
OS_FLAVOR=$ID
OS_RELEASE=$VERSION_ID
OS_RELEASE_MAJOR=${VERSION_ID%%.*} # extract major release, e.g. 1.2 -> 1, 1.2.3 -> 1
case $OS_FLAVOR$OS_RELEASE in
ubuntu18.04 | ubuntu20.04 | ubuntu22.04 | rhel7* | rhel8* )
;;
*)
echo "Unknown system type: $OS_FLAVOR $OS_RELEASE"
exit 1
;;
esac
PIN_CONTAINER="frolvlad/alpine-miniconda3:python3.7"
PIN_TMP="tmp.json"
REBOOT=0
LOGOUT=0
nvlog () {
echo "###NV### `date` #### $1"
}
install_autocomplete() {
if [ ! -f ~/.bash_completion ]
then
echo "#/usr/bin/env bash" > ~/.bash_completion
cat dss.comp >> ~/.bash_completion
else
# does the existing file contain the autocompletion already?
_tmp=`grep "complete -F _dss ./data-science-stack" ~/.bash_completion`
if [ -z "$_tmp" ]
then
# add our autocompletions
cat dss.comp >> ~/.bash_completion
fi
fi
}
require_user () {
if [ $(id -u) = 0 ]; then
nvlog "ERROR: Cannot run this step as root, run script as user or without 'sudo'"
exit 1
fi
}
semver_gte () {
# $1 >= $2 ?
[ "$2" != "`echo -e "$1\n$2" | sort -V | head -n1`" ]
}
install_base () {
nvlog "START Installing base packages"
# Install base apt/yum packages needed
set -e
if [ $OS_FLAVOR = "ubuntu" ]; then
sudo apt-get -y update --fix-missing
sudo apt-get -y upgrade
sudo apt-get -y install --no-install-recommends apt-utils
sudo apt-get -y install \
curl \
font-manager \
graphviz \
git \
gcc \
g++ \
jq \
npm \
screen \
tzdata \
wget \
unzip \
zlib1g-dev
elif [ $OS_FLAVOR$OS_RELEASE_MAJOR = "rhel7" ]; then
sudo subscription-manager repos --enable rhel-7-workstation-devtools-rpms
sudo subscription-manager repos --enable rhel-7-workstation-optional-rpms
sudo subscription-manager repos --enable rhel-7-workstation-extras-rpms
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm || true
sudo yum groups mark convert
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y \
bzip2 \
clang \
curl \
device-mapper-persistent-data \
devtoolset-4 \
file \
git \
graphviz \
jq \
lvm2 \
npm \
screen \
vim \
wget \
which \
yum-utils
else # RHEL 8
sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm || true
sudo yum groupinstall -y 'Development Tools'
sudo yum install -y \
bzip2 \
clang \
curl \
device-mapper-persistent-data \
file \
git \
graphviz \
jq \
lvm2 \
npm \
screen \
vim \
wget \
which \
yum-utils
fi
set +e
install_autocomplete
nvlog "END Installing base packages"
}
detect_driver () {
if [ -f /usr/bin/nvidia-smi ]; then
DRIVER_VER=$(/usr/bin/nvidia-smi --query-gpu=driver_version --format=csv,noheader | head -n1 | cut -d " " -f1 2> /dev/null)
if [ $? -ne 0 ]; then
DRIVER_VER=0
fi
if [ $DRIVER_VER = "Failed" ]; then
DRIVER_VER=0
fi
else
DRIVER_VER=0
fi
}
install_driver () {
nvlog "START Installing Driver"
if [ "$WSL" = true ]
then
nvlog "Driver installation is not needed in WSL - skip install"
nvlog "END Installing Driver"
return
fi
if [ $OS_FLAVOR = "ubuntu" ]; then
if [ -f /usr/bin/nvidia-uninstall ]; then
cat << EOF
Found /usr/bin/nvidia-uninstall which means a driver .run file was used
on this machine. Driver install/update cannot proceed. The solution is to
purge the driver and reinstall it with the correct apt repositories.
Make sure you are connected to the internet and run:
${SCRIPT_NAME} purge-driver
${SCRIPT_NAME} install-driver
Then rerun the command you just ran to proceed.
EOF
exit 1
fi
fi
semver_gte $DRIVER_VER $MIN_DRIVER
if [ $? -eq 1 ]; then
nvlog "Driver is new enough - skip install"
nvlog "END Installing Driver"
return
fi
set -e
#if [ $OS_FLAVOR = "ubuntu" ]; then NO LONGER NEEDED INSTALL_CUDA will load the driver
# sudo add-apt-repository -y ppa:graphics-drivers/ppa
#sudo apt-get -y update
#sudo apt-get -y upgrade
#sudo apt-get -y install nvidia-driver-525
#sudo apt-get -y autoremove
#REBOOT=1
#el
if [ $OS_FLAVOR$OS_RELEASE_MAJOR = "rhel8" ]; then
sudo dnf config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
sudo dnf install -y kernel-devel-$(uname -r) kernel-headers-$(uname -r)
sudo dnf -y module install nvidia-driver:465-dkms
# REBOOT not necessary
else
nvlog "Automated NVIDIA driver install on $OS_FLAVOR $OS_RELEASE_FULL is not supported."
nvlog "Please install NVIDIA driver $MIN_DRIVER or newer and run again."
exit 1
fi
set +e
nvlog "END Installing Driver"
}
purge_driver () {
nvlog "START Purge Driver"
if [ "$WSL" = true ]
then
nvlog "Driver Purge is not needed in WSL - skip Purge"
nvlog "END Purge Driver"
return
fi
if [ $OS_FLAVOR != "ubuntu" ]; then
nvlog "ERROR: Automated NVIDIA driver purge for Red Hat not supported."
nvlog "Please run /usr/bin/nvidia-uninstall and reboot to remove driver."
exit 1
fi
cat << EOF
WARNING:
Removing the NVIDIA Driver will also remove CUDA and other libraries like
nvidia-docker2 that depend on the driver.
Helpful once the system is rebooted:
${SCRIPT_NAME} setup-system
EOF
read -p "DANGER: Are you SURE [y/N]?" -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
nvlog "Starting removal..."
if [ -f /usr/bin/nvidia-uninstall ]; then
nvlog "Running /usr/bin/nvidia-uninstall first."
sudo /usr/bin/nvidia-uninstall
fi
sudo apt-get -y purge nvidia-*
sudo apt -y autoremove
sudo rm -f /etc/modprobe.d/blacklist-nouveau.conf
sudo rm -f /etc/modprobe.d/nvidia-installer-disable-nouveau.conf
sudo update-initramfs -k all -u
REBOOT=1
else
nvlog "Aborting - doing nothing"
fi
nvlog "END Purge Driver"
}
detect_cuda () {
if [ -f /usr/local/cuda/version.json ]; then
CUDA_VER=$(jq -r ".cuda.version" /usr/local/cuda/version.json 2>/dev/null)
elif [ -f /usr/local/cuda/version.txt ]; then
CUDA_VER=$(cat /usr/local/cuda/version.txt | awk '{ print $3 }' 2> /dev/null)
if [ $? -ne 0 ]; then
CUDA_VER=0
fi
else
CUDA_VER=0
fi
}
install_cuda () {
nvlog "START Installing CUDA"
semver_gte $CUDA_VER $MIN_CUDA
if [ $? -eq 1 ]; then
nvlog "CUDA is new enough - skip install"
nvlog "END Installing CUDA"
return
fi
set -e
if [ $OS_FLAVOR = "ubuntu" ]; then
if [ $OS_RELEASE = "18.04" ]; then
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda
elif [ $OS_RELEASE = "20.04" ]; then
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda
else
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.0-1_all.deb
sudo dpkg -i cuda-keyring_1.0-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda
fi
else
if [ $OS_FLAVOR$OS_RELEASE_MAJOR = "rhel7" ]; then
sudo yum-config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/cuda-rhel7.repo
sudo yum clean all
sudo yum install -y cuda-toolkit-11-7
else
sudo dnf config-manager --add-repo http://developer.download.nvidia.com/compute/cuda/repos/rhel8/x86_64/cuda-rhel8.repo
sudo dnf clean all
sudo dnf -y install cuda-toolkit-11-7
fi
fi
set +e
echo "export PATH=/usr/local/cuda/bin/:\$PATH # DATA-SCIENCE-STACK-ADDED" >> ${HOME}/.bashrc
echo "export LD_LIBRARY_PATH=/usr/local/cuda-11.7/lib64:/lib:\$LD_LIBRARY_PATH # DATA-SCIENCE-STACK-ADDED" >> ${HOME}/.bashrc
source ${HOME}/.bashrc
nvlog "END Installing CUDA"
}
detect_docker () {
DOCKER_VER=$(docker version --format '{{.Client.Version}}' 2> /dev/null)
if [ $? -ne 0 ]; then
DOCKER_VER=0
fi
}
install_docker () {
nvlog "START Installing Docker and NVIDIA Container Toolkit"
semver_gte $DOCKER_VER $MIN_DOCKER
if [ $? -eq 1 ]; then
nvlog "Docker is new enough, checking for nvidia-docker2..."
if [ $OS_FLAVOR = "ubuntu" ]; then
nvd2=$(dpkg -l | grep nvidia-docker2 | grep ii)
else
nvd2=$(yum list installed | grep nvidia-docker2)
fi
if [ "$nvd2" != "" ]; then
nvlog "nvidia-docker2 found, no install needed"
nvlog "END Installing Docker and NVIDIA Container Toolkit"
return
fi
fi
set -e
if [ $OS_FLAVOR = "ubuntu" ]; then
# NVIDIA Repo
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$OS_FLAVOR$OS_RELEASE/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
# Docker Repo
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get -y update
sudo apt-get -y install \
apt-transport-https \
ca-certificates \
gnupg-agent \
software-properties-common
sudo apt-get -y install \
nvidia-docker2 \
docker-ce \
docker-ce-cli \
containerd.io
sudo systemctl enable docker
sudo apt install -y acl
nvlog "setting nvidia runtime as the default docker runtime"
sudo mv /etc/docker/daemon.json /etc/docker/daemon.json.bak
sudo cp docker/daemon.json /etc/docker/daemon.json
if [ "$WSL" = true ]
then
sudo /etc/init.d/docker start
sudo groupadd -f docker
sudo /etc/init.d/docker restart
# wait for /var/run/docker.sock to be created
while [ ! -S /var/run/docker.sock ]
do
nvlog "/var/run/docker.sock does not exist, waiting"
sleep 1
done
nvlog "/var/run/docker.sock verified"
else
sudo systemctl start docker
sudo groupadd -f docker
sudo systemctl restart docker
fi
elif [ $OS_FLAVOR$OS_RELEASE_MAJOR = "rhel7" ]; then
# NVIDIA Repos
curl -s -L https://nvidia.github.io/nvidia-docker/$OS_FLAVOR$OS_RELEASE/nvidia-docker.repo | \
sudo tee /etc/yum.repos.d/nvidia-docker.repo
# Docker Repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y \
nvidia-docker2 \
docker-ce \
docker-ce-cli \
containerd.io
sudo systemctl enable docker
if [ "$WSL" = true ]
then
sudo /etc/init.d/docker start
sudo groupadd -f docker
sudo /etc/init.d/docker restart
# wait for /var/run/docker.sock to be created
while [ ! -S /var/run/docker.sock ]
do
nvlog "/var/run/docker.sock does not exist, waiting"
sleep 1
done
nvlog "/var/run/docker.sock verified"
else
sudo systemctl start docker
sudo groupadd -f docker
sudo systemctl restart docker
fi
else # RHEL 8
# NVIDIA Repos
curl -s -L https://nvidia.github.io/nvidia-docker/$OS_FLAVOR$OS_RELEASE/nvidia-docker.repo | \
sudo tee /etc/yum.repos.d/nvidia-docker.repo
# Docker Repo
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
# force new-enough containerd.io
curl -s https://download.docker.com/linux/centos/7/x86_64/stable/Packages/containerd.io-1.2.13-3.2.el7.x86_64.rpm \
--output containerd.rpm
sudo yum localinstall -y containerd.rpm
rm containerd.rpm
sudo yum install -y \
docker-ce \
nvidia-container-toolkit \
iptables
sudo systemctl enable docker
if [ "$WSL" = true ]
then
sudo /etc/init.d/docker start
sudo groupadd -f docker
sudo /etc/init.d/docker restart
# wait for /var/run/docker.sock to be created
while [ ! -S /var/run/docker.sock ]
do
nvlog "/var/run/docker.sock does not exist, waiting"
sleep 1
done
nvlog "/var/run/docker.sock verified"
else
sudo systemctl start docker
sudo groupadd -f docker
sudo systemctl restart docker
fi
fi
set +e
nvlog "END Installing Docker and NVIDIA Container Toolkit"
}
docker_adduser () {
nvlog "START Add User to Docker Group"
if groups $USER | grep -qw '\bdocker\b'; then
nvlog "User already member of docker group"
nvlog "END Add User to Docker Group"
return
fi
set -e
nvlog "Adding user '$USER' to docker group"
sudo usermod -a -G docker $USER
sudo setfacl -m user:$USER:rw /var/run/docker.sock
if [ "$WSL" = true ]
then
sudo /etc/init.d/docker restart
else
sudo systemctl daemon-reload
sudo systemctl reload docker
fi
LOGOUT=1
set +e
nvlog "END Add User to Docker Group"
}
build_container () {
nvlog "START Building Container - env:${ENVIRONMENT_NAME} => ${ENVIRONMENT_NAME}:${STACK_VERSION}"
TEMPDIR=$(mktemp -d)
nvlog "Run From: $RUNFROM"
nvlog "Temp Directory: $TEMPDIR"
cd $TEMPDIR
cp -a $RUNFROM/data-science-stack.Dockerfile $RUNFROM/README.md $TEMPDIR
cp -a $RUNFROM/environments/${ENVIRONMENT_NAME}-pinned.yaml $TEMPDIR/environment-pinned.yaml
ls -aFl
docker build \
--tag ${ENVIRONMENT_NAME}:${STACK_VERSION} \
-f ./data-science-stack.Dockerfile .
rm -r $TEMPDIR
nvlog "END Building Container"
nvlog "Next you can run: ${SCRIPT_NAME} run-container"
}
purge_container () {
nvlog "START Purge Container - env:${ENVIRONMENT_NAME} => ${ENVIRONMENT_NAME}:${STACK_VERSION}"
read -p "DANGER: Are you sure you want to remove container ${ENVIRONMENT_NAME}:${STACK_VERSION} [y/N]?" -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
nvlog "Removing container ${ENVIRONMENT_NAME}:${STACK_VERSION}"
CMD="docker rmi -f ${ENVIRONMENT_NAME}:${STACK_VERSION}"
nvlog "${CMD}"
${CMD}
else
nvlog "Aborting - no container deleted"
fi
nvlog "END Purge Container"
}
detect_conda () {
CONDA_VER=$(conda --version 2> /dev/null)
if [ $? -ne 0 ]; then
CONDA_VER=0
return
fi
CONDA_VER=$(echo "$CONDA_VER" | awk '{ print $2 }' 2> /dev/null)
CONDA_ROOT=$(dirname $(dirname $(which conda)))
}
install_miniconda () {
nvlog "START Install Miniconda"
nvlog "$CONDA_ROOT directory listing"
semver_gte $CONDA_VER $MIN_CONDA
if [ $? -eq 1 ]; then
nvlog "Conda is new enough"
nvlog "END Install Miniconda"
return
elif [ $CONDA_VER != 0 ]; then
nvlog
nvlog "ERROR: Conda is installed but older, please update conda environment"
nvlog "Try 'conda update -n base -c defaults conda'"
nvlog
exit 1
fi
if [ -d "${CONDA_ROOT}" ]; then
nvlog
nvlog "ERROR: Failed to detect Conda version but found a ${CONDA_ROOT} directory, please move/backup before install"
nvlog
exit 1
fi
set -e
mkdir -p ${HOME}/.conda
curl https://repo.anaconda.com/miniconda/Miniconda3-py310_$MIN_CONDA-Linux-x86_64.sh -o miniconda.sh
chmod +x miniconda.sh
/bin/bash ./miniconda.sh -bf -p ${CONDA_ROOT} # Use the existing Conda
rm -f ./miniconda.sh
echo "export PATH=${CONDA_ROOT}/bin:\$PATH # DATA-SCIENCE-STACK-ADDED" >> ${HOME}/.bashrc
source ${HOME}/.bashrc
${CONDA_ROOT}/bin/conda init bash
source ${HOME}/.bashrc
LOGOUT=1
set +e
nvlog "END Install Miniconda"
}
create_conda_env () {
nvlog "START Setup Conda Env - env:${ENVIRONMENT_NAME} => ${ENVIRONMENT_NAME}-${STACK_VERSION}"
if [ ! -f $RUNFROM/environments/${ENVIRONMENT_NAME}-pinned.yaml ]; then
nvlog "ERROR: unknown environment '${ENVIRONMENT_NAME}', try $0 list"
exit 1
fi
${CONDA_ROOT}/bin/conda env create -n ${ENVIRONMENT_NAME}-${STACK_VERSION} \
-f $RUNFROM/environments/${ENVIRONMENT_NAME}-pinned.yaml
sed -i '/DATA-SCIENCE-STACK-ADDED-ACT/d' ${HOME}/.bashrc
echo "conda activate ${ENVIRONMENT_NAME}-${STACK_VERSION} # DATA-SCIENCE-STACK-ADDED-ACT" >> ${HOME}/.bashrc
if [ -d ${HOME}/Desktop/ ]; then
cp $RUNFROM/README.md ${HOME}/Desktop/data-science-stack-README.md
fi
source ${CONDA_ROOT}/bin/activate ${ENVIRONMENT_NAME}-${STACK_VERSION} ; \
jupyter labextension install -y --clean \
@jupyter-widgets/jupyterlab-manager \
jupyter-threejs \
dask-labextension
nvlog "END Setup Conda Env"
nvlog "Next you can run: ${SCRIPT_NAME} run-jupyter"
}
purge_conda_env () {
nvlog "START Purge Conda Env - env:${ENVIRONMENT_NAME} => ${ENVIRONMENT_NAME}-${STACK_VERSION}"
read -p "DANGER: Are you sure you want to remove ${ENVIRONMENT_NAME}-${STACK_VERSION} [y/N]?" -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
nvlog "Removing Conda environment ${ENVIRONMENT_NAME}-${STACK_VERSION}"
sed -i '/DATA-SCIENCE-STACK-ADDED-ACT/d' ${HOME}/.bashrc
nvlog "${CONDA_ROOT}/bin/conda env remove -n ${ENVIRONMENT_NAME}-${STACK_VERSION}"
source ${CONDA_ROOT}/bin/deactivate ; \
${CONDA_ROOT}/bin/conda env remove -n ${ENVIRONMENT_NAME}-${STACK_VERSION}
LOGOUT=1
else
nvlog "Aborting - no files deleted"
fi
nvlog "END Purge Conda Env"
}
install_notebooks () {
nvlog "Start Install Notebooks"
set -e
nvlog "Installing Notebooks v${NOTEBOOKS_VERSION} to ${NOTEBOOKS_DIR}/"
if [ ! -d "${NOTEBOOKS_DIR}" ]; then
mkdir -p ${NOTEBOOKS_DIR}
else
if [ -d "${NOTEBOOKS_DIR}/notebooks" ]; then
rm -rf ${NOTEBOOKS_DIR}/notebooks
fi
fi
cd ${NOTEBOOKS_DIR}
git clone --single-branch --depth 1 --branch branch-${NOTEBOOKS_VERSION} \
https://github.com/rapidsai/notebooks.git
cd notebooks
git submodule update --init --remote
rm -rf .git
rm -rf `find repos/ -maxdepth 2 -mindepth 2 | grep -v notebooks`
set +e
nvlog "END Install Notebooks"
}
purge_conda () {
nvlog "START Remove Conda"
read -p "DANGER: Are you sure you want to remove ALL of Conda and ALL \
of NVIDIA Data Science Stack ( ${NOTEBOOKS_DIR} \
${HOME}/conda ${HOME}/.conda ) [y/N]?" -r
if [[ $REPLY =~ ^[Yy]$ ]]; then
nvlog "Removing Conda and Notebook files"
if [ -f ${CONDA_ROOT}/bin/conda ]; then
${CONDA_ROOT}/bin/conda init --reverse
fi
rm -rf ${NOTEBOOKS_DIR}
rm -rf ${HOME}/conda
rm -rf ${HOME}/.conda
nvlog "Saving ${HOME}/.bashrc to ${HOME}/.bashrc.bak"
cp ${HOME}/.bashrc ${HOME}/.bashrc.bak
sed -i '/DATA-SCIENCE-STACK-ADDED/d' ${HOME}/.bashrc
LOGOUT=1
else
nvlog "Aborting - no files deleted"
fi
nvlog "END Remove Conda"
}
diagnostics () {
nvlog "START Diagnostics"
nvlog "Run as: $USER"
nvlog "WSL: $WSL"
nvlog "OS Flavor: $OS_FLAVOR"
nvlog "OS Release: $OS_RELEASE"
if [ -f /usr/bin/lsb_release ]; then
nvlog "lsb_release:"
/usr/bin/lsb_release -r -d
fi
if [ -f /bin/uname ]; then
nvlog "uname -a"
/bin/uname -a
fi
nvlog "Storage (non-tmpfs, non-loopback)"
df -h | grep -v dev/loop | grep -v tmpfs
nvlog "Network test"
ping -c 1 -W 3 8.8.8.8
nvlog "Driver detected (0 means not installed): $DRIVER_VER"
if [ "$WSL" = false ]
then
nvlog "NVIDIA SMI:"
if [ -f /usr/bin/nvidia-smi ]; then
/usr/bin/nvidia-smi
else
echo "nvidia-smi not found, NVIDIA GPU Driver not installed correctly."
fi
fi
nvlog "CUDA detected (0 means not installed): $CUDA_VER"
nvlog "Docker detected (0 means not installed): $DOCKER_VER"
nvlog "Shared libraries:"
ldconfig -p | grep 'nvidia\|libnv\|cuda\|libcu'
nvlog "Notebooks directory: $NOTEBOOKS_DIR"
nvlog "Conda detected (0 means not installed): $CONDA_VER"
nvlog "Target Conda root: $CONDA_ROOT"
semver_gte $CONDA_VER $MIN_CONDA
if [ $? -eq 1 ]; then
nvlog "Conda packages:"
conda list
fi
nvlog "END Diagnostics"
}
notify_reboot () {
nvlog
nvlog
nvlog "ACTION REQUIRED:"
nvlog "For the changes to take effect, reboot the machine."
nvlog
nvlog "Current working directory: `pwd`/"
nvlog "data-science-stack script: ${RUNFROM}/${SCRIPT_NAME}"
nvlog
nvlog
}
get_latest_dss_version() {
TEMPFILE=$(mktemp)
curl --silent -o $TEMPFILE "https://api.github.com/repos/NVIDIA/data-science-stack/releases/latest"
local GH_LATEST=$(cat $TEMPFILE | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
rm -f $TEMPFILE
echo "$GH_LATEST"
}
upgrade() {
lv=$(get_latest_dss_version)
if [[ "$lv" == v* ]]; then
lv=`echo $lv | cut -d 'v' -f2`
cv=${STACK_VERSION}
nvlog "local version: ${cv}, latest vesion: ${lv}"
semver_gte $cv $lv
if [ $? -eq 1 ]; then
nvlog "already at the latest version"
return
fi
nvlog "UPGRADE upgrading to version ${lv}"
do_upgrade
else
nvlog "could not determine the latest data science stack version"
return
fi
}
do_upgrade() {
nvlog "UPGRADE starting"
ENVIRONMENT_NAME=${DEFAULT_ENVIRONMENT}
# remove the default docker container image if it exists
if [ $DOCKER_VER != 0 ]; then
purge_container
fi
# remove the default conda env if it exists
if [ $CONDA_VER != 0 ]; then
purge_conda_env
fi
# We don't completely wipe the system here, we just install the new script[s]
# While this may lack rigor, it also should save time
# back up the current (old) version of the stack
mv ${HOME}/data-science-stack ${HOME}/data-science-stack-backup-${STACK_VERSION}
cd ${HOME}
# install the new version
git clone https://github.com/NVIDIA/data-science-stack.git
cd ${HOME}/data-science-stack
bash ./data-science-stack setup-system
cd ${HOME}
nvlog "UPGRADE done, please log out and log in"
}
notify_logout () {
nvlog
nvlog
nvlog "ACTION REQUIRED:"
nvlog "For the changes to take effect, please logout and login back in."
nvlog
nvlog "Current working directory: `pwd`/"
nvlog "data-science-stack script: ${RUNFROM}/${SCRIPT_NAME}"
nvlog
nvlog
}
NOTEBOOK_OVERRIDE_CODE="
def my_run_line_magic(*args, **kwargs):
g=globals()
l={}
for a in args:
try:
exec(str(a),g,l)
except Exception as e:
print('WARNING: %s\n While executing this magic function code:\n%s\n continuing...\n' % (e, a))
else:
g.update(l)
def my_run_cell_magic(*args, **kwargs):
my_run_line_magic(*args, **kwargs)
get_ipython().run_line_magic=my_run_line_magic
get_ipython().run_cell_magic=my_run_cell_magic
"
run_notebook () {
nvlog "START running $1"
NBFILENAME=$(basename $1)
NBNAME=${NBFILENAME%.*}
NBNAME=${NBNAME##*/}
NBTESTSCRIPT=/tmp/${NBNAME}-test.py
TEMPFILE=$(mktemp)
pushd $(dirname $1)
jupyter nbconvert --to script ${NBFILENAME} --output /tmp/${NBNAME}-test
echo "${NOTEBOOK_OVERRIDE_CODE}" > ${TEMPFILE}
cat ${NBTESTSCRIPT} >> ${TEMPFILE}
mv ${TEMPFILE} ${NBTESTSCRIPT}
nvlog "Running \"ipython --colors=NoColor ${NBTESTSCRIPT}\" on $(date)"
time ipython --colors=NoColor ${NBTESTSCRIPT}
NBEXITCODE=$?
nvlog "EXIT CODE: ${NBEXITCODE}"
rm -f $TEMPFILE
rm -f $NBTESTSCRIPT
popd
nvlog "END running $1"
}
install_kubernetes() {
nvlog "START Kubernetes install with kubeadm"
if [ $OS_FLAVOR != "ubuntu" ]; then
nvlog "ERROR: Automated Kubernetes install for Red Hat not supported."
exit 1
fi
set -e
sudo apt-get update && sudo apt-get install -y apt-transport-https curl
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list
sudo apt-get update
sudo apt-get install -y kubelet kubeadm kubectl
sudo apt-mark hold kubelet kubeadm kubectl
# Init cluster w/Flannel
nvlog "NOTE: disabling swap (paging to disk)"
sudo swapoff -a
sudo kubeadm init --pod-network-cidr 10.244.0.0/16
# Setup credentials for user
mkdir -p $HOME/.kube
sudo cp /etc/kubernetes/admin.conf $HOME/.kube/config
sudo chown -R $(id -u):$(id -g) $HOME/.kube/
# Allow scheduling on master node since there is only one node
kubectl taint nodes --all node-role.kubernetes.io/master-
# Flannel
sudo sysctl net.bridge.bridge-nf-call-iptables=1
kubectl apply -f \
https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml
# NVIDIA Device Plugin
kubectl create -f \
https://raw.githubusercontent.com/NVIDIA/k8s-device-plugin/master/nvidia-device-plugin.yml
# Smoke test
sleep 5
nvlog
nvlog
nvlog "Kubernetes cluster will take some time to pull images and start"
nvlog "but here is what's running so far (from 'kubectl get all --all-namespaces')"
nvlog
nvlog
kubectl get all --all-namespaces
set +e
nvlog "END Kubernetes install with kubeadm"
}
install_jupyter-repo2docker() {
nvlog "START jupyter-repo2docker install"
if [ $OS_FLAVOR = "ubuntu" ]; then
sudo apt install -y python3-pip
pip3 install jupyter-repo2docker
else #RHEL
sudo yum install -y python3-pip
pip3 install jupyter-repo2docker
fi
nvlog "END jupyter-repo2docker install"
}
purge_jupyter-repo2docker() {
nvlog "START jupyter-repo2docker purge"
# let us not remove python-pip as it may be used for other things in the future
if [ $OS_FLAVOR = "ubuntu" ]; then
pip3 uninstall -y jupyter-repo2docker
else #RHEL
pip3 uninstall -y jupyter-repo2docker
fi
nvlog "END jupyter-repo2docker purge"
}
install_ngc_cli() {
nvlog "START NGC CLI install"
if [ ! -d "${HOME}/.local/bin" ]
then
mkdir -p "${HOME}/.local/bin"
fi
pushd "${HOME}/.local/bin"
wget -O ngccli_cat_linux.zip https://ngc.nvidia.com/downloads/ngccli_cat_linux.zip && unzip -o ngccli_cat_linux.zip && chmod u+x ngc && rm ngccli_cat_linux.zip
popd
nvlog "END NCG CLI install. Please use 'ngc config set' to start using the cli"
}
purge_ngc_cli() {
nvlog "START NGC CLI purge"
if [ -f "${HOME}/.local/bin/ngc" ]
then
rm "${HOME}/.local/bin/ngc"
nvlog "NGC CLI purged"
fi
nvlog "END NGC CLI purge."
}
install_kaggle_cli() {