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

feat: add support for pytorch compile of the codec model #365

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
7 changes: 6 additions & 1 deletion bark/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _cast_bool_env_var(s):
USE_SMALL_MODELS = _cast_bool_env_var(os.environ.get("SUNO_USE_SMALL_MODELS", "False"))
GLOBAL_ENABLE_MPS = _cast_bool_env_var(os.environ.get("SUNO_ENABLE_MPS", "False"))
OFFLOAD_CPU = _cast_bool_env_var(os.environ.get("SUNO_OFFLOAD_CPU", "False"))

DISABLE_COMPILE = _cast_bool_env_var(os.environ.get("SUNO_DISABLE_COMPILE", "False"))

REMOTE_MODEL_PATHS = {
"text_small": {
Expand Down Expand Up @@ -254,6 +254,11 @@ def _load_codec_model(device):
model.set_target_bandwidth(6.0)
model.eval()
model.to(device)
if callable(getattr(torch, "compile")) and not DISABLE_COMPILE:
logger.info("torch.compile available, compiling codec model.")
model = torch.compile(model)
else:
logger.info("torch.compile *not* available, you will get better performance if you use pytorch >= 2.0.")
_clear_cuda_cache()
return model

Expand Down