Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve HF integration #16

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion model.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import torch
from torch import Tensor, nn

from huggingface_hub import PyTorchModelHubMixin

from modules.layers import (DoubleStreamBlock, EmbedND, LastLayer,
MLPEmbedder, SingleStreamBlock,
timestep_embedding)
Expand All @@ -24,7 +26,7 @@ class FluxParams:
guidance_embed: bool


class Flux(nn.Module):
class Flux(nn.Module, PyTorchModelHubMixin, repo_url="https://github.com/feizc/FluxMusic", pipeline_tag="text-to-audio", tags=["text-to-music"], license="apache-2.0"):
"""
Transformer model for flow matching on sequences.
"""
Expand Down
9 changes: 3 additions & 6 deletions sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,9 @@ def main(args):

latent_size = (256, 16)

model = build_model(args.version).to(device)
local_path = args.ckpt_path
state_dict = torch.load(local_path, map_location=lambda storage, loc: storage)
model.load_state_dict(state_dict['ema'])
model.eval() # important!
repo_id = f"feizhengcong/FluxMusic-{args.version}"
model.from_pretrained(repo_id)
model.to(device)
diffusion = RF()

# Setup VAE
Expand Down Expand Up @@ -112,7 +110,6 @@ def main(args):
parser = argparse.ArgumentParser()
parser.add_argument("--version", type=str, default="small")
parser.add_argument("--prompt_file", type=str, default='config/example.txt')
parser.add_argument("--ckpt_path", type=str, default='musicflow_s.pt')
parser.add_argument("--audioldm2_model_path", type=str, default='/maindata/data/shared/multimodal/public/dataset_music/audioldm2' )
parser.add_argument("--seed", type=int, default=2024)
args = parser.parse_args()
Expand Down