Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
B
Basedformer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Basedformer
Commits
ebb032d8
Commit
ebb032d8
authored
Sep 14, 2022
by
kurumuz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
sharding and epoch support with global shuffle
parent
1f2c39ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
+12
-3
basedformer/dataset.py
basedformer/dataset.py
+12
-3
No files found.
basedformer/dataset.py
View file @
ebb032d8
...
...
@@ -94,24 +94,33 @@ class ShardedImageDataset(data.Dataset):
#make so metadata is shardable by world_size(num_gpus)
#and batch_size
self
.
original_index
=
self
.
index
self
.
index
=
self
.
shard
(
shuffle
=
shuffle
)
self
.
shard
(
shuffle
=
shuffle
)
#override possible gil locks by making the index map an nparray
self
.
index
=
np
.
array
(
self
.
index
)
self
.
ids
=
self
.
index
.
transpose
(
1
,
0
)[
2
]
self
.
executor
=
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
self
.
threads
)
def
__len__
(
self
):
return
len
(
self
.
index
)
//
self
.
bsz
def
shard
(
self
,
shuffle
=
False
):
def
shard
(
self
,
shuffle
=
False
,
epoch
=
1
,
seed
=
69
):
#get numpy random state
state
=
np
.
random
.
get_state
()
#set numpy seed
np
.
random
.
seed
(
seed
)
#use this function to shuffle every new epoch as well.
self
.
index
=
self
.
original_index
if
shuffle
:
#repeat index n_epoch times
self
.
index
=
np
.
repeat
(
self
.
index
,
epoch
,
axis
=
0
)
#shuffle the index
self
.
index
=
np
.
random
.
permutation
(
self
.
index
)
self
.
index
=
self
.
index
[:
len
(
self
.
index
)
-
(
len
(
self
.
index
)
%
(
self
.
bsz
*
self
.
world_size
))]
self
.
index
=
self
.
index
[
self
.
global_rank
::
self
.
world_size
]
return
self
.
index
#reset numpy random state
np
.
random
.
set_state
(
state
)
def
__getitem__
(
self
,
key
):
key
=
self
.
skip
+
key
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment