loaderx 0.0.2__tar.gz
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.
- loaderx-0.0.2/LICENSE +21 -0
- loaderx-0.0.2/PKG-INFO +87 -0
- loaderx-0.0.2/README.md +46 -0
- loaderx-0.0.2/loaderx/__init__.py +4 -0
- loaderx-0.0.2/loaderx/dataloader.py +52 -0
- loaderx-0.0.2/loaderx/dataset.py +9 -0
- loaderx-0.0.2/loaderx.egg-info/PKG-INFO +87 -0
- loaderx-0.0.2/loaderx.egg-info/SOURCES.txt +10 -0
- loaderx-0.0.2/loaderx.egg-info/dependency_links.txt +1 -0
- loaderx-0.0.2/loaderx.egg-info/top_level.txt +1 -0
- loaderx-0.0.2/pyproject.toml +31 -0
- loaderx-0.0.2/setup.cfg +4 -0
loaderx-0.0.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 EOELAB AI Research
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
loaderx-0.0.2/PKG-INFO
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: loaderx
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Minimal data loader for Flax
|
|
5
|
+
Author-email: Ben0i0d <ben0i0d@foxmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 EOELAB AI Research
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/eoeair/loaderx
|
|
29
|
+
Project-URL: Documentation, https://github.com/eoeair/loaderx
|
|
30
|
+
Project-URL: Source, https://github.com/eoeair/loaderx
|
|
31
|
+
Project-URL: Bug Tracker, https://github.com/eoeair/loaderx/issues
|
|
32
|
+
Keywords: flax,python,dataloader
|
|
33
|
+
Classifier: Development Status :: 3 - Alpha
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Requires-Python: >=3.10
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# loaderx
|
|
43
|
+
Minimal data loader for Flax
|
|
44
|
+
|
|
45
|
+
## Rationale for Creating mloader
|
|
46
|
+
While Flax supports various data loading backends—such as PyTorch, TensorFlow, Grain, and jax_dataloader—these often come with nontrivial dependencies.
|
|
47
|
+
1. Installing heavy frameworks like PyTorch or TensorFlow solely for data loading is undesirable.
|
|
48
|
+
2. Grain offers a clean API but suffers from suboptimal performance in practice.
|
|
49
|
+
3. jax_dataloader leverages GPU memory by default, which may lead to inefficient memory usage in certain scenarios.
|
|
50
|
+
|
|
51
|
+
## Design Goals of mloader
|
|
52
|
+
mloader is designed with simplicity and efficiency in mind.
|
|
53
|
+
It follows a pragmatic approach—favoring low memory overhead and minimal dependencies.
|
|
54
|
+
The implementation targets common use cases, with a particular focus on single-host training pipelines.
|
|
55
|
+
|
|
56
|
+
## Current Limitations
|
|
57
|
+
At present, mloader only supports single-host scenarios and does not yet address multi-host training setups.
|
|
58
|
+
|
|
59
|
+
## How to integrate it with Flax.
|
|
60
|
+
Below is a code example.
|
|
61
|
+
|
|
62
|
+
The mloader is mainly inspired by the design of Grain, so avoid using patterns like `for epoch in num_epochs`.
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
def loss_fn(model: CNN, batch):
|
|
66
|
+
logits = model(batch['data'])
|
|
67
|
+
loss = optax.softmax_cross_entropy_with_integer_labels(logits=logits, labels=batch['label']).mean()
|
|
68
|
+
return loss, logits
|
|
69
|
+
|
|
70
|
+
@nnx.jit
|
|
71
|
+
def train_step(model: CNN, optimizer: nnx.Optimizer, metrics: nnx.MultiMetric, batch):
|
|
72
|
+
"""Train for a single step."""
|
|
73
|
+
grad_fn = nnx.value_and_grad(loss_fn, has_aux=True)
|
|
74
|
+
(loss, logits), grads = grad_fn(model, batch)
|
|
75
|
+
metrics.update(loss=loss, logits=logits, labels=batch['label']) # In-place updates.
|
|
76
|
+
optimizer.update(grads) # In-place updates.
|
|
77
|
+
|
|
78
|
+
@nnx.jit
|
|
79
|
+
def eval_step(model: CNN, metrics: nnx.MultiMetric, batch):
|
|
80
|
+
loss, logits = loss_fn(model, batch)
|
|
81
|
+
metrics.update(loss=loss, logits=logits, labels=batch['label']) # In-place updates.
|
|
82
|
+
|
|
83
|
+
@nnx.jit
|
|
84
|
+
def pred_step(model: CNN, batch):
|
|
85
|
+
logits = model(batch['data'])
|
|
86
|
+
return logits.argmax(axis=1)
|
|
87
|
+
```
|
loaderx-0.0.2/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# loaderx
|
|
2
|
+
Minimal data loader for Flax
|
|
3
|
+
|
|
4
|
+
## Rationale for Creating mloader
|
|
5
|
+
While Flax supports various data loading backends—such as PyTorch, TensorFlow, Grain, and jax_dataloader—these often come with nontrivial dependencies.
|
|
6
|
+
1. Installing heavy frameworks like PyTorch or TensorFlow solely for data loading is undesirable.
|
|
7
|
+
2. Grain offers a clean API but suffers from suboptimal performance in practice.
|
|
8
|
+
3. jax_dataloader leverages GPU memory by default, which may lead to inefficient memory usage in certain scenarios.
|
|
9
|
+
|
|
10
|
+
## Design Goals of mloader
|
|
11
|
+
mloader is designed with simplicity and efficiency in mind.
|
|
12
|
+
It follows a pragmatic approach—favoring low memory overhead and minimal dependencies.
|
|
13
|
+
The implementation targets common use cases, with a particular focus on single-host training pipelines.
|
|
14
|
+
|
|
15
|
+
## Current Limitations
|
|
16
|
+
At present, mloader only supports single-host scenarios and does not yet address multi-host training setups.
|
|
17
|
+
|
|
18
|
+
## How to integrate it with Flax.
|
|
19
|
+
Below is a code example.
|
|
20
|
+
|
|
21
|
+
The mloader is mainly inspired by the design of Grain, so avoid using patterns like `for epoch in num_epochs`.
|
|
22
|
+
|
|
23
|
+
```
|
|
24
|
+
def loss_fn(model: CNN, batch):
|
|
25
|
+
logits = model(batch['data'])
|
|
26
|
+
loss = optax.softmax_cross_entropy_with_integer_labels(logits=logits, labels=batch['label']).mean()
|
|
27
|
+
return loss, logits
|
|
28
|
+
|
|
29
|
+
@nnx.jit
|
|
30
|
+
def train_step(model: CNN, optimizer: nnx.Optimizer, metrics: nnx.MultiMetric, batch):
|
|
31
|
+
"""Train for a single step."""
|
|
32
|
+
grad_fn = nnx.value_and_grad(loss_fn, has_aux=True)
|
|
33
|
+
(loss, logits), grads = grad_fn(model, batch)
|
|
34
|
+
metrics.update(loss=loss, logits=logits, labels=batch['label']) # In-place updates.
|
|
35
|
+
optimizer.update(grads) # In-place updates.
|
|
36
|
+
|
|
37
|
+
@nnx.jit
|
|
38
|
+
def eval_step(model: CNN, metrics: nnx.MultiMetric, batch):
|
|
39
|
+
loss, logits = loss_fn(model, batch)
|
|
40
|
+
metrics.update(loss=loss, logits=logits, labels=batch['label']) # In-place updates.
|
|
41
|
+
|
|
42
|
+
@nnx.jit
|
|
43
|
+
def pred_step(model: CNN, batch):
|
|
44
|
+
logits = model(batch['data'])
|
|
45
|
+
return logits.argmax(axis=1)
|
|
46
|
+
```
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import numpy as np
|
|
2
|
+
import threading
|
|
3
|
+
from queue import Queue
|
|
4
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
5
|
+
|
|
6
|
+
class DataLoader:
|
|
7
|
+
def __init__(self, dataset, batch_size=256, shuffle=True, prefetch=2, num_epoch=1, seed=None):
|
|
8
|
+
self.dataset = dataset
|
|
9
|
+
self.batch_size = batch_size
|
|
10
|
+
self.shuffle = shuffle
|
|
11
|
+
self.prefetch = prefetch
|
|
12
|
+
self.num_epoch = num_epoch
|
|
13
|
+
self.seed = seed
|
|
14
|
+
|
|
15
|
+
self.indices = list(range(len(dataset)))
|
|
16
|
+
self.queue = Queue(maxsize=prefetch)
|
|
17
|
+
self.stop_signal = threading.Event()
|
|
18
|
+
self.current_epoch = 0
|
|
19
|
+
|
|
20
|
+
self.thread = threading.Thread(target=self._prefetch_data)
|
|
21
|
+
self.thread.start()
|
|
22
|
+
|
|
23
|
+
def _prefetch_data(self):
|
|
24
|
+
while not self.stop_signal.is_set() and self.current_epoch < self.num_epoch:
|
|
25
|
+
if self.shuffle:
|
|
26
|
+
if self.seed is not None:
|
|
27
|
+
np.random.seed(self.seed + self.current_epoch)
|
|
28
|
+
np.random.shuffle(self.indices)
|
|
29
|
+
for i in range(0, len(self.indices), self.batch_size):
|
|
30
|
+
batch_indices = self.indices[i:i + self.batch_size]
|
|
31
|
+
with ThreadPoolExecutor() as executor:
|
|
32
|
+
batch = executor.map(self.dataset.__getitem__, batch_indices)
|
|
33
|
+
batch_data, batch_labels = zip(*batch)
|
|
34
|
+
self.queue.put({'data': np.stack(batch_data), 'label': np.stack(batch_labels)})
|
|
35
|
+
self.current_epoch += 1
|
|
36
|
+
self.stop_signal.set()
|
|
37
|
+
|
|
38
|
+
def __iter__(self):
|
|
39
|
+
return self
|
|
40
|
+
|
|
41
|
+
def __next__(self):
|
|
42
|
+
if self.stop_signal.is_set() and self.queue.empty():
|
|
43
|
+
raise StopIteration
|
|
44
|
+
return self.queue.get()
|
|
45
|
+
|
|
46
|
+
def __del__(self):
|
|
47
|
+
try:
|
|
48
|
+
self.stop_signal.set()
|
|
49
|
+
if hasattr(self, 'thread') and self.thread is not None and self.thread.is_alive():
|
|
50
|
+
self.thread.join()
|
|
51
|
+
except Exception:
|
|
52
|
+
pass
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: loaderx
|
|
3
|
+
Version: 0.0.2
|
|
4
|
+
Summary: Minimal data loader for Flax
|
|
5
|
+
Author-email: Ben0i0d <ben0i0d@foxmail.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2025 EOELAB AI Research
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in all
|
|
18
|
+
copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
26
|
+
SOFTWARE.
|
|
27
|
+
|
|
28
|
+
Project-URL: Homepage, https://github.com/eoeair/loaderx
|
|
29
|
+
Project-URL: Documentation, https://github.com/eoeair/loaderx
|
|
30
|
+
Project-URL: Source, https://github.com/eoeair/loaderx
|
|
31
|
+
Project-URL: Bug Tracker, https://github.com/eoeair/loaderx/issues
|
|
32
|
+
Keywords: flax,python,dataloader
|
|
33
|
+
Classifier: Development Status :: 3 - Alpha
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Programming Language :: Python :: 3
|
|
37
|
+
Requires-Python: >=3.10
|
|
38
|
+
Description-Content-Type: text/markdown
|
|
39
|
+
License-File: LICENSE
|
|
40
|
+
Dynamic: license-file
|
|
41
|
+
|
|
42
|
+
# loaderx
|
|
43
|
+
Minimal data loader for Flax
|
|
44
|
+
|
|
45
|
+
## Rationale for Creating mloader
|
|
46
|
+
While Flax supports various data loading backends—such as PyTorch, TensorFlow, Grain, and jax_dataloader—these often come with nontrivial dependencies.
|
|
47
|
+
1. Installing heavy frameworks like PyTorch or TensorFlow solely for data loading is undesirable.
|
|
48
|
+
2. Grain offers a clean API but suffers from suboptimal performance in practice.
|
|
49
|
+
3. jax_dataloader leverages GPU memory by default, which may lead to inefficient memory usage in certain scenarios.
|
|
50
|
+
|
|
51
|
+
## Design Goals of mloader
|
|
52
|
+
mloader is designed with simplicity and efficiency in mind.
|
|
53
|
+
It follows a pragmatic approach—favoring low memory overhead and minimal dependencies.
|
|
54
|
+
The implementation targets common use cases, with a particular focus on single-host training pipelines.
|
|
55
|
+
|
|
56
|
+
## Current Limitations
|
|
57
|
+
At present, mloader only supports single-host scenarios and does not yet address multi-host training setups.
|
|
58
|
+
|
|
59
|
+
## How to integrate it with Flax.
|
|
60
|
+
Below is a code example.
|
|
61
|
+
|
|
62
|
+
The mloader is mainly inspired by the design of Grain, so avoid using patterns like `for epoch in num_epochs`.
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
def loss_fn(model: CNN, batch):
|
|
66
|
+
logits = model(batch['data'])
|
|
67
|
+
loss = optax.softmax_cross_entropy_with_integer_labels(logits=logits, labels=batch['label']).mean()
|
|
68
|
+
return loss, logits
|
|
69
|
+
|
|
70
|
+
@nnx.jit
|
|
71
|
+
def train_step(model: CNN, optimizer: nnx.Optimizer, metrics: nnx.MultiMetric, batch):
|
|
72
|
+
"""Train for a single step."""
|
|
73
|
+
grad_fn = nnx.value_and_grad(loss_fn, has_aux=True)
|
|
74
|
+
(loss, logits), grads = grad_fn(model, batch)
|
|
75
|
+
metrics.update(loss=loss, logits=logits, labels=batch['label']) # In-place updates.
|
|
76
|
+
optimizer.update(grads) # In-place updates.
|
|
77
|
+
|
|
78
|
+
@nnx.jit
|
|
79
|
+
def eval_step(model: CNN, metrics: nnx.MultiMetric, batch):
|
|
80
|
+
loss, logits = loss_fn(model, batch)
|
|
81
|
+
metrics.update(loss=loss, logits=logits, labels=batch['label']) # In-place updates.
|
|
82
|
+
|
|
83
|
+
@nnx.jit
|
|
84
|
+
def pred_step(model: CNN, batch):
|
|
85
|
+
logits = model(batch['data'])
|
|
86
|
+
return logits.argmax(axis=1)
|
|
87
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
loaderx
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "loaderx"
|
|
7
|
+
dynamic = ["version"]
|
|
8
|
+
description = "Minimal data loader for Flax"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
authors = [
|
|
12
|
+
{name = "Ben0i0d", email = "ben0i0d@foxmail.com"},
|
|
13
|
+
]
|
|
14
|
+
license = {file = "LICENSE"}
|
|
15
|
+
keywords = ["flax", "python", "dataloader"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 3 - Alpha",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
]
|
|
22
|
+
dependencies = []
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.dynamic]
|
|
25
|
+
version = {attr = "loaderx.__version__"}
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
"Homepage" = "https://github.com/eoeair/loaderx"
|
|
29
|
+
"Documentation" = "https://github.com/eoeair/loaderx"
|
|
30
|
+
"Source" = "https://github.com/eoeair/loaderx"
|
|
31
|
+
"Bug Tracker" = "https://github.com/eoeair/loaderx/issues"
|
loaderx-0.0.2/setup.cfg
ADDED