FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge branch 'master' into bigquery · feibyte/docker-python@ddf0170 · GitHub

Commit ddf0170

Browse files
committed
Merge branch 'master' into bigquery
2 parents 9e15f68 + ce9a9fe commit ddf0170

9 files changed

Lines changed: 129 additions & 48 deletions

File tree

‎Dockerfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,8 @@ RUN pip install flashtext && \
473473
pip install ggplot && \
474474
pip install cesium && \
475475
pip install rgf_python && \
476+
pip install pytext-nlp && \
477+
pip install tsfresh && \
476478
/tmp/clean-layer.sh
477479

478480
# Pin Vowpal Wabbit v8.6.0 because 8.6.1 does not build or install successfully

‎Jenkinsfile‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
String cron_string = BRANCH_NAME == "master" ? "H 12 * * 1-5" : ""
1+
String cron_string = BRANCH_NAME == "master" ? "H 12 * * 1,3" : ""
22

33
pipeline {
44
agent { label 'ephemeral-linux' }
@@ -29,14 +29,14 @@ pipeline {
2929
}
3030
}
3131

32-
stage('Push CPU Untested Image') {
32+
stage('Push CPU Pretest Image') {
3333
steps {
34-
slackSend color: 'none', message: "*<${env.BUILD_URL}console|${JOB_NAME} pushing untested image>* ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
34+
slackSend color: 'none', message: "*<${env.BUILD_URL}console|${JOB_NAME} pushing pretest image>* ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
3535
sh '''#!/bin/bash
3636
set -exo pipefail
3737
3838
date
39-
./push ci-untested
39+
./push ci-pretest
4040
'''
4141
}
4242
}
@@ -83,15 +83,15 @@ pipeline {
8383
}
8484
}
8585

86-
stage('Push GPU Untested Image') {
86+
stage('Push GPU Pretest Image') {
8787
agent { label 'ephemeral-linux-gpu' }
8888
steps {
89-
slackSend color: 'none', message: "*<${env.BUILD_URL}console|${JOB_NAME} pushing untested image>* ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
89+
slackSend color: 'none', message: "*<${env.BUILD_URL}console|${JOB_NAME} pushing pretest image>* ${GIT_COMMIT_SUMMARY}", channel: env.SLACK_CHANNEL
9090
sh '''#!/bin/bash
9191
set -exo pipefail
9292
9393
date
94-
./push --gpu ci-untested
94+
./push --gpu ci-pretest
9595
'''
9696
}
9797
}

‎README.md‎

Lines changed: 60 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,88 @@
1-
**Kaggle Kernels** allow users to run scripts against our competitions and datasets without having to download data or set up their environment. Here's [an example](https://www.kaggle.com/devinanzelmo/d/devinanzelmo/dota-2-matches/setting-up-a-prediction-problem-dota-2):
1+
[Kaggle Kernels](https://www.kaggle.com/kernels) allow users to run a Python Notebook in the cloud against our competitions and datasets without having to download data or set up their environment.
22

3-
![example script](http://i.imgur.com/yrWycNA.png)
3+
This repository includes our Dockerfiles for building the [CPU-only](Dockerfile) and [GPU](gpu.Dockerfile) image that runs Python Kernels on Kaggle.
44

5-
This is the Dockerfile (etc.) used for building the image that runs python scripts on Kaggle. [Here's](https://gcr.io/kaggle-images/python) the Docker image on Google Container Registry.
5+
Our Python Docker images are stored on Google Container Registry at:
6+
7+
* CPU-only: [gcr.io/kaggle-images/python](https://gcr.io/kaggle-images/python)
8+
* GPU: private for now, we will make it public soon.
9+
10+
Note: The base image for the GPU image is our CPU-only image. The [gpu.Dockerfile](gpu.Dockerfile) adds a few extra layers to install GPU related libraries and packages (cuda, libcudnn, pycuda etc.) and reinstall packages with specific GPU builds (torch, tensorflow and a few mores).
611

712
## Getting started
813

914
To get started with this image, read our [guide](http://blog.kaggle.com/2016/02/05/how-to-get-started-with-data-science-in-containers/) to using it yourself, or browse [Kaggle Kernels](https://www.kaggle.com/kernels) for ideas.
1015

11-
## Requesting new features
16+
## Requesting new packages
1217

13-
**We welcome pull requests** if there are any packages you'd like to add!
18+
First, evaluate whether installing the package yourself in your own Kernels suits your needs. See [guide](https://github.com/Kaggle/docker-python/wiki/Missing-Packages).
1419

15-
We can merge your request quickly if you check that it builds correctly. Here's how to do that.
20+
If you the first step above doesn't work for your use case, [open an issue](https://github.com/Kaggle/docker-python/issues/new) or a [pull request](https://github.com/Kaggle/docker-python/pulls).
1621

17-
Start by running this image on your system:
22+
## Opening a pull request
1823

19-
```
20-
me@my-computer:/home$ docker run --rm -it gcr.io/kaggle-images/python
21-
root@d72b81a003e1:/#
22-
```
24+
1. Update the *Dockerfile*
25+
1. For changes specific to the GPU image, update the [gpu.Dockerfile](gpu.Dockerfile).
26+
1. Otherwise, update the [Dockerfile](Dockerfile).
27+
1. Follow the instructions below to build a new image.
28+
1. Add tests for your new package. See this [example](https://github.com/Kaggle/docker-python/blob/master/tests/test_fastai.py).
29+
1. Follow the instructions below to test the new image.
30+
1. Open a PR on this repo and you are all set!
2331

24-
Then follow the package's installation instructions for a Linux system. It could be as simple as installing via Pip:
32+
## Building a new image
2533

26-
```
27-
root@d72b81a003e1:/# pip install coolpackage
28-
Collecting coolpackage
29-
[...etc...]
34+
```sh
35+
./build
3036
```
3137

32-
Once that's done, check that you can import it correctly. (Sometimes, if a package is missing a dependency, it throws an error when you try to import it.)
38+
Flags:
3339

34-
```
35-
root@d72b81a003e1:/# python
36-
Python 3.5.2 |Anaconda 4.2.0 (64-bit)| (default, Jul 2 2016, 17:53:06)
37-
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux
38-
Type "help", "copyright", "credits" or "license" for more information.
39-
>>> import coolpackage
40-
>>>
41-
```
40+
* `--gpu` to build an image for GPU.
41+
* `--use-cache` for faster iterative builds.
4242

43-
Once that's working, add the necessary lines to our [Dockerfile](https://github.com/Kaggle/docker-python/blob/master/Dockerfile). (In this case, that would mean adding `pip install coolpackage` to the last section.)
43+
## Testing a new image
4444

45-
Next run the build:
45+
A suite of tests can be found under the `/tests` folder. You can run the test using this command:
4646

47+
```sh
48+
./test
4749
```
48-
./build
49-
```
5050

51-
Finally run the tests:
51+
Flags:
52+
53+
* `--gpu` to test the GPU image.
54+
55+
## Running the image
5256

57+
For the CPU-only image:
58+
59+
```sh
60+
# Run the image built locally:
61+
docker run --rm -it kaggle/python-build /bin/bash
62+
# Run the pre-built image from gcr.io
63+
docker run --rm -it gcr.io/kaggle-images/python /bin/bash
5364
```
54-
./test
65+
66+
For the GPU image:
67+
68+
```sh
69+
# Run the image built locally:
70+
docker run --runtime nvidia --rm -it kaggle/python-gpu-build /bin/bash
71+
# Run the image pre-built image from gcr.io
72+
# TODO: Our GPU images are not yet publicly available.
5573
```
5674

57-
Then submit your pull request, and you're all set!
75+
To ensure your container can access the GPU, follow the instructions posted [here](https://github.com/Kaggle/docker-python/issues/361#issuecomment-448093930).
76+
77+
## Tensorflow custom pre-built wheel
78+
79+
A Tensorflow custom pre-built wheel is used mainly for:
80+
81+
* Faster build time: Building tensorflow from sources takes ~1h. Keeping this process outside the main build allows faster iterations when working on our Dockerfiles.
5882

83+
Building Tensorflow from sources:
5984

85+
* Increase performance: When building from sources, we can leverage CPU specific optimizations
86+
* Is required: Tensorflow with GPU support must be built from sources
6087

88+
The [Dockerfile](tensorflow-whl/Dockerfile) and the [instructions](tensorflow-whl/README.md) can be found in the [tensorflow-whl folder/](tensorflow-whl/).

‎gpu.Dockerfile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,6 @@ RUN pip uninstall -y tensorflow && \
5454

5555
# Install GPU-only packages
5656
RUN pip install pycuda && \
57+
pip install cupy-cuda92 && \
58+
pip install pynvrtc && \
5759
/tmp/clean-layer.sh

‎patches/sitecustomize.py‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# TODO(rosbo): Remove this once we fix the issue with fastai importing older libcudnn if imported prior to tensorflow
2-
import tensorflow
31
import os
42
from google.auth import credentials
53
from google.cloud import bigquery

‎tensorflow-whl/README.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
./build
55
```
66

7-
# Push the new wheels
7+
# Push the new wheels (Kaggle Engineers only)
88

99
1. Add an entry in the [CHANGELOG](CHANGELOG.md) with an appropriate `LABEL`.
1010
2. Push the new image using the `LABEL` you picked above.
@@ -17,6 +17,12 @@
1717
1818
Update the line below in the [CPU Dockerfile](../Dockerfile) and the [GPU Dockerfile](../gpu.Dockerfile) to use the new `LABEL`.
1919
20+
To use wheels built locally:
21+
```
22+
FROM kaggle/python-tensorflow-whl as tensorflow_whl
23+
```
24+
25+
To use our pre-built wheels:
2026
```
2127
FROM gcr.io/kaggle-images/python-tensorflow-whl:<LABEL> as tensorflow_whl
2228
```

‎test‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
#!/bin/bash
22
set -e
33

4+
IMAGE_TAG='kaggle/python-build'
5+
IMAGE_TAG_OVERRIDE=''
6+
ADDITONAL_OPTS=''
7+
PATTERN='test*.py'
8+
49
usage() {
510
cat << EOF
611
Usage: $0 [OPTIONS]
712
Run tests for a newly-built Python Docker image.
813
By default, it runs the tests for the CPU image.
914
1015
Options:
11-
-g, --gpu Run tests for the GPU image.
12-
-i, --image IMAGE Run tests against the specified image
16+
-g, --gpu Run tests for the GPU image.
17+
-i, --image IMAGE Run tests against the specified image
18+
-p, --pattern PATTERN Pattern to match test files ($PATTERN default)
1319
1420
EOF
1521
}
1622

17-
IMAGE_TAG='kaggle/python-build'
18-
ADDITONAL_OPTS=''
19-
2023
while :; do
2124
case "$1" in
2225
-h|--help)
@@ -36,6 +39,15 @@ while :; do
3639
IMAGE_TAG_OVERRIDE=$2
3740
shift # skip the flag value
3841
;;
42+
-p|--pattern)
43+
if [[ -z $2 ]]; then
44+
usage
45+
printf 'ERROR: No PATTERN specified after the %s flag.\n' "$1" >&2
46+
exit
47+
fi
48+
PATTERN="$2"
49+
shift # skip the flag value
50+
;;
3951
-?*)
4052
usage
4153
printf 'ERROR: Unknown option: %s\n' "$1" >&2
@@ -54,6 +66,7 @@ fi
5466

5567
readonly IMAGE_TAG
5668
readonly ADDITONAL_OPTS
69+
readonly PATTERN
5770

5871
set -x
5972
rm -rf /tmp/python-build
@@ -74,4 +87,4 @@ docker run --rm -t --read-only --net=none \
7487
-w=/working \
7588
$ADDITONAL_OPTS \
7689
"$IMAGE_TAG" \
77-
/bin/bash -c 'python -m unittest discover -s /input/tests'
90+
/bin/bash -c "python -m unittest discover -s /input/tests -p $PATTERN"

‎tests/test_pytext.py‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import unittest
2+
3+
from pytext.config.field_config import FeatureConfig
4+
from pytext.data.featurizer import InputRecord, SimpleFeaturizer
5+
6+
class TestPyText(unittest.TestCase):
7+
8+
def test_tokenize(self):
9+
featurizer = SimpleFeaturizer.from_config(
10+
SimpleFeaturizer.Config(), FeatureConfig()
11+
)
12+
13+
tokens = featurizer.featurize(InputRecord(raw_text="At eight o'clock")).tokens
14+
self.assertEqual(['at', 'eight', "o'clock"], tokens)

‎tests/test_tsfresh.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import unittest
2+
3+
import pandas as pd
4+
import numpy as np
5+
6+
from tsfresh import extract_features
7+
8+
class TestTsFresh(unittest.TestCase):
9+
def test_extract_feature(self):
10+
ts = pd.DataFrame({
11+
'id': np.array(['a', 'a', 'a', 'b', 'b', 'b']),
12+
'time': np.array([0,1,2,0,1,2]),
13+
'x': np.array([3,4,5,7,8,10])
14+
})
15+
extracted_features = extract_features(ts, column_id='id', column_sort='time')
16+
self.assertEqual(2, len(extracted_features))
17+
18+

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL