Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
H
Hydra Node Http
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
Hydra Node Http
Commits
c1b0e089
Commit
c1b0e089
authored
Aug 21, 2022
by
kurumuz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vectoradjustprior support
parent
d22bf3c7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
1 deletion
+30
-1
hydra_node/config.py
hydra_node/config.py
+1
-0
hydra_node/models.py
hydra_node/models.py
+28
-1
main.py
main.py
+1
-0
No files found.
hydra_node/config.py
View file @
c1b0e089
...
@@ -92,6 +92,7 @@ def init_config_model():
...
@@ -92,6 +92,7 @@ def init_config_model():
# Resolve where we get our model and data from.
# Resolve where we get our model and data from.
config
.
model_path
=
os
.
getenv
(
'MODEL_PATH'
,
None
)
config
.
model_path
=
os
.
getenv
(
'MODEL_PATH'
,
None
)
config
.
prior_path
=
os
.
getenv
(
'PRIOR_PATH'
,
None
)
# Misc settings
# Misc settings
config
.
model_alias
=
os
.
getenv
(
'MODEL_ALIAS'
)
config
.
model_alias
=
os
.
getenv
(
'MODEL_ALIAS'
)
...
...
hydra_node/models.py
View file @
c1b0e089
...
@@ -99,6 +99,29 @@ def decode_image(image, model):
...
@@ -99,6 +99,29 @@ def decode_image(image, model):
image
=
custom_to_pil
(
image
)
image
=
custom_to_pil
(
image
)
return
image
return
image
class
VectorAdjustPrior
(
nn
.
Module
):
def
__init__
(
self
,
hidden_size
,
inter_dim
=
64
):
super
()
.
__init__
()
self
.
vector_proj
=
nn
.
Linear
(
hidden_size
*
2
,
inter_dim
,
bias
=
True
)
self
.
out_proj
=
nn
.
Linear
(
hidden_size
+
inter_dim
,
hidden_size
,
bias
=
True
)
def
forward
(
self
,
z
):
b
,
s
=
z
.
shape
[
0
:
2
]
x1
=
torch
.
mean
(
z
,
dim
=
1
)
.
repeat
(
s
,
1
)
x2
=
z
.
reshape
(
b
*
s
,
-
1
)
x
=
torch
.
cat
((
x1
,
x2
),
dim
=
1
)
x
=
self
.
vector_proj
(
x
)
x
=
torch
.
cat
((
x2
,
x
),
dim
=
1
)
x
=
self
.
out_proj
(
x
)
x
=
x
.
reshape
(
b
,
s
,
-
1
)
return
x
@
classmethod
def
load_model
(
cls
,
model_path
,
hidden_size
=
768
,
inter_dim
=
64
):
model
=
cls
(
hidden_size
=
hidden_size
,
inter_dim
=
inter_dim
)
model
.
load_state_dict
(
torch
.
load
(
model_path
)[
"state_dict"
])
return
model
class
StableInterface
(
nn
.
Module
):
class
StableInterface
(
nn
.
Module
):
def
__init__
(
self
,
model
,
thresholder
=
None
):
def
__init__
(
self
,
model
,
thresholder
=
None
):
super
()
.
__init__
()
super
()
.
__init__
()
...
@@ -145,6 +168,8 @@ class StableDiffusionModel(nn.Module):
...
@@ -145,6 +168,8 @@ class StableDiffusionModel(nn.Module):
'k_dpm_2_ancestral'
:
K
.
sampling
.
sample_dpm_2_ancestral
,
'k_dpm_2_ancestral'
:
K
.
sampling
.
sample_dpm_2_ancestral
,
'k_lms'
:
K
.
sampling
.
sample_lms
,
'k_lms'
:
K
.
sampling
.
sample_lms
,
}
}
if
config
.
prior_path
:
self
.
prior
=
VectorAdjustPrior
.
load_model
(
config
.
prior_path
,
hidden_size
=
model_config
[
'hidden_size'
])
def
from_folder
(
self
,
folder
):
def
from_folder
(
self
,
folder
):
folder
=
Path
(
folder
)
folder
=
Path
(
folder
)
...
@@ -213,6 +238,8 @@ class StableDiffusionModel(nn.Module):
...
@@ -213,6 +238,8 @@ class StableDiffusionModel(nn.Module):
prompt
=
[
request
.
prompt
]
*
request
.
n_samples
prompt
=
[
request
.
prompt
]
*
request
.
n_samples
prompt_condition
=
prompt_mixing
(
self
.
model
,
prompt
[
0
],
request
.
n_samples
)
prompt_condition
=
prompt_mixing
(
self
.
model
,
prompt
[
0
],
request
.
n_samples
)
if
self
.
prior
and
request
.
mitigate
:
prompt_condition
=
self
.
prior
(
prompt_condition
)
uc
=
None
uc
=
None
if
request
.
scale
!=
1.0
:
if
request
.
scale
!=
1.0
:
...
@@ -253,7 +280,7 @@ class StableDiffusionModel(nn.Module):
...
@@ -253,7 +280,7 @@ class StableDiffusionModel(nn.Module):
else
:
else
:
start_code
=
start_code
*
sigmas
[
0
]
start_code
=
start_code
*
sigmas
[
0
]
extra_args
=
{
'cond'
:
prompt_condition
,
'uncond'
:
uc
,
'cond_scale'
:
request
.
scale
}
extra_args
=
{
'cond'
:
prompt_condition
,
'uncond'
:
uc
,
'cond_scale'
:
request
.
scale
}
samples
=
self
.
sampler_map
[
request
.
sampler
](
self
.
k_model
,
start_code
,
sigmas
,
extra_args
=
extra_args
)
samples
=
self
.
sampler_map
[
request
.
sampler
](
self
.
k_model
,
start_code
,
sigmas
,
extra_args
=
extra_args
)
...
...
main.py
View file @
c1b0e089
...
@@ -74,6 +74,7 @@ class GenerationRequest(BaseModel):
...
@@ -74,6 +74,7 @@ class GenerationRequest(BaseModel):
stage_two_seed
:
int
=
None
stage_two_seed
:
int
=
None
strength
:
float
=
0.69
strength
:
float
=
0.69
noise
:
float
=
0.667
noise
:
float
=
0.667
mitigate
:
bool
=
False
class
GenerationOutput
(
BaseModel
):
class
GenerationOutput
(
BaseModel
):
output
:
List
[
str
]
output
:
List
[
str
]
...
...
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