diff --git a/.github/workflows/checksum.yml b/.github/workflows/checksum.yml index 11ff840..77233c6 100644 --- a/.github/workflows/checksum.yml +++ b/.github/workflows/checksum.yml @@ -13,7 +13,7 @@ jobs: - name: Run RVC-Models-Downloader run: | - wget https://github.com/fumiama/RVC-Models-Downloader/releases/download/v0.2.10/rvcmd_linux_amd64.deb + wget https://github.com/fumiama/RVC-Models-Downloader/releases/download/v0.2.11/rvcmd_linux_amd64.deb sudo apt -y install ./rvcmd_linux_amd64.deb rm -f ./rvcmd_linux_amd64.deb rvcmd -notrs -w 1 -notui assets/chtts diff --git a/ChatTTS/model/gpt.py b/ChatTTS/model/gpt.py index 41076f6..832fd1e 100644 --- a/ChatTTS/model/gpt.py +++ b/ChatTTS/model/gpt.py @@ -162,7 +162,7 @@ class GPT(nn.Module): def _prepare_generation_inputs( self, input_ids: torch.Tensor, - past_key_values: Optional[Tuple[Tuple[torch.FloatTensor]]] = None, + past_key_values: Optional[Union[Tuple[Tuple[torch.FloatTensor]], Cache]] = None, attention_mask: Optional[torch.Tensor] = None, inputs_embeds: Optional[torch.Tensor] = None, cache_position: Optional[torch.Tensor] = None, @@ -180,28 +180,30 @@ class GPT(nn.Module): has_static_cache = past_key_values is not None past_length = 0 + max_cache_length = None + cache_length = 0 if past_key_values is not None: if isinstance(past_key_values, Cache): - past_length = ( - int(cache_position[0]) - if cache_position is not None - else past_key_values.get_seq_length() - ) - try: - max_cache_length = past_key_values.get_max_cache_shape() - except: - max_cache_length = ( - past_key_values.get_max_length() - ) # deprecated in transformers 4.48 - cache_length = ( - past_length - if max_cache_length is None - else min(max_cache_length, past_length) - ) + if past_key_values.layers and len(past_key_values.layers): + past_length = ( + int(cache_position[0]) + if cache_position is not None + else past_key_values.get_seq_length() + ) + try: + max_cache_length = past_key_values.get_max_cache_shape() + except: + max_cache_length = ( + past_key_values.get_max_length() + ) # deprecated in transformers 4.48 + cache_length = ( + past_length + if max_cache_length is None + else min(max_cache_length, past_length) + ) # TODO joao: remove this `else` after `generate` prioritizes `Cache` objects else: cache_length = past_length = past_key_values[0][0].shape[2] - max_cache_length = None # Keep only the unprocessed tokens: # 1 - If the length of the attention_mask exceeds the length of input_ids, then we are in a setting where @@ -224,11 +226,13 @@ class GPT(nn.Module): # If we are about to go beyond the maximum cache length, we need to crop the input attention mask. if ( max_cache_length is not None + and max_cache_length > 0 and attention_mask is not None and cache_length + input_ids.shape[1] > max_cache_length ): + start_pos = attention_mask.shape[1] - max_cache_length attention_mask = attention_mask.narrow( - 1, -max_cache_length, max_cache_length + 1, start_pos, max_cache_length ) if attention_mask is not None and position_ids is None: diff --git a/ChatTTS/utils/dl.py b/ChatTTS/utils/dl.py index 2cdd649..b70303a 100644 --- a/ChatTTS/utils/dl.py +++ b/ChatTTS/utils/dl.py @@ -143,15 +143,7 @@ def download_and_extract_zip( logger.get_logger().info(f"extracted into {folder}") -def download_dns_yaml(url: str, folder: str, headers: Dict[str, str]): - logger.get_logger().info(f"downloading {url}") - response = requests.get(url, headers=headers, stream=True, timeout=(100, 3)) - with open(os.path.join(folder, "dns.yaml"), "wb") as out_file: - out_file.write(response.content) - logger.get_logger().info(f"downloaded into {folder}") - - -def download_all_assets(tmpdir: str, homedir: str, version="0.2.10"): +def download_all_assets(tmpdir: str, homedir: str, version="0.2.11"): import subprocess import platform @@ -175,48 +167,15 @@ def download_all_assets(tmpdir: str, homedir: str, version="0.2.10"): if not architecture: logger.get_logger().error(f"architecture {architecture} is not supported") exit(1) - try: - BASE_URL = "https://github.com/fumiama/RVC-Models-Downloader/releases/download/" - suffix = "zip" if is_win else "tar.gz" - RVCMD_URL = BASE_URL + f"v{version}/rvcmd_{system_type}_{architecture}.{suffix}" - cmdfile = os.path.join(tmpdir, "rvcmd") - if is_win: - download_and_extract_zip(RVCMD_URL, tmpdir) - cmdfile += ".exe" - else: - download_and_extract_tar_gz(RVCMD_URL, tmpdir) - os.chmod(cmdfile, 0o755) - subprocess.run([cmdfile, "-notui", "-w", "0", "-H", homedir, "assets/chtts"]) - except Exception: - BASE_URL = ( - "https://gitea.seku.su/fumiama/RVC-Models-Downloader/releases/download/" - ) - suffix = "zip" if is_win else "tar.gz" - RVCMD_URL = BASE_URL + f"v{version}/rvcmd_{system_type}_{architecture}.{suffix}" - download_dns_yaml( - "https://gitea.seku.su/fumiama/RVC-Models-Downloader/raw/branch/main/dns.yaml", - tmpdir, - headers={ - "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0" - }, - ) - cmdfile = os.path.join(tmpdir, "rvcmd") - if is_win: - download_and_extract_zip(RVCMD_URL, tmpdir) - cmdfile += ".exe" - else: - download_and_extract_tar_gz(RVCMD_URL, tmpdir) - os.chmod(cmdfile, 0o755) - subprocess.run( - [ - cmdfile, - "-notui", - "-w", - "0", - "-dns", - os.path.join(tmpdir, "dns.yaml"), - "-H", - homedir, - "assets/chtts", - ] - ) + + BASE_URL = "https://github.com/fumiama/RVC-Models-Downloader/releases/download/" + suffix = "zip" if is_win else "tar.gz" + RVCMD_URL = BASE_URL + f"v{version}/rvcmd_{system_type}_{architecture}.{suffix}" + cmdfile = os.path.join(tmpdir, "rvcmd") + if is_win: + download_and_extract_zip(RVCMD_URL, tmpdir) + cmdfile += ".exe" + else: + download_and_extract_tar_gz(RVCMD_URL, tmpdir) + os.chmod(cmdfile, 0o755) + subprocess.run([cmdfile, "-notui", "-w", "0", "-H", homedir, "assets/chtts"]) diff --git a/examples/web/webui.py b/examples/web/webui.py index a2bcf9e..2f8e60c 100644 --- a/examples/web/webui.py +++ b/examples/web/webui.py @@ -116,14 +116,14 @@ def main(): spk_emb_text = gr.Textbox( label="Speaker Embedding", max_lines=3, - show_copy_button=True, + buttons=["copy"], interactive=True, scale=2, ) dvae_coef_text = gr.Textbox( label="DVAE Coefficient", max_lines=3, - show_copy_button=True, + buttons=["copy"], interactive=True, scale=2, ) @@ -161,7 +161,7 @@ def main(): text_output = gr.Textbox( label="Output Text", interactive=False, - show_copy_button=True, + buttons=["copy"], ) sample_audio_input.change( @@ -279,7 +279,7 @@ def main(): server_port=args.server_port, root_path=args.root_path, inbrowser=True, - show_api=False, + footer_links=['api', 'gradio', 'settings'], )