Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
412d3ff5
Commit
412d3ff5
authored
Nov 11, 2023
by
comfyanonymous
Browse files
Refactor.
parent
ca2812ba
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
15 deletions
+9
-15
comfy/ops.py
comfy/ops.py
+9
-15
No files found.
comfy/ops.py
View file @
412d3ff5
import
torch
import
torch
from
contextlib
import
contextmanager
from
contextlib
import
contextmanager
class
Linear
(
torch
.
nn
.
Module
):
class
Linear
(
torch
.
nn
.
Linear
):
def
__init__
(
self
,
in_features
:
int
,
out_features
:
int
,
bias
:
bool
=
True
,
def
reset_parameters
(
self
):
device
=
None
,
dtype
=
None
)
->
None
:
return
None
factory_kwargs
=
{
'device'
:
device
,
'dtype'
:
dtype
}
super
().
__init__
()
self
.
in_features
=
in_features
self
.
out_features
=
out_features
self
.
weight
=
torch
.
nn
.
Parameter
(
torch
.
empty
((
out_features
,
in_features
),
**
factory_kwargs
))
if
bias
:
self
.
bias
=
torch
.
nn
.
Parameter
(
torch
.
empty
(
out_features
,
**
factory_kwargs
))
else
:
self
.
register_parameter
(
'bias'
,
None
)
def
forward
(
self
,
input
):
return
torch
.
nn
.
functional
.
linear
(
input
,
self
.
weight
,
self
.
bias
)
class
Conv2d
(
torch
.
nn
.
Conv2d
):
class
Conv2d
(
torch
.
nn
.
Conv2d
):
def
reset_parameters
(
self
):
def
reset_parameters
(
self
):
return
None
return
None
class
Conv3d
(
torch
.
nn
.
Conv3d
):
def
reset_parameters
(
self
):
return
None
def
conv_nd
(
dims
,
*
args
,
**
kwargs
):
def
conv_nd
(
dims
,
*
args
,
**
kwargs
):
if
dims
==
2
:
if
dims
==
2
:
return
Conv2d
(
*
args
,
**
kwargs
)
return
Conv2d
(
*
args
,
**
kwargs
)
elif
dims
==
3
:
return
Conv3d
(
*
args
,
**
kwargs
)
else
:
else
:
raise
ValueError
(
f
"unsupported dimensions:
{
dims
}
"
)
raise
ValueError
(
f
"unsupported dimensions:
{
dims
}
"
)
...
...
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