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
cb67abcb
Commit
cb67abcb
authored
Jul 04, 2022
by
novelailab
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
make so can transfer to cuda after reduced
parent
5c846daf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
4 deletions
+9
-4
basedformer/dataset.py
basedformer/dataset.py
+9
-4
No files found.
basedformer/dataset.py
View file @
cb67abcb
...
...
@@ -46,7 +46,7 @@ class ShardedDataset(data.Dataset):
class
ShardedImageDataset
(
data
.
Dataset
):
def
__init__
(
self
,
dataset_path
:
str
,
metadata_path
:
str
,
threads
=
None
,
inner_transform
=
None
,
outer_transform
=
None
,
skip
=
0
,
bsz
=
256
,
world_size
=
1
,
rank
=
0
):
outer_transform
=
None
,
skip
=
0
,
bsz
=
256
,
world_size
=
1
,
local_rank
=
0
,
global_rank
=
0
,
device
=
"cpu"
):
self
.
skip
=
skip
self
.
threads
=
threads
...
...
@@ -57,7 +57,9 @@ class ShardedImageDataset(data.Dataset):
self
.
outer_transform
=
outer_transform
self
.
dataset_path
=
dataset_path
self
.
world_size
=
world_size
self
.
rank
=
rank
self
.
local_rank
=
local_rank
self
.
global_rank
=
global_rank
self
.
device
=
device
with
open
(
metadata_path
,
'rb'
)
as
f
:
self
.
metadata
=
pickle
.
load
(
f
)
...
...
@@ -69,7 +71,7 @@ class ShardedImageDataset(data.Dataset):
self
.
metadata
=
self
.
metadata
[:
len
(
self
.
metadata
)
-
(
len
(
self
.
metadata
)
%
(
bsz
*
world_size
))]
#shard the dataset according to the rank
self
.
metadata
=
self
.
metadata
[
rank
::
world_size
]
self
.
metadata
=
self
.
metadata
[
global_
rank
::
world_size
]
#override possible gil locks by making the metadata map an nparray
self
.
metadata
=
np
.
array
(
self
.
metadata
)
self
.
executor
=
concurrent
.
futures
.
ThreadPoolExecutor
(
max_workers
=
self
.
threads
)
...
...
@@ -85,6 +87,9 @@ class ShardedImageDataset(data.Dataset):
#make sure these operations are fast!
ids
=
[
t
[
1
]
for
t
in
tensors
]
tensors
=
torch
.
stack
([
t
[
0
]
for
t
in
tensors
])
if
self
.
device
==
"cuda"
:
tensors
=
tensors
.
to
(
self
.
local_rank
)
tensors
=
tensors
.
permute
(
0
,
3
,
1
,
2
)
.
float
()
#####################################
if
self
.
outer_transform
:
...
...
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