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
Nuomanzz
TangoFlux
Commits
e8a362f1
Commit
e8a362f1
authored
Dec 29, 2024
by
hungchiayu1
Browse files
update gitignore
parent
f0877951
Changes
2
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
137 additions
and
51 deletions
+137
-51
Inference.ipynb
Inference.ipynb
+137
-0
inference.py
inference.py
+0
-51
No files found.
Inference.ipynb
0 → 100644
View file @
e8a362f1
This diff is collapsed.
Click to expand it.
inference.py
deleted
100644 → 0
View file @
f0877951
from
diffusers
import
AutoencoderOobleck
import
torch
from
transformers
import
T5EncoderModel
,
T5TokenizerFast
from
diffusers
import
FluxTransformer2DModel
from
torch
import
nn
from
typing
import
List
from
diffusers
import
FlowMatchEulerDiscreteScheduler
from
diffusers.training_utils
import
compute_density_for_timestep_sampling
import
copy
import
torch.nn.functional
as
F
import
numpy
as
np
from
tqdm
import
tqdm
from
typing
import
Optional
,
Union
,
List
from
datasets
import
load_dataset
,
Audio
from
math
import
pi
import
inspect
import
yaml
from
safetensors.torch
import
load_file
class
TangoFluxInference
:
def
__init__
(
self
,
path
=
'declare-lab/TangoFlux'
,
device
=
"cuda"
):
self
.
vae
=
AutoencoderOobleck
.
from_pretrained
(
"stabilityai/stable-audio-open-1.0"
,
subfolder
=
'vae'
)
weights
=
load_file
(
"{}/tangoflux.safetensors"
.
format
(
paths
))
with
open
(
'{}/config.json'
.
format
(
paths
),
'r'
)
as
f
:
config
=
json
.
load
(
f
)
self
.
model
=
TangoFlux
(
config
)
self
.
model
.
load_state_dict
(
weights
,
strict
=
False
)
# _IncompatibleKeys(missing_keys=['text_encoder.encoder.embed_tokens.weight'], unexpected_keys=[]) this behaviour is expected
self
.
vae
.
to
(
device
)
self
.
model
.
to
(
device
)
def
generate
(
self
,
prompt
,
steps
=
25
,
duration
=
10
,
guidance_scale
=
4.5
):
with
torch
.
no_grad
():
latents
=
self
.
model
.
inference_flow
(
prompt
,
duration
=
duration
,
num_inference_steps
=
steps
,
guidance_scale
=
guidance_scale
)
wave
=
self
.
vae
.
decode
(
latents
.
transpose
(
2
,
1
)).
sample
.
cpu
()[
0
]
return
wave
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