rwightman HF staff commited on
Commit
0da5cb0
·
verified ·
1 Parent(s): b560dc1

Upload folder using huggingface_hub

Browse files
Files changed (10) hide show
  1. Dockerfile +138 -0
  2. README.md +11 -8
  3. login.html +72 -0
  4. on_build.sh +2 -0
  5. overrides.json +8 -0
  6. packages.txt +0 -0
  7. requirements.txt +9 -0
  8. setup_timm_dev +11 -0
  9. setup_timm_scripts +8 -0
  10. start_server.sh +19 -0
Dockerfile ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM nvidia/cuda:12.5.1-cudnn-devel-ubuntu22.04
2
+
3
+ ARG TIMEZONE=America/Vancouver
4
+
5
+ # Set environment variables
6
+ ENV DEBIAN_FRONTEND=noninteractive \
7
+ TZ=${TIMEZONE} \
8
+ CONDA_AUTO_UPDATE_CONDA=false \
9
+ PYTHONUNBUFFERED=1 \
10
+ GRADIO_ALLOW_FLAGGING=never \
11
+ GRADIO_NUM_PORTS=1 \
12
+ GRADIO_SERVER_NAME=0.0.0.0 \
13
+ GRADIO_THEME=huggingface \
14
+ SYSTEM=spaces \
15
+ SHELL=/bin/bash
16
+
17
+ # Remove any third-party apt sources to avoid issues with expiring keys.
18
+ # Install apt-packages
19
+ RUN rm -f /etc/apt/sources.list.d/*.list && \
20
+ apt-get update && apt-get install -y --no-install-recommends \
21
+ tzdata \
22
+ curl \
23
+ ca-certificates \
24
+ sudo \
25
+ git \
26
+ wget \
27
+ procps \
28
+ git-lfs \
29
+ zip \
30
+ unzip \
31
+ htop \
32
+ vim \
33
+ nano \
34
+ bzip2 \
35
+ libx11-6 \
36
+ build-essential \
37
+ libsndfile-dev \
38
+ software-properties-common \
39
+ jq \
40
+ tree \
41
+ libjpeg-turbo8-dev \
42
+ zlib1g-dev \
43
+ libtiff5-dev \
44
+ liblcms2-dev \
45
+ libfreetype6-dev \
46
+ libwebp-dev \
47
+ libharfbuzz-dev \
48
+ libfribidi-dev \
49
+ libopenjp2-7-dev \
50
+ libraqm0 \
51
+ && rm -rf /var/lib/apt/lists/*
52
+
53
+ # Add sources & install nvtop & node
54
+ RUN add-apt-repository ppa:flexiondotorg/nvtop && \
55
+ curl -sL https://deb.nodesource.com/setup_21.x | bash - && \
56
+ apt-get update && apt-get install -y --no-install-recommends \
57
+ nvtop \
58
+ nodejs \
59
+ && npm install -g configurable-http-proxy \
60
+ && rm -rf /var/lib/apt/lists/*
61
+
62
+ # Create a non-root user and switch to it
63
+ RUN adduser --disabled-password --gecos '' --shell /bin/bash user
64
+ RUN echo "user ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-user
65
+ USER user
66
+
67
+ # All users can use /home/user as their home directory
68
+ ENV HOME=/home/user
69
+ RUN mkdir $HOME/.cache $HOME/.config $HOME/app $HOME/bin \
70
+ && chmod -R 775 $HOME
71
+ ENV PATH=$HOME/bin:$PATH
72
+
73
+ # Switch to user for conda installation
74
+ USER user
75
+
76
+ WORKDIR $HOME
77
+
78
+ # Install Miniconda
79
+ ARG CONDA_URL=https://repo.anaconda.com/miniconda/Miniconda3-py312_24.11.1-0-Linux-x86_64.sh
80
+ ENV PATH=$HOME/miniconda/bin:$PATH
81
+ RUN curl -sLo ~/miniconda.sh ${CONDA_URL} && \
82
+ chmod +x ~/miniconda.sh && \
83
+ ~/miniconda.sh -b -p ~/miniconda && \
84
+ rm ~/miniconda.sh && \
85
+ conda clean -ya
86
+
87
+ # base python packages
88
+ RUN pip install --no-cache-dir --upgrade \
89
+ jupyterlab==4.3.4 \
90
+ tornado==6.4.2 \
91
+ ipywidgets
92
+
93
+ # Copy some context we need now / later into app folder
94
+ COPY 'packages.txt' 'requirements.txt' 'login.html' 'on_build.sh' 'start_server.sh' $HOME/app/
95
+ COPY 'setup_timm_dev' 'setup_timm_scripts' $HOME/bin/
96
+
97
+ #######################################
98
+ # Start root user section
99
+ #######################################
100
+ USER root
101
+
102
+ # User Debian packages
103
+ ## Security warning : Potential user code executed as root (build time)
104
+ RUN apt-get update && \
105
+ xargs -r -a $HOME/app/packages.txt apt-get install -y --no-install-recommends && \
106
+ rm -rf /var/lib/apt/lists/*
107
+
108
+ # Instead of using $HOME/app as our default, let's have files relative to our workspace in /data
109
+ # This way it will be persisent if a persistent drive is mapped to /data
110
+ WORKDIR /data
111
+ RUN mkdir /data/.cache
112
+ RUN chown -R user:user /data
113
+ ENV HF_HOME=/data/.cache/huggingface
114
+ RUN chmod +x $HOME/app/start_server.sh
115
+ #######################################
116
+ # End root user section
117
+ #######################################
118
+ USER user
119
+
120
+ # Python packages in packages.txt
121
+ RUN pip install --no-cache-dir --upgrade -r $HOME/app/requirements.txt
122
+
123
+ # Run extra steps to build environment via on_build.sh script
124
+ RUN bash $HOME/app/on_build.sh
125
+
126
+ # Apply overrides to Juptyer default settings
127
+ RUN mkdir -p $HOME/miniconda/share/jupyter/lab/settings/
128
+ COPY overrides.json $HOME/miniconda/share/jupyter/lab/settings/
129
+
130
+ # Update login page template
131
+ RUN SITE_PACKAGES=$(python -c "import site; print(site.getsitepackages()[0])") \
132
+ && mv $HOME/app/login.html "$SITE_PACKAGES/jupyter_server/templates/login.html"
133
+
134
+ # Remove Pillow and install faster Pillow-SIMD (big impact for limited CPU)
135
+ RUN pip uninstall -y pillow && \
136
+ CC="cc -mavx2" pip install -U --force-reinstall --no-cache-dir pillow-simd
137
+
138
+ CMD ["/home/user/app/start_server.sh"]
README.md CHANGED
@@ -1,12 +1,15 @@
1
  ---
2
- title: Jupyterlab Timm Dev
3
- emoji: 😻
4
- colorFrom: blue
5
- colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 5.12.0
8
- app_file: app.py
9
  pinned: false
 
 
 
 
 
10
  ---
11
 
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: JupyterLab (timm)
3
+ emoji: 💻🐳
4
+ colorFrom: gray
5
+ colorTo: green
6
+ sdk: docker
 
 
7
  pinned: false
8
+ tags:
9
+ - jupyterlab
10
+ - timm
11
+ suggested_storage: small
12
+ short_description: Improved JuptyerLab template w/ timm
13
  ---
14
 
15
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
login.html ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {% extends "page.html" %}
2
+
3
+
4
+ {% block stylesheet %}
5
+ {% endblock %}
6
+
7
+ {% block site %}
8
+
9
+ <div id="jupyter-main-app" class="container">
10
+
11
+ <img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="Hugging Face Logo">
12
+ <h4>Welcome to JupyterLab</h4>
13
+
14
+ <h5>The default token is <span style="color:orange;">huggingface</span></h5>
15
+
16
+ {% if login_available %}
17
+ {# login_available means password-login is allowed. Show the form. #}
18
+ <div class="row">
19
+ <div class="navbar col-sm-8">
20
+ <div class="navbar-inner">
21
+ <div class="container">
22
+ <div class="center-nav">
23
+ <form action="{{base_url}}login?next={{next}}" method="post" class="navbar-form pull-left">
24
+ {{ xsrf_form_html() | safe }}
25
+ {% if token_available %}
26
+ <label for="password_input"><strong>{% trans %}Jupyter token <span title="This is the secret you set up when deploying your JupyterLab space">ⓘ</span> {% endtrans
27
+ %}</strong></label>
28
+ {% else %}
29
+ <label for="password_input"><strong>{% trans %}Jupyter password:{% endtrans %}</strong></label>
30
+ {% endif %}
31
+ <input type="password" name="password" id="password_input" class="form-control">
32
+ <button type="submit" class="btn btn-default" id="login_submit">{% trans %}Log in{% endtrans
33
+ %}</button>
34
+ </form>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ {% else %}
41
+ <p>{% trans %}No login available, you shouldn't be seeing this page.{% endtrans %}</p>
42
+ {% endif %}
43
+
44
+ <h5>If you don't have the credentials for this Jupyter space, <a target="_blank" href="https://huggingface.co/spaces/timm/jupyterlab-timm?duplicate=true">create your own.</a></h5>
45
+ <br>
46
+
47
+ <p>This is an updated version of the JuptyerLab Spaces template tuned for timm usage. Modified by <a href="https://twitter.com/wightmanr" target="_blank" >Ross Wightman</a> </p>
48
+
49
+ <br>
50
+
51
+ <p>The original template was created by <a href="https://twitter.com/camenduru" target="_blank" >camenduru</a> and <a href="https://huggingface.co/nateraw" target="_blank" >nateraw</a>, with contributions from <a href="https://huggingface.co/osanseviero" target="_blank" >osanseviero</a> and <a href="https://huggingface.co/azzr" target="_blank" >azzr</a> </p>
52
+ {% if message %}
53
+ <div class="row">
54
+ {% for key in message %}
55
+ <div class="message {{key}}">
56
+ {{message[key]}}
57
+ </div>
58
+ {% endfor %}
59
+ </div>
60
+ {% endif %}
61
+ {% if token_available %}
62
+ {% block token_message %}
63
+
64
+ {% endblock token_message %}
65
+ {% endif %}
66
+ </div>
67
+
68
+ {% endblock %}
69
+
70
+
71
+ {% block script %}
72
+ {% endblock %}
on_build.sh ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ #!/bin/bash
2
+ # Write some commands here that will run as user while building Space.
overrides.json ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "@jupyterlab/apputils-extension:themes": {
3
+ "theme": "JupyterLab Dark"
4
+ },
5
+ "@jupyterlab/terminal-extension:plugin": {
6
+ "theme": "dark"
7
+ }
8
+ }
packages.txt ADDED
File without changes
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ torchvision
3
+ torchaudio
4
+ wandb
5
+ datasets
6
+ webdataset==0.2.86
7
+ hf-transfer
8
+ transformers
9
+ timm
setup_timm_dev ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ git clone https://github.com/huggingface/pytorch-image-models.git
3
+
4
+ ln -s pytorch-image-models/train.py train.py
5
+ ln -s pytorch-image-models/validate.py validate.py
6
+ ln -s pytorch-image-models/inference.py inference.py
7
+ ln -s pytorch-image-models/benchmark.py benchmark.py
8
+ ln -s pytorch-image-models/distributed_train.sh distributed_train.sh
9
+
10
+ # NOTE important to use no-deps to install editable timm, otherwise will stomp over Pillow-SIMD
11
+ cd pytorch-image-models && pip install --no-deps -e .
setup_timm_scripts ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ TIMM_TAG=$(curl -s https://api.github.com/repos/huggingface/pytorch-image-models/releases/latest | jq -r '.tag_name')
3
+
4
+ for file in train.py validate.py inference.py benchmark.py distributed_train.sh; do \
5
+ curl -sLO "https://raw.githubusercontent.com/huggingface/pytorch-image-models/${TIMM_TAG}/${file}"; \
6
+ done
7
+
8
+ chmod +x distributed_train.sh
start_server.sh ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ JUPYTER_TOKEN="${JUPYTER_TOKEN:=huggingface}"
3
+
4
+ NOTEBOOK_DIR="/data"
5
+
6
+ jupyter labextension disable "@jupyterlab/apputils-extension:announcements"
7
+
8
+ jupyter-lab \
9
+ --ip 0.0.0.0 \
10
+ --port 7860 \
11
+ --no-browser \
12
+ --allow-root \
13
+ --ServerApp.token="$JUPYTER_TOKEN" \
14
+ --ServerApp.tornado_settings="{'headers': {'Content-Security-Policy': 'frame-ancestors *'}}" \
15
+ --ServerApp.cookie_options="{'SameSite': 'None', 'Secure': True}" \
16
+ --ServerApp.disable_check_xsrf=True \
17
+ --LabApp.news_url=None \
18
+ --LabApp.check_for_updates_class="jupyterlab.NeverCheckForUpdate" \
19
+ --notebook-dir=$NOTEBOOK_DIR