Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
supr
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mnsc
supr
Commits
da96baed
Commit
da96baed
authored
3 years ago
by
mnsc
Browse files
Options
Downloads
Patches
Plain Diff
added sequential layer
parent
8204da3f
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
supr/layers.py
+20
-6
20 additions, 6 deletions
supr/layers.py
supr/utils.py
+5
-0
5 additions, 0 deletions
supr/utils.py
with
25 additions
and
6 deletions
supr/layers.py
+
20
−
6
View file @
da96baed
import
torch
import
torch
import
torch.nn
as
nn
from
torch.nn.functional
import
pad
import
math
...
...
@@ -8,10 +7,10 @@ from typing import List
# Data:
# N x V
x C
# └───│──
─│─
N: Data points
# └──
─│─
V: Variables
#
└─ C: Channels
# N x V
# └───│── N: Data points
# └── V: Variables
#
# Probability:
# N x T x V x C
# └───│───│───│─ N: Data points
...
...
@@ -31,13 +30,28 @@ class SuprLayer(nn.Module):
def
em_update
(
self
,
*
args
,
**
kwargs
):
pass
class
SuprSequential
(
nn
.
Sequential
):
def
__init__
(
self
,
*
args
):
super
().
__init__
(
*
args
)
def
em_batch_update
(
self
):
with
torch
.
no_grad
():
for
module
in
self
:
module
.
em_batch
()
module
.
em_update
()
def
sample
(
self
):
value
=
[]
for
module
in
reversed
(
self
):
value
=
module
.
sample
(
*
value
)
return
value
class
Parallel
(
SuprLayer
):
def
__init__
(
self
,
nets
:
List
[
SuprLayer
]):
super
().
__init__
()
self
.
nets
=
nets
def
forward
(
self
,
x
:
torch
.
Tensor
):
def
forward
(
self
,
x
:
List
[
torch
.
Tensor
]
):
return
[
n
(
x
)
for
n
,
x
in
zip
(
self
.
nets
,
x
)]
...
...
This diff is collapsed.
Click to expand it.
supr/utils.py
+
5
−
0
View file @
da96baed
...
...
@@ -63,3 +63,8 @@ def local_scramble_2d(dist: float, dim: tuple):
n
=
[
torch
.
argsort
(
m
+
torch
.
randn
(
dim
)
*
dist
,
dim
=
i
)
for
i
,
m
in
enumerate
(
grid
)]
idx
=
torch
.
reshape
(
torch
.
arange
(
torch
.
tensor
(
dim
).
prod
()),
dim
)
return
idx
[
n
[
0
],
grid
[
1
]][
grid
[
0
],
n
[
1
]].
flatten
()
def
bsgen
(
v
,
v0
):
while
v
>
v0
:
yield
v
v
=
math
.
ceil
(
v
/
2
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment