chugr 0.2.0.dev0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- chugr/__init__.py +46 -0
- chugr/app/test.py +105 -0
- chugr/common/__init__.py +9 -0
- chugr/common/cli.py +234 -0
- chugr/common/collate.py +104 -0
- chugr/common/config.py +335 -0
- chugr/common/random.py +76 -0
- chugr/common/serialize.py +150 -0
- chugr/common/task_config.py +24 -0
- chugr/common/types.py +122 -0
- chugr/common/urls.py +88 -0
- chugr/doc/__init__.py +17 -0
- chugr/doc/constants.py +15 -0
- chugr/doc/doc_processor.py +248 -0
- chugr/doc/doc_read_processor.py +249 -0
- chugr/doc/doc_vqa_processor.py +113 -0
- chugr/doc/synth_text.py +212 -0
- chugr/hfds/__init__.py +2 -0
- chugr/hfds/collate.py +83 -0
- chugr/hfds/loader.py +385 -0
- chugr/hfds/wrappers.py +108 -0
- chugr/image/__init__.py +4 -0
- chugr/image/build_transforms_doc.py +427 -0
- chugr/image/build_transforms_image.py +203 -0
- chugr/image/transforms_alb.py +112 -0
- chugr/image/transforms_factory.py +58 -0
- chugr/image/transforms_torch.py +137 -0
- chugr/loader.py +249 -0
- chugr/naflex.py +357 -0
- chugr/task_pipeline/__init__.py +7 -0
- chugr/task_pipeline/pipeline_doc_read.py +66 -0
- chugr/task_pipeline/pipeline_doc_vqa.py +124 -0
- chugr/task_pipeline/pipeline_factory.py +32 -0
- chugr/task_pipeline/pipeline_gtparse.py +93 -0
- chugr/task_pipeline/pipeline_image_text.py +90 -0
- chugr/task_pipeline/pipeline_manual.py +27 -0
- chugr/text/__init__.py +1 -0
- chugr/text/tokenization.py +222 -0
- chugr/version.py +1 -0
- chugr/wds/__init__.py +7 -0
- chugr/wds/dataset_info.py +65 -0
- chugr/wds/decode.py +319 -0
- chugr/wds/filters.py +142 -0
- chugr/wds/helpers.py +68 -0
- chugr/wds/loader.py +187 -0
- chugr/wds/pipeline.py +182 -0
- chugr/wds/shardlists.py +134 -0
- chugr/wds/tariterators.py +70 -0
- chugr-0.2.0.dev0.dist-info/METADATA +436 -0
- chugr-0.2.0.dev0.dist-info/RECORD +53 -0
- chugr-0.2.0.dev0.dist-info/WHEEL +4 -0
- chugr-0.2.0.dev0.dist-info/entry_points.txt +4 -0
- chugr-0.2.0.dev0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1,436 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chugr
|
|
3
|
+
Version: 0.2.0.dev0
|
|
4
|
+
Summary: Data pipelines for document and image-text training: webdataset and Hugging Face datasets, PDF decoding, NaFlex batching
|
|
5
|
+
Keywords: webdataset,datasets,data-loading,documents,pdf,pytorch
|
|
6
|
+
Author-Email: Ross Wightman <rwightman@gmail.com>
|
|
7
|
+
License-Expression: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Education
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
14
|
+
Classifier: Topic :: Scientific/Engineering
|
|
15
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Project-URL: homepage, https://github.com/rwightman/chugr
|
|
18
|
+
Project-URL: repository, https://github.com/rwightman/chugr
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: webdataset
|
|
21
|
+
Requires-Dist: braceexpand
|
|
22
|
+
Requires-Dist: datasets
|
|
23
|
+
Requires-Dist: timm
|
|
24
|
+
Requires-Dist: torch
|
|
25
|
+
Requires-Dist: torchvision
|
|
26
|
+
Requires-Dist: numpy
|
|
27
|
+
Requires-Dist: pillow
|
|
28
|
+
Requires-Dist: pyyaml
|
|
29
|
+
Requires-Dist: pypdfium2
|
|
30
|
+
Provides-Extra: alb
|
|
31
|
+
Requires-Dist: albumentations; extra == "alb"
|
|
32
|
+
Requires-Dist: opencv-python-headless; extra == "alb"
|
|
33
|
+
Provides-Extra: text
|
|
34
|
+
Requires-Dist: transformers; extra == "text"
|
|
35
|
+
Requires-Dist: fonttools; extra == "text"
|
|
36
|
+
Description-Content-Type: text/markdown
|
|
37
|
+
|
|
38
|
+
# Chugging Data (`chugr`)
|
|
39
|
+
|
|
40
|
+
Data pipelines for training multi-modal models on documents and image + text pairs, built on
|
|
41
|
+
[`webdataset`](https://github.com/webdataset/webdataset) and Hugging Face [`datasets`](https://github.com/huggingface/datasets).
|
|
42
|
+
|
|
43
|
+
* `webdataset` tar shards for scalable (streamed, sharded) pretraining, Hugging Face `datasets` (map-style or streaming)
|
|
44
|
+
for exploration, validation and fine-tuning, behind one config driven `create_loader()`
|
|
45
|
+
* On the fly PDF decoding and rendering, so large collections of native `.pdf` files can be streamed w/o pre-rendering
|
|
46
|
+
pages to `.png` / `.tiff`. The PDF decoder works at the webdataset level and can be plugged into other pipelines
|
|
47
|
+
* Document image transforms (incl. an `albumentations` port of the `nougat` augmentations) and NaFlex (native aspect,
|
|
48
|
+
variable resolution) patch sequence transforms
|
|
49
|
+
* NaFlex batching: per batch sequence lengths sized to a token budget, w/ a rank-identical schedule. This padded,
|
|
50
|
+
per sample scheme is the focus for variable aspect / size images, not NaViT style multi-image sequence packing
|
|
51
|
+
* Task pipelines for document reading (OCR targets), document VQA and image-text, w/ tokenization and prompt handling
|
|
52
|
+
* Interval based training: fixed sample counts per interval, the same number of batches on every rank, shard lists that
|
|
53
|
+
repeat (reshuffled per pass) or are resampled, distributed eval w/o padded or repeated samples
|
|
54
|
+
|
|
55
|
+
`chugr` is the continuation of the original `chug` library (huggingface/chug), renamed and revived. It provides the
|
|
56
|
+
data pipelines for [`pixr`](https://github.com/rwightman/pixr).
|
|
57
|
+
|
|
58
|
+
## Installation
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
pip install --pre chugr
|
|
62
|
+
# optional extras: albumentations based transforms (doc_nougat), HF tokenizers by name + synthetic text font checks
|
|
63
|
+
pip install --pre "chugr[alb,text]"
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
PDF rendering uses [pypdfium2](https://github.com/pypdfium2-team/pypdfium2) by default.
|
|
67
|
+
[fitz / PyMuPDF](https://github.com/pymupdf/PyMuPDF) can be used instead if your use case is okay with its AGPL-3.0
|
|
68
|
+
license, it must be installed separately and enabled w/ `CHUGR_USE_AGPL_PYMUPDF=1`.
|
|
69
|
+
|
|
70
|
+
## Status
|
|
71
|
+
|
|
72
|
+
Alpha. Major features work and have been used for document reading pretraining and DocVQA fine-tuning, expect breaking
|
|
73
|
+
changes. `pip install --pre chugr` installs the current dev version.
|
|
74
|
+
|
|
75
|
+
### Changes since `chug`
|
|
76
|
+
* `simple_parsing` dependency replaced by a minimal `Serializable` mixin and nested dataclass CLI parser (`chugr.common.parse_args`)
|
|
77
|
+
* NaFlex (native aspect, variable resolution) document transforms (`doc_naflex`) producing patch sequences + coords, padded by `chugr.common.collate`
|
|
78
|
+
* Fixes for `doc_basic` / `doc_better` train transforms, albumentations 2.x support for `doc_nougat`
|
|
79
|
+
* HF datasets loader: shuffled & sharded `IntervalSampler` for training (w/ intervals shorter than an epoch), split slicing (`train[:1000]`)
|
|
80
|
+
* `python -m chugr.app.test` to benchmark loaders and dump (reassembled) samples
|
|
81
|
+
* NaFlex batching (`chugr.naflex`, adapted from OpenCLIP's streaming NaFlex loader): a rank-identical schedule of
|
|
82
|
+
`(seq_len, batch_size)` per batch drawn from `naflex_seq_lens` / `naflex_seq_len_probs` and sized to a token budget
|
|
83
|
+
(`naflex_max_tokens`, w/ optional per row `naflex_text_tokens` cost), samples are resized to each batch's patch
|
|
84
|
+
budget. `length_bucketing` pool sorts samples by target text length. `mean_batch_size` is exposed on the loader for
|
|
85
|
+
loss scaling.
|
|
86
|
+
* Webdataset shard lists repeat (reshuffled per pass) instead of requiring `resampled`, so fixed sample count
|
|
87
|
+
intervals and NaFlex batching work w/o sampling shards w/ replacement
|
|
88
|
+
* NaFlex batching for HF datasets. Map-style (`format hfds`, `NaFlexMapDataset` adapted from OpenCLIP's
|
|
89
|
+
`NaFlexMapDatasetWrapper`): the same schedule over rank sharded shuffled indices that continue through the dataset
|
|
90
|
+
across intervals, failed samples are replaced. Streaming (`hfids`): `NaFlexBatcher` over the repeating stream.
|
|
91
|
+
* Streaming HF datasets yield a fixed number of train batches per worker (the stream wraps around), so every rank
|
|
92
|
+
sees the same number of batches per interval, as the webdataset loader. `num_workers` is limited to the number of
|
|
93
|
+
data shards (files) per rank. The dataset epoch (shard / shuffle seed) is set from the main process only.
|
|
94
|
+
* Ranks are split w/ the explicit `DistributedCfg` rank / world size (no reliance on `RANK` / `WORLD_SIZE` env vars
|
|
95
|
+
in dataloader workers), per rank seeds are spaced by a large stride (`chugr.common.rank_seed`) so runs w/ nearby
|
|
96
|
+
seeds don't share streams.
|
|
97
|
+
* Eval splits are exact: map-style HF datasets are split across ranks w/o padding or repeated samples (uneven per rank
|
|
98
|
+
counts), uncapped streaming eval reads every sample once.
|
|
99
|
+
* Webdataset eval: `num_samples` below the dataset size caps the eval set to exactly the first `num_samples` samples
|
|
100
|
+
for any number of ranks / workers (every worker reads that head of the stream, keep it small). W/o a cap all
|
|
101
|
+
samples are used, split by shard if there are at least `ranks * workers` shards, otherwise by sample.
|
|
102
|
+
* Text preprocessing w/ a `prompt_end_token`: an over-long prompt (question) is shortened so the prompt end token
|
|
103
|
+
and target (answer) still fit in `max_length`.
|
|
104
|
+
|
|
105
|
+
## Roadmap
|
|
106
|
+
|
|
107
|
+
### Nearish
|
|
108
|
+
* Cleanup and refinement, codebase will change
|
|
109
|
+
* Documentation & unit-tests
|
|
110
|
+
* Support reading of info .json/.yaml files for automatic shard info resolution for webdatasets (like timm)
|
|
111
|
+
|
|
112
|
+
### Mediumish
|
|
113
|
+
* Option to output bbox annotations for lines (or word + word output) for tasks that leverage layout
|
|
114
|
+
* Unified preprocessor functions for combined image + text tokenization (img+text token interleaving, etc.)
|
|
115
|
+
|
|
116
|
+
### Longish
|
|
117
|
+
* Increase range of task pipelines for other tasks, modelling needs
|
|
118
|
+
* Support additional modalities & targets (video, audio, detection/dense pixel targets, image/video/audio targets)
|
|
119
|
+
* Explore alternatives to .tar shards (array_record, arrow, etc)
|
|
120
|
+
|
|
121
|
+
## Design
|
|
122
|
+
|
|
123
|
+
### Submodule Hierarchy
|
|
124
|
+
|
|
125
|
+
The library has been designed so that functions, classes at different levels can be used independently.
|
|
126
|
+
|
|
127
|
+
If one wants to build a loader & pipeline with JSON/YAML serializable configs, use the top-level `chugr.create_loader()` in `chugr/loader.py`. Depending on dataset sources, one can easily switch this between webdataset, HF datasets (in the future, other sources).
|
|
128
|
+
|
|
129
|
+
Bypassing the highest level, one can also call `build_pipeline_*` methods in `task_pipeline` and then call `create_loader_wds` with a full array of args for `wds` only use cases.
|
|
130
|
+
|
|
131
|
+
If one doesn't want to use `chugr` loaders and pipelines at all, `image`, `text`, and `wds` (especially decoder) functionality may be useful in other projects.
|
|
132
|
+
|
|
133
|
+
#### Library modules (highest to lowest level)
|
|
134
|
+
|
|
135
|
+
The dependencies of modules within the library are intended to follow the hierarchy below. e.g. doc depends on wds, but wds should never depend on doc.
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
app
|
|
139
|
+
|
|
|
140
|
+
loader (chugr/loader.py)
|
|
141
|
+
|
|
|
142
|
+
task_pipeline
|
|
143
|
+
|
|
|
144
|
+
doc
|
|
145
|
+
|
|
|
146
|
+
wds, hfds, image, text
|
|
147
|
+
|
|
|
148
|
+
common
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Submodules
|
|
152
|
+
|
|
153
|
+
#### `common`
|
|
154
|
+
|
|
155
|
+
Configs, structures (dataclasses) for general use across the library
|
|
156
|
+
|
|
157
|
+
#### `wds`
|
|
158
|
+
|
|
159
|
+
Webdataset (`wds` for short) specific code. Extensions and alterations of webdataset functionality to fit covered use case and improve robustness.
|
|
160
|
+
|
|
161
|
+
All data pipelines in `chugr` currently leverage `wds` pipelines, even when not using `wds` datasets.
|
|
162
|
+
|
|
163
|
+
Document oriented decoding (pdf decoder) is present in `chugr/wds/decode.py`, it can be used with any webdataset pipeline as a decoder. e.g. `wds.decode(chugr.wds.DecodeDoc('pill'), 'pill')`
|
|
164
|
+
|
|
165
|
+
#### `hfds`
|
|
166
|
+
|
|
167
|
+
Hugging Face `datasets` support. A minimal wrapper that allows `datasets` to be used with chugr processing pipelines.
|
|
168
|
+
|
|
169
|
+
The processing pipelines remain webdataset based when using `datasets`, they are invoked by a custom collate class.
|
|
170
|
+
|
|
171
|
+
#### `image`
|
|
172
|
+
|
|
173
|
+
Image processing, `torchvision` and `albumentations` based transform building code. A mix of generic image (imagenet, simclr) transforms and document specific transforms, including an implementation of `albumentations` based `nougat` transforms.
|
|
174
|
+
|
|
175
|
+
#### `text`
|
|
176
|
+
|
|
177
|
+
Text processing, tokenization code.
|
|
178
|
+
|
|
179
|
+
#### `doc`
|
|
180
|
+
|
|
181
|
+
Document processing code. Currently focused on processors that apply image/pdf decoders and process document OCR or VQA annotations.
|
|
182
|
+
|
|
183
|
+
#### `task_pipeline`
|
|
184
|
+
|
|
185
|
+
Task specific pipelines, where dataset formats meet modelling needs.
|
|
186
|
+
|
|
187
|
+
Inputs to task pipelines are sample dictionaries based on the dataset form, they are decoded and then processed into outputs that match model input requirements.
|
|
188
|
+
|
|
189
|
+
Task specific pipelines that handle the data <--> model input interface are inserted into an encompassing data pipeline which handles shard lists, shuffle, wrapping, distributed worker, splitting, batching, etc.
|
|
190
|
+
|
|
191
|
+
#### `naflex`
|
|
192
|
+
|
|
193
|
+
NaFlex (variable sequence length) batching helpers: `NaFlexBatchScheduler` (rank-identical seq len / batch size
|
|
194
|
+
schedule from a token budget), `NaFlexBatcher` (per seq len processors + batching of a sample stream),
|
|
195
|
+
`NaFlexMapDataset` (the same over a map-style dataset), `LengthBucketer`.
|
|
196
|
+
|
|
197
|
+
#### `chugr.loader`
|
|
198
|
+
|
|
199
|
+
This lone top-level file includes the main factory methods for creating loaders w/ associated pipelines from config dataclasses.
|
|
200
|
+
|
|
201
|
+
#### `app`
|
|
202
|
+
|
|
203
|
+
Most applications using `chugr` will exist outside of the lib in training libraries, etc. Some builtin utility / exploration apps will be included here.
|
|
204
|
+
|
|
205
|
+
## Datasets
|
|
206
|
+
|
|
207
|
+
Datasets that work well with this library can be found on the Hugging Face Hub under the `pixparse` organization (https://huggingface.co/pixparse).
|
|
208
|
+
|
|
209
|
+
We'll add links to other noteworthy datasets that can be used as we become aware of them.
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
## Usage / Examples
|
|
213
|
+
|
|
214
|
+
### Document Reading, Training w/ IDL
|
|
215
|
+
```python
|
|
216
|
+
import chugr
|
|
217
|
+
img_cfg = chugr.ImageInputCfg(size=(1024, 768), transform_type='doc_better')
|
|
218
|
+
img_fn = chugr.create_image_preprocessor(input_cfg=img_cfg, is_training=True)
|
|
219
|
+
txt_fn = chugr.create_text_preprocessor(
|
|
220
|
+
'naver-clova-ix/donut-base',
|
|
221
|
+
prompt_end_token='<s_idl>',
|
|
222
|
+
task_start_token='<s_idl>', # NOTE needs to be added to tokenizer
|
|
223
|
+
)
|
|
224
|
+
|
|
225
|
+
task_cfg = chugr.DataTaskDocReadCfg(
|
|
226
|
+
image_process_fn=img_fn,
|
|
227
|
+
text_process_fn=txt_fn,
|
|
228
|
+
page_sampling='random',
|
|
229
|
+
error_handler='dump_and_reraise',
|
|
230
|
+
)
|
|
231
|
+
data_cfg = chugr.DataCfg(
|
|
232
|
+
source='pipe:curl -s -f -L https://huggingface.co/datasets/pixparse/idl-wds/resolve/main/idl-train-0{0000..2999}.tar',
|
|
233
|
+
batch_size=8,
|
|
234
|
+
num_samples=3144726,
|
|
235
|
+
format='wds',
|
|
236
|
+
)
|
|
237
|
+
lb = chugr.create_loader(
|
|
238
|
+
data_cfg,
|
|
239
|
+
task_cfg,
|
|
240
|
+
is_training=True,
|
|
241
|
+
)
|
|
242
|
+
ii = iter(lb)
|
|
243
|
+
sample = next(ii)
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Document Reading, Exploring IDL
|
|
247
|
+
```python
|
|
248
|
+
import chugr
|
|
249
|
+
task_cfg = chugr.DataTaskDocReadCfg(page_sampling='all')
|
|
250
|
+
data_cfg = chugr.DataCfg(
|
|
251
|
+
source='pixparse/idl-wds',
|
|
252
|
+
split='train',
|
|
253
|
+
batch_size=None,
|
|
254
|
+
format='hfids',
|
|
255
|
+
num_workers=0,
|
|
256
|
+
)
|
|
257
|
+
lb = chugr.create_loader(
|
|
258
|
+
data_cfg,
|
|
259
|
+
task_cfg,
|
|
260
|
+
)
|
|
261
|
+
ii = iter(lb)
|
|
262
|
+
sample = next(ii)
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Document Reading, Training with PDFA
|
|
266
|
+
|
|
267
|
+
```python
|
|
268
|
+
import chugr
|
|
269
|
+
img_cfg = chugr.ImageInputCfg(size=(1024, 768), transform_type='doc_nougat')
|
|
270
|
+
img_fn = chugr.create_image_preprocessor(input_cfg=img_cfg, is_training=True)
|
|
271
|
+
txt_fn = chugr.create_text_preprocessor(
|
|
272
|
+
'naver-clova-ix/donut-base',
|
|
273
|
+
prompt_end_token='<s_pdfa>',
|
|
274
|
+
task_start_token='<s_pdfa>', # NOTE needs to be added to tokenizer
|
|
275
|
+
)
|
|
276
|
+
|
|
277
|
+
task_cfg = chugr.DataTaskDocReadCfg(
|
|
278
|
+
image_process_fn=img_fn,
|
|
279
|
+
text_process_fn=txt_fn,
|
|
280
|
+
page_sampling='random',
|
|
281
|
+
)
|
|
282
|
+
data_cfg = chugr.DataCfg(
|
|
283
|
+
source='pipe:curl -s -f -L https://huggingface.co/datasets/pixparse/pdfa-english-train/resolve/main/pdfa-eng-train-{000000..005000}.tar',
|
|
284
|
+
batch_size=8,
|
|
285
|
+
num_samples=1000000, # FIXME replace with actual
|
|
286
|
+
format='wds',
|
|
287
|
+
)
|
|
288
|
+
lb = chugr.create_loader(
|
|
289
|
+
data_cfg,
|
|
290
|
+
task_cfg,
|
|
291
|
+
is_training=True,
|
|
292
|
+
)
|
|
293
|
+
ii = iter(lb)
|
|
294
|
+
sample = next(ii)
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### Document Reading, Exploring PDFA
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
import chugr
|
|
301
|
+
|
|
302
|
+
task_cfg = chugr.DataTaskDocReadCfg(
|
|
303
|
+
page_sampling='all',
|
|
304
|
+
)
|
|
305
|
+
data_cfg = chugr.DataCfg(
|
|
306
|
+
source='pixparse/pdfa-eng-wds',
|
|
307
|
+
split='train',
|
|
308
|
+
batch_size=None,
|
|
309
|
+
format='hfids',
|
|
310
|
+
num_workers=0,
|
|
311
|
+
)
|
|
312
|
+
lb = chugr.create_loader(
|
|
313
|
+
data_cfg,
|
|
314
|
+
task_cfg,
|
|
315
|
+
)
|
|
316
|
+
ii = iter(lb)
|
|
317
|
+
sample = next(ii)
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
### NaFlex (variable resolution) document input
|
|
322
|
+
|
|
323
|
+
```python
|
|
324
|
+
import chugr
|
|
325
|
+
from PIL import Image
|
|
326
|
+
|
|
327
|
+
# pages keep their aspect ratio, resized to fit a patch budget (max_seq_len patches of patch_size x patch_size)
|
|
328
|
+
img_cfg = chugr.ImageInputCfg(transform_type='doc_naflex', patch_size=16, max_seq_len=1024)
|
|
329
|
+
img_fn = chugr.create_image_preprocessor(input_cfg=img_cfg, is_training=True)
|
|
330
|
+
out = img_fn(Image.new('L', (850, 1100), 255))
|
|
331
|
+
# {'patches': [N, 256], 'patch_coord': [N, 2] (y, x), 'patch_valid': [N] bool}, N <= max_seq_len
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
For batches w/ a sequence length (patch budget) drawn per batch and the batch size set by a token budget, set
|
|
335
|
+
`naflex_seq_lens`, `naflex_seq_len_probs` and `naflex_max_tokens` in `DataCfg` (webdataset, map-style or streaming
|
|
336
|
+
HF datasets).
|
|
337
|
+
|
|
338
|
+
### Image + Text
|
|
339
|
+
|
|
340
|
+
#### Training
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
import chugr
|
|
344
|
+
import transformers
|
|
345
|
+
from functools import partial
|
|
346
|
+
img_cfg = chugr.ImageInputCfg(size=(512, 512), transform_type='image_timm')
|
|
347
|
+
img_fn = chugr.create_image_preprocessor(input_cfg=img_cfg, is_training=True)
|
|
348
|
+
tokenizer = transformers.AutoTokenizer.from_pretrained('laion/CLIP-ViT-H-14-laion2B-s32B-b79K')
|
|
349
|
+
txt_fn = partial(chugr.tokenize, max_length=1000, tokenizer=tokenizer)
|
|
350
|
+
task_cfg = chugr.DataTaskImageTextCfg(
|
|
351
|
+
image_process_fn=img_fn,
|
|
352
|
+
text_process_fn=txt_fn,
|
|
353
|
+
)
|
|
354
|
+
data_cfg = chugr.DataCfg(
|
|
355
|
+
source='pipe:curl -s -f -L https://huggingface.co/datasets/pixparse/cc12m-wds/resolve/main/cc12m-train-{0000..2175}.tar',
|
|
356
|
+
batch_size=8,
|
|
357
|
+
num_samples=10968539,
|
|
358
|
+
format='wds',
|
|
359
|
+
)
|
|
360
|
+
lb = chugr.create_loader(
|
|
361
|
+
data_cfg,
|
|
362
|
+
task_cfg,
|
|
363
|
+
is_training=True,
|
|
364
|
+
)
|
|
365
|
+
ii = iter(lb)
|
|
366
|
+
sample = next(ii)
|
|
367
|
+
```
|
|
368
|
+
|
|
369
|
+
### Document VQA
|
|
370
|
+
|
|
371
|
+
#### Training, Fine-tuning
|
|
372
|
+
```python
|
|
373
|
+
import chugr
|
|
374
|
+
img_cfg = chugr.ImageInputCfg(size=(1024, 768), transform_type='doc_basic')
|
|
375
|
+
img_fn = chugr.create_image_preprocessor(img_cfg, is_training=True)
|
|
376
|
+
txt_fn = chugr.create_text_preprocessor(
|
|
377
|
+
'naver-clova-ix/donut-base-finetuned-docvqa',
|
|
378
|
+
prompt_end_token='<s_answer>',
|
|
379
|
+
task_start_token='<s_docvqa>',
|
|
380
|
+
)
|
|
381
|
+
|
|
382
|
+
task_cfg = chugr.DataTaskDocVqaCfg(
|
|
383
|
+
image_process_fn=img_fn,
|
|
384
|
+
text_process_fn=txt_fn,
|
|
385
|
+
)
|
|
386
|
+
data_cfg = chugr.DataCfg(
|
|
387
|
+
source='pipe:curl -s -f -L https://huggingface.co/datasets/pixparse/docvqa-wds/resolve/main/docvqa-train-{000..383}.tar',
|
|
388
|
+
batch_size=8,
|
|
389
|
+
format='wds',
|
|
390
|
+
num_samples=39463,
|
|
391
|
+
)
|
|
392
|
+
lb = chugr.create_loader(
|
|
393
|
+
data_cfg,
|
|
394
|
+
task_cfg,
|
|
395
|
+
is_training=True,
|
|
396
|
+
)
|
|
397
|
+
ii = iter(lb)
|
|
398
|
+
sample = next(ii)
|
|
399
|
+
```
|
|
400
|
+
|
|
401
|
+
#### Exploration
|
|
402
|
+
|
|
403
|
+
```python
|
|
404
|
+
import chugr
|
|
405
|
+
task_cfg = chugr.DataTaskDocVqaCfg(
|
|
406
|
+
question_prefix='Question: ',
|
|
407
|
+
question_suffix='',
|
|
408
|
+
answer_prefix='Answer: ',
|
|
409
|
+
answer_suffix=''
|
|
410
|
+
)
|
|
411
|
+
data_cfg = chugr.DataCfg(
|
|
412
|
+
source='pixparse/docvqa-single-page-questions',
|
|
413
|
+
split='validation',
|
|
414
|
+
batch_size=None,
|
|
415
|
+
format='hfids',
|
|
416
|
+
num_workers=0,
|
|
417
|
+
)
|
|
418
|
+
lb = chugr.create_loader(
|
|
419
|
+
data_cfg,
|
|
420
|
+
task_cfg
|
|
421
|
+
)
|
|
422
|
+
ii = iter(lb)
|
|
423
|
+
sample = next(ii)
|
|
424
|
+
```
|
|
425
|
+
|
|
426
|
+
## Acknowledgement
|
|
427
|
+
|
|
428
|
+
`chugr` evolved from the `webdataset` datapipeline used successfully in the [OpenCLIP](https://github.com/mlfoundations/open_clip) project. Thanks to all the contributors in that project. Future work will likely involve closing the loop and leveraging `chugr` in OpenCLIP for increased capability.
|
|
429
|
+
|
|
430
|
+
The image/document augmentations in `chugr` rely on a number of external influences. Our document oriented `doc_better` torchvision augmentations are influenced by `nougat`, and the `doc_nougat` is a direct adaptation of the [`albumentations`](https://albumentations.ai/) + `cv2` document pipeline in [`nougat`](https://github.com/facebookresearch/nougat). Several image augmentations leverage existing work in the `timm` library.
|
|
431
|
+
|
|
432
|
+
Also, big thanks to the maintainers of [`webdataset`](https://github.com/webdataset/webdataset) and Hugging Face [`datasets`](https://github.com/huggingface/datasets).
|
|
433
|
+
|
|
434
|
+
## License
|
|
435
|
+
|
|
436
|
+
Apache 2.0, see [LICENSE](LICENSE). The optional PyMuPDF backend is AGPL-3.0 licensed (see above).
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
chugr-0.2.0.dev0.dist-info/METADATA,sha256=b9qr-BxaSsy0l_ku17vrvZ0c3r4hyL9z4tovO9uw0qE,17399
|
|
2
|
+
chugr-0.2.0.dev0.dist-info/WHEEL,sha256=IuIk3wbaEnFH1cx75iM2R1CmliRI3dFLXTbRakgvgFQ,90
|
|
3
|
+
chugr-0.2.0.dev0.dist-info/entry_points.txt,sha256=6OYgBcLyFCUgeqLgnvMyOJxPCWzgy7se4rLPKtNonMs,34
|
|
4
|
+
chugr-0.2.0.dev0.dist-info/licenses/LICENSE,sha256=s29fkiq0mOrn5lORLIiKrvcZdfW5oQ63jCN8xF-q5MA,11347
|
|
5
|
+
chugr/__init__.py,sha256=k5AUMlXAQVenCLOv7VmVWOgxjtnf1IZqysguqWSE5Sw,1177
|
|
6
|
+
chugr/app/test.py,sha256=Rsw0ivRTiOT52ENYIYscLyfNqkhuamIol59VNQu9QlU,4333
|
|
7
|
+
chugr/common/__init__.py,sha256=F_2KlUL9kJ4FumIVuXfl3C3eVRdqIEC_h20AMOEbd6A,585
|
|
8
|
+
chugr/common/cli.py,sha256=hH_tLWQnSAMa6Otf81uF1l_zJfeNdoCXz153DBuSwQ4,8785
|
|
9
|
+
chugr/common/collate.py,sha256=d0ZlmW7ZhYfltN49SpaOKxqKylYnxc0saBtwZ8v_oz8,4450
|
|
10
|
+
chugr/common/config.py,sha256=m6aTtOBFvqFpeAOlQKcwmClksu19FT7AUOcvtjCSDQE,12061
|
|
11
|
+
chugr/common/random.py,sha256=nm7JWwipRn9z9eZlNBbvnnSmbIoh3kVuJAlZLRmYO9Q,2773
|
|
12
|
+
chugr/common/serialize.py,sha256=8ImFPMZmVN-47vdmv8hp8wp0KIfj2pIWMlaKKPlEGyU,4975
|
|
13
|
+
chugr/common/task_config.py,sha256=OkdmhD2_qWRidEbi7QNQyxCF7JNknbf8WNipAbI177I,1193
|
|
14
|
+
chugr/common/types.py,sha256=3SolKc9-eN4m8lcBB-vOGaPOXk5eQ7N1JD6uuGUXHm0,3513
|
|
15
|
+
chugr/common/urls.py,sha256=9N28cw0bh4620iobZL5giTuPcKlYdksIpcPCHP9ZOOk,2605
|
|
16
|
+
chugr/doc/__init__.py,sha256=VrD9ECxY9jaYzzMAyzfx3F50RlQkzZi6z4IOtYiSnL8,511
|
|
17
|
+
chugr/doc/constants.py,sha256=tPwKiuunQVeYCsDzyERbtDwotzpykJhnHcprJnPa53c,738
|
|
18
|
+
chugr/doc/doc_processor.py,sha256=JeR80lLHfNdnSzrMywGk5MJxI-kDYXtLilW0tMPBsz0,9138
|
|
19
|
+
chugr/doc/doc_read_processor.py,sha256=dvoxHLYb8V0JT-FsRrPzJOHXhZjxp2Zohi-8zjac9Ic,10713
|
|
20
|
+
chugr/doc/doc_vqa_processor.py,sha256=ugpQAe6GOjkTWbL0XqBHIk_k_-PbnCpUfosSe5b0rTA,5188
|
|
21
|
+
chugr/doc/synth_text.py,sha256=WyVT2SscYj6hqvC8HWey_lpLJG0dp9MoW_poqnPQbKU,8671
|
|
22
|
+
chugr/hfds/__init__.py,sha256=VkhuT-6rEvrxL2li4FVNeowSIlC4kNp-jkT-mBR26lM,70
|
|
23
|
+
chugr/hfds/collate.py,sha256=Tgc6hUppIsyEai7NNET5A1GpNQmBu7q9hj2UtncjYOE,2465
|
|
24
|
+
chugr/hfds/loader.py,sha256=niYXYHB_sQLqUSZ1KD8cBudLHH6CRHq3t-5N41_Bdj4,15175
|
|
25
|
+
chugr/hfds/wrappers.py,sha256=jpxYEY8wYJsWUuC4hCVZ4i2gTDAaa9b4BvOLO-avS1s,4223
|
|
26
|
+
chugr/image/__init__.py,sha256=YmiYYXF_-zsbL75WZykTwiCTmOFaUeBvFGscnZpU-lk,346
|
|
27
|
+
chugr/image/build_transforms_doc.py,sha256=jcVjMQga78oCQ24td64zvDsKAG8Wp1FcRMzx2zHryfw,14659
|
|
28
|
+
chugr/image/build_transforms_image.py,sha256=VY5_QRubnKEuggPmXBX9NhS-8aMyKq6Gdw_qPGQTjgk,7360
|
|
29
|
+
chugr/image/transforms_alb.py,sha256=UYNd31COV4TZ61_2NhrYGMto1t4jvDDmJnrt2xRM88o,3266
|
|
30
|
+
chugr/image/transforms_factory.py,sha256=7OC5CvonbYt-jGT5ZyW_06Sqql-JF7fja243r1_Pdp0,1872
|
|
31
|
+
chugr/image/transforms_torch.py,sha256=U8ygV1Z1x-MiBgUgYCMsHil2F9gUqWWoRTPF6xqQ7G0,4328
|
|
32
|
+
chugr/loader.py,sha256=70WcaGBkMZvFgtoTSxm9pMWJfVIxpj2WAvjGSHzcAhE,8819
|
|
33
|
+
chugr/naflex.py,sha256=EjXAk7_BvTW5H4XoO3xr8y_SiK1kwrvJAz0fIFkabSQ,15793
|
|
34
|
+
chugr/task_pipeline/__init__.py,sha256=T-9ftIhmgoxN72uC0EgSHLh1u9J3oM6ShdvJYY5L72g,450
|
|
35
|
+
chugr/task_pipeline/pipeline_doc_read.py,sha256=Rd81TT0-9_rHl-FcmZXa6yAkIIstUXCSZzLi5pcBAJU,2475
|
|
36
|
+
chugr/task_pipeline/pipeline_doc_vqa.py,sha256=qEp1jOS0-5ksjNy3-ZqX5ogOK_gMy8PdF-DN4iTEDIU,4110
|
|
37
|
+
chugr/task_pipeline/pipeline_factory.py,sha256=IyTDjO1dke0Hb_0mg0HwPDXKfhSThWmTUx3UHYHJRLQ,1327
|
|
38
|
+
chugr/task_pipeline/pipeline_gtparse.py,sha256=ISNHtawxKZnzYLBP_n5GOKejdiJ0qqjPY4YrI3rHF78,2846
|
|
39
|
+
chugr/task_pipeline/pipeline_image_text.py,sha256=ZvsozaT7srNdxmpG6bp1UQieArd_XaPN-sYMoFl7PIA,2701
|
|
40
|
+
chugr/task_pipeline/pipeline_manual.py,sha256=_16LcePY6Z5fjTBiJS56mY0E7esuuRbxXCkG25yJLZ4,656
|
|
41
|
+
chugr/text/__init__.py,sha256=efHOP5WlEzDNAqJujEIOLsP-f40ckeEbkuiOLnTPC4o,102
|
|
42
|
+
chugr/text/tokenization.py,sha256=rPx3DEA1yKgPtT_lITGGaNHq-Sq_mtnw0oCx9pf5NWw,8412
|
|
43
|
+
chugr/version.py,sha256=swZcYerOohV7Qaos_F8PHWTjyuhVB0Siug4R-iUXwFk,26
|
|
44
|
+
chugr/wds/__init__.py,sha256=eHPwwKW5ITbrvAhrciu5lHKqcGysxVpzhWt8yYtfAto,473
|
|
45
|
+
chugr/wds/dataset_info.py,sha256=NjPcVDAzhyl4Qr8D9vYOuJc5A5jrY4JaZJFd6ajU10g,2263
|
|
46
|
+
chugr/wds/decode.py,sha256=y2ltoXAA7Jx20aipgLa92fPmxVPYtG7WIp29O1p-naU,10640
|
|
47
|
+
chugr/wds/filters.py,sha256=FbDe4wzkVVk02gbcUHAzI5WPckkHkRxSbyygRLyt60s,4389
|
|
48
|
+
chugr/wds/helpers.py,sha256=3TZfIlibqkPbzHHQ-3l1zeYu2iFOa-iRfC_eGUT6GGY,2232
|
|
49
|
+
chugr/wds/loader.py,sha256=tiPp6GIKEgs8yql-_sCT9rUOxsSsEySv9QYTu4efdT4,8064
|
|
50
|
+
chugr/wds/pipeline.py,sha256=bY52RiyQJ9QIX00a6jthg1YdIdEWtxrUfBA1-5L7Df4,7539
|
|
51
|
+
chugr/wds/shardlists.py,sha256=1bgTjUl2xDJWsHY9Qb8LgrRuWxi2vKiMbsvOyDLYfIo,5025
|
|
52
|
+
chugr/wds/tariterators.py,sha256=heQ8RBa_HGVylYPExKSpEcTegs7wTDA4B8ApxBjTPIg,2370
|
|
53
|
+
chugr-0.2.0.dev0.dist-info/RECORD,,
|