Skip to content

Commit fe8ba0a

Browse files
authored
[DIST] Support hybrid parallelism using embedding_lookup_* API
1 parent 7f5ddb3 commit fe8ba0a

94 files changed

Lines changed: 5394 additions & 1184 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ HYBRIDBACKEND_CONFIG=$(wildcard .config.mk)
66
include $(HYBRIDBACKEND_CONFIG)
77

88
HYBRIDBACKEND_WITH_CUDA ?= ON
9-
HYBRIDBACKEND_WITH_CUDA_GENCODE ?= "70 75 80 86"
9+
HYBRIDBACKEND_WITH_CUDA_GENCODE ?= 70 75 80 86
1010
HYBRIDBACKEND_WITH_NVTX ?= ON
1111
HYBRIDBACKEND_WITH_NCCL ?= ON
1212
HYBRIDBACKEND_WITH_ARROW ?= ON
@@ -20,9 +20,9 @@ HYBRIDBACKEND_WITH_TENSORFLOW_HALF ?= ON
2020
HYBRIDBACKEND_WITH_BUILDINFO ?= ON
2121
HYBRIDBACKEND_USE_CXX11_ABI ?= 0
2222
HYBRIDBACKEND_DEBUG ?= OFF
23-
HYBRIDBACKEND_WHEEL_ALIAS ?= ""
24-
HYBRIDBACKEND_WHEEL_BUILD ?= ""
25-
HYBRIDBACKEND_WHEEL_REQUIRES ?= ""
23+
HYBRIDBACKEND_WHEEL_ALIAS ?=
24+
HYBRIDBACKEND_WHEEL_BUILD ?=
25+
HYBRIDBACKEND_WHEEL_REQUIRES ?=
2626
HYBRIDBACKEND_WHEEL_DEBUG ?= OFF
2727
HYBRIDBACKEND_CHECK_INSTANCE ?= OFF
2828

@@ -70,36 +70,29 @@ HYBRIDBACKEND_BUILD_VERSION := $(shell \
7070
grep __version__ hybridbackend/__init__.py | cut -d\' -f2 \
7171
2>/dev/null)
7272
HYBRIDBACKEND_BUILD_COMMIT := $(shell git rev-parse HEAD 2>/dev/null)
73-
HYBRIDBACKEND_BUILD_GLIBC := $(shell \
74-
ldd --version | head -1 | rev | cut -d' ' -f1 | rev 2>/dev/null)
7573
HYBRIDBACKEND_BUILD_CXX := $(shell \
76-
$(CXX) --version | head -1 | rev | cut -d ' ' -f1 | rev \
74+
$(CXX) --version | head -1 | rev | cut -d ' ' -f1,4 | rev \
7775
2>/dev/null)
7876

7977
CFLAGS := $(CFLAGS) \
8078
-DHYBRIDBACKEND_BUILDINFO=1 \
8179
-DHYBRIDBACKEND_BUILD_VERSION="\"$(HYBRIDBACKEND_BUILD_VERSION)\"" \
8280
-DHYBRIDBACKEND_BUILD_COMMIT="\"$(HYBRIDBACKEND_BUILD_COMMIT)\"" \
83-
-DHYBRIDBACKEND_BUILD_GLIBC="\"$(HYBRIDBACKEND_BUILD_GLIBC)\"" \
8481
-DHYBRIDBACKEND_BUILD_CXX="\"$(HYBRIDBACKEND_BUILD_CXX)\"" \
85-
-DHYBRIDBACKEND_BUILD_CXX11_ABI="\"$(HYBRIDBACKEND_USE_CXX11_ABI)\""
82+
-DHYBRIDBACKEND_BUILD_CXX11_ABI=$(HYBRIDBACKEND_USE_CXX11_ABI)
8683
endif
8784

8885
ifeq ($(HYBRIDBACKEND_WITH_CUDA),ON)
8986
NVCC ?= nvcc
9087
CUDA_HOME ?= /usr/local
9188
HYBRIDBACKEND_CUDA_GENCODE := $(shell \
92-
echo $(HYBRIDBACKEND_WITH_CUDA_GENCODE) | tr ' ' ',' \
93-
2>/dev/null)
94-
HYBRIDBACKEND_CUDA_CC := $(shell \
95-
$(NVCC) --version | tail -1 | cut -d' ' -f2 \
89+
echo "$(HYBRIDBACKEND_WITH_CUDA_GENCODE)" | tr ' ' ',' \
9690
2>/dev/null)
9791
CFLAGS := $(CFLAGS) \
9892
-isystem $(CUDA_HOME) \
9993
-isystem $(CUDA_HOME)/cuda/include \
10094
-DHYBRIDBACKEND_CUDA=1 \
101-
-DHYBRIDBACKEND_CUDA_GENCODE="\"$(HYBRIDBACKEND_CUDA_GENCODE)\"" \
102-
-DHYBRIDBACKEND_CUDA_CC="\"$(HYBRIDBACKEND_CUDA_CC)\""
95+
-DHYBRIDBACKEND_CUDA_GENCODE="\"$(HYBRIDBACKEND_CUDA_GENCODE)\""
10396
NVCC_CFLAGS := --std=c++11 \
10497
-lineinfo \
10598
--expt-relaxed-constexpr \

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import tensorflow as tf
2727
import hybridbackend.tensorflow as hb
2828

2929
ds = hb.data.ParquetDataset(filenames, batch_size=batch_size)
30-
ds = ds.apply(hb.data.to_sparse())
30+
ds = ds.apply(hb.data.parse())
3131
# ...
3232

3333
with tf.device('/gpu:0'):
@@ -78,7 +78,7 @@ if your organization is interested in adoption. We will discuss
7878
[RoadMap](https://github.com/alibaba/HybridBackend/blob/main/ROADMAP.md) with
7979
registered adopters in advance.
8080

81-
- Please cite HybridBackend in your publications if it helps:
81+
- Please cite [HybridBackend](https://ieeexplore.ieee.org/document/9835450) in your publications if it helps:
8282

8383
```text
8484
@inproceedings{zhang2022picasso,

docs/advanced.md

Lines changed: 0 additions & 134 deletions
This file was deleted.

docs/data.md

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ ds = hb.data.ParquetDataset(
9494
batch_size=1024,
9595
fields=['a', 'c'])
9696
# Convert results to sparse tensors.
97-
ds = ds.apply(hb.data.to_sparse())
97+
ds = ds.apply(hb.data.parse())
9898
ds = ds.prefetch(4)
9999
it = tf.data.make_one_shot_iterator(ds)
100100
batch = it.get_next()
@@ -118,11 +118,61 @@ ds = filenames.apply(hb.data.read_parquet(1024, fields=fields))
118118
ds = ds.prefetch(4)
119119
it = tf.data.make_one_shot_iterator(ds)
120120
batch = it.get_next()
121-
# {'a': tensora, 'c': tensorc}
121+
# {'A': scalar_tensor, 'C': sparse_tensor}
122122
...
123123
```
124124

125-
### 2.6 Benchmark
125+
### 2.6 Example: Parse to tensors and sparse tensors
126+
127+
```python
128+
import tensorflow as tf
129+
import hybridbackend.tensorflow as hb
130+
131+
# Define data frame fields.
132+
fields = [
133+
hb.data.DataFrame.Field('A', tf.int64), # scalar
134+
hb.data.DataFrame.Field('B', tf.int64, shape=[32]), # fixed-length list
135+
hb.data.DataFrame.Field('C', tf.int64, ragged_rank=1), # variable-length list
136+
hb.data.DataFrame.Field('D', tf.int64, ragged_rank=1)] # variable-length list
137+
# Read from parquet files by reading upstream filename dataset.
138+
ds = hb.data.ParquetDataset(
139+
'/path/to/f1.parquet',
140+
fields=fields,
141+
batch_size=1024)
142+
ds = ds.apply(hb.data.parse(pad={'D': True}))
143+
ds = ds.prefetch(4)
144+
it = tf.data.make_one_shot_iterator(ds)
145+
batch = it.get_next()
146+
# {'A': scalar_tensor, 'B': list_tensor, 'C': sparse_tensor, 'D': padded_list_tensor}
147+
...
148+
```
149+
150+
### 2.7 Example: Remove dataset ops in exported saved model
151+
152+
```python
153+
import tensorflow as tf
154+
from tensorflow.tools.graph_transforms import TransformGraph
155+
import hybridbackend.tensorflow as hb
156+
157+
# ...
158+
model_inputs = {t.name.split(":")[0]: t for t in model.inputs}
159+
model_outputs = {t.name.split(":")[0]: t for t in model.outputs}
160+
train_graph_def = tf.get_default_graph().as_graph_def()
161+
predict_graph_def = TransformGraph(
162+
train_graph_def,
163+
list(model_inputs.keys()),
164+
list(model_outputs.keys()),
165+
['strip_unused_nodes'])
166+
with tf.Graph().as_default() as predict_graph:
167+
tf.import_graph_def(predict_graph_def, name='')
168+
with tf.Session(graph=predict_graph) as predict_sess:
169+
tf.saved_model.simple_save(
170+
predict_sess, export_dir,
171+
inputs=model_inputs,
172+
outputs=model_outputs)
173+
```
174+
175+
### 2.8 Benchmark
126176

127177
In benchmark for reading 20k samples from 200 columns of a Parquet file,
128178
`hb.data.ParquetDataset` is about **21.51x faster** than
@@ -145,7 +195,7 @@ Parquet (SNAPPY) | 3346.10 | HybridBackend | 20 | 21.67
145195
Set `MALLOC_CONF` to `"background_thread:true,metadata_thp:auto"` to speed
146196
up memory access.
147197
.. note::
148-
Set `ARROW_NUM_THREADS` to read different columns in parallel.
198+
Set `ARROW_NUM_THREADS` to parse different columns in parallel.
149199
```
150200

151201
## 3. Data Pipeline Functions
@@ -155,7 +205,7 @@ HybridBackend supports various data pipeline functions for common tasks.
155205
### 3.1 APIs
156206

157207
```{eval-rst}
158-
.. autofunction:: hybridbackend.tensorflow.data.to_sparse
208+
.. autofunction:: hybridbackend.tensorflow.data.parse
159209
.. autofunction:: hybridbackend.tensorflow.data.rebatch
160210
```
161211

@@ -171,7 +221,7 @@ ds = hb.data.ParquetDataset(
171221
batch_size=1024,
172222
fields=['a', 'c'])
173223
# Convert results to sparse tensors.
174-
ds = ds.apply(hb.data.to_sparse())
224+
ds = ds.apply(hb.data.parse())
175225
ds = ds.prefetch(4)
176226
it = tf.data.make_one_shot_iterator(ds)
177227
batch = it.get_next()
@@ -196,7 +246,7 @@ ds = ds.shuffle(2048 // 256)
196246
# Change batch size to 1024.
197247
ds = ds.apply(hb.data.rebatch(1024, fields=fields))
198248
# Convert results to sparse tensors.
199-
ds = ds.apply(hb.data.to_sparse())
249+
ds = ds.apply(hb.data.parse())
200250
ds = ds.prefetch(4)
201251
it = tf.data.make_one_shot_iterator(ds)
202252
batch = it.get_next()

0 commit comments

Comments
 (0)