internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: tiangolo/fastapi

Issue:
FastAPI tests in pydantic failing due to flask deprecation
### Privileged issue

- [X] I'm @tiangolo or he asked me directly to create an issue here.

### Issue Content

hope you don't mind me creating an issue, pydantic's 1.10.X tests are failing due to a new issue with running our fastapi tests, see

https://github.com/pydantic/pydantic/actions/runs/4832692304/jobs/8611783607?pr=5628

output from pydantic's tests:

```
==================================== ERRORS ====================================
______ ERROR collecting tests/test_tutorial/test_wsgi/test_tutorial001.py ______
tests/test_tutorial/test_wsgi/test_tutorial001.py:3: in <module>
    from docs_src.wsgi.tutorial001 import app
docs_src/wsgi/tutorial001.py:3: in <module>
    from flask import Flask, escape, request
<frozen importlib._bootstrap>:1075: in _handle_fromlist
    ???
/opt/hostedtoolcache/Python/3.10.11/x64/lib/python3.10/site-packages/flask/__init__.py:71: in __getattr__
    warnings.warn(
E   DeprecationWarning: 'flask.escape' is deprecated and will be removed in Flask 2.4. Import 'markupsafe.escape' instead.
=========================== short test summary info ============================
ERROR tests/test_tutorial/test_wsgi/test_tutorial001.py - DeprecationWarning: 'flask.escape' is deprecated and will be removed in Flask 2.4. Import 'markupsafe.escape' 
```

related to https://github.com/pydantic/pydantic/pull/5628


Discussion:

Resolving patch:
diff --git a/docs_src/wsgi/tutorial001.py b/docs_src/wsgi/tutorial001.py
--- a/docs_src/wsgi/tutorial001.py
+++ b/docs_src/wsgi/tutorial001.py
@@ -1,6 +1,7 @@
 from fastapi import FastAPI
 from fastapi.middleware.wsgi import WSGIMiddleware
-from flask import Flask, escape, request
+from flask import Flask, request
+from markupsafe import escape
 
 flask_app = Flask(__name__)
 


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
Prepare model for inference
**Is your feature request related to a problem? Please describe.**
The first time inference occurs takes the longest, where as the next inferences afterwards are faster. Since normally the first time is in the sounddevice callback, it's likely that audio will not be processed in time and will end up delayed.

**Describe the solution you'd like**
After loading the model, run an initial inference with some dummy data, perhaps torch.zeros of appropriate sizes.

**Additional context**
On my computer with a RTX 3050, the first time inference takes about 3 seconds to complete. Otherwise I get a Realtime coef of ~28



Discussion:
As you said, I am not sure why, but it has improved very much. Thank you.

Resolving patch:
diff --git a/src/so_vits_svc_fork/inference_main.py b/src/so_vits_svc_fork/inference_main.py
--- a/src/so_vits_svc_fork/inference_main.py
+++ b/src/so_vits_svc_fork/inference_main.py
@@ -145,6 +145,21 @@ def realtime(
         f"Input Device: {devices[input_device]['name']}, Output Device: {devices[output_device]['name']}"
     )
 
+    # the model realtime coef is somewhat significantly low only in the first inference
+    # there could be no better way to warm up the model than to do a dummy inference
+    # (there are not differences in the behavior of the model between the first and the later inferences)
+    # so we do a dummy inference to warm up the model (1 second of audio)
+    LOG.info("Warming up the model...")
+    svc_model.infer(
+        speaker=speaker,
+        transpose=transpose,
+        auto_predict_f0=auto_predict_f0,
+        cluster_infer_ratio=cluster_infer_ratio,
+        noise_scale=noise_scale,
+        f0_method=f0_method,
+        audio=np.zeros(svc_model.target_sample, dtype=np.float32),
+    )
+
     def callback(
         indata: np.ndarray,
         outdata: np.ndarray,


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
AlsaOpen error
**Describe the bug**
Audio does not play using svcg

**To Reproduce**
Steps to reproduce the behaviour:
1. svcg
2. select a .wav file under "input audio path"
3. press the "play" button

**Additional context**
Add any other context about the problem here.
The following error appears when trying to play:
```Expression 'ret' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1736
Expression 'AlsaOpen( &alsaApi->baseHostApiRep, params, streamDir, &self->pcm )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 1904
Expression 'PaAlsaStreamComponent_Initialize( &self->playback, alsaApi, outParams, StreamDirection_Out, NULL != callback )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2175
Expression 'PaAlsaStream_Initialize( stream, alsaHostApi, inputParameters, outputParameters, sampleRate, framesPerBuffer, callback, streamFlags, userData )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2839
```
the .out.wav file is produced when clicking "infer" which can then be played normally.


Discussion:
I assume you can open it with librosa and can't open it with soundfile, can you modify the code to try?
```shell
data, sr = librosa.load(path)
```
https://github.com/34j/so-vits-svc-fork/blob/f3ec4b3711775ec18c3edf83eb3b12089f739dd2/src/so_vits_svc_fork/gui.py#L26

Resolving patch:
diff --git a/src/so_vits_svc_fork/gui.py b/src/so_vits_svc_fork/gui.py
--- a/src/so_vits_svc_fork/gui.py
+++ b/src/so_vits_svc_fork/gui.py
@@ -4,9 +4,9 @@
 from logging import getLogger
 from pathlib import Path
 
+import librosa
 import PySimpleGUI as sg
 import sounddevice as sd
-import soundfile as sf
 import torch
 from pebble import ProcessPool
 
@@ -22,7 +22,7 @@
 def play_audio(path: Path | str):
     if isinstance(path, Path):
         path = path.as_posix()
-    data, sr = sf.read(path)
+    data, sr = librosa.load(path)
     sd.play(data, sr)
 
 


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
"keep_ckpts" not working
In the config file, the default `"keep_ckpts": 3` does not work. When training, all checkpoints will be saved. Changing the value to any other number will not work as well.


Discussion:

Resolving patch:
diff --git a/src/so_vits_svc_fork/utils.py b/src/so_vits_svc_fork/utils.py
--- a/src/so_vits_svc_fork/utils.py
+++ b/src/so_vits_svc_fork/utils.py
@@ -441,14 +441,18 @@ def clean_checkpoints(
                           False -> lexicographically delete ckpts
     """
     path_to_models = Path(path_to_models)
-    name_key = lambda p: int(re.match(r"._(\d+)\.pth", p.name).group(1))
+    name_key = lambda p: int(re.match(r"._(\d+)", p.stem).group(1))
     time_key = lambda p: p.stat().st_mtime
     models_sorted = sorted(
-        path_to_models.glob(r"._(\d+).pth"), key=time_key if sort_by_time else name_key
+        filter(
+            lambda p: (p.is_file() and re.match(r"._\d+", p.stem)),
+            path_to_models.glob("*.pth"),
+        ),
+        key=time_key if sort_by_time else name_key,
     )
-    models_sorted_grouped = groupby(models_sorted, lambda p: p.name[0])
+    models_sorted_grouped = groupby(models_sorted, lambda p: p.stem[0])
     for k, g in models_sorted_grouped:
-        to_dels = list(g)[n_ckpts_to_keep:]
+        to_dels = list(g)[:-n_ckpts_to_keep]
         for to_del in to_dels:
             if to_del.stem.endswith("_0"):
                 continue


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
"keep_ckpts" not working
In the config file, the default `"keep_ckpts": 3` does not work. When training, all checkpoints will be saved. Changing the value to any other number will not work as well.


Discussion:
I noticed it earlier too. I am having difficulty correcting it.
I just updated to 1.2.8 but the bug is still present. All the checkpoints are still saved.
😭
After a bit of back and forth with ChatGPT and looking at the documentation for `itertools.groupby` it is an issue with how the models are sorted.

The resulting array of `models_sorted` is sorted by the suffix of the G_ or D_ files, but the resulting array alternates between a "G" path and a "D" path.
This, ultimately, means that it will create a group **for every G_ and D_ path**
![image](https://user-images.githubusercontent.com/1345036/227338841-4d21b6c3-e398-4504-b023-7386fb331d72.png)

I fixed this by modifying the `sorted` method call.

Additionally, I've cleaned up the code a bit more.
Will do a pull request shortly!

Resolving patch:
diff --git a/src/so_vits_svc_fork/utils.py b/src/so_vits_svc_fork/utils.py
--- a/src/so_vits_svc_fork/utils.py
+++ b/src/so_vits_svc_fork/utils.py
@@ -451,24 +451,35 @@ def clean_checkpoints(
     sort_by_time      --  True -> chronologically delete ckpts
                           False -> lexicographically delete ckpts
     """
+    LOG.warning("Cleaning old checkpoints...")
     path_to_models = Path(path_to_models)
-    name_key = lambda p: int(re.match(r"._(\d+)", p.stem).group(1))
+
+    # Define sort key functions
+    name_key = lambda p: int(re.match(r"[GD]_(\d+)", p.stem).group(1))
     time_key = lambda p: p.stat().st_mtime
-    models_sorted = sorted(
+    path_key = lambda p: (p.stem[0], time_key(p) if sort_by_time else name_key(p))
+
+    models = list(
         filter(
-            lambda p: (p.is_file() and re.match(r"._\d+", p.stem)),
+            lambda p: (
+                p.is_file()
+                and re.match(r"[GD]_\d+", p.stem)
+                and not p.stem.endswith("_0")
+            ),
             path_to_models.glob("*.pth"),
-        ),
-        key=time_key if sort_by_time else name_key,
+        )
     )
+
+    models_sorted = sorted(models, key=path_key)
+
     models_sorted_grouped = groupby(models_sorted, lambda p: p.stem[0])
-    for k, g in models_sorted_grouped:
-        to_dels = list(g)[:-n_ckpts_to_keep]
-        for to_del in to_dels:
-            if to_del.stem.endswith("_0"):
-                continue
-            LOG.warning(f"Removing {to_del}")
-            to_del.unlink()
+
+    for group_name, group_items in models_sorted_grouped:
+        to_delete_list = list(group_items)[:-n_ckpts_to_keep]
+
+        for to_delete in to_delete_list:
+            LOG.warning(f"Removing {to_delete}")
+            to_delete.unlink()
 
 
 def summarize(


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
Speaker not automatically set to 0 if not found when cluster_ratio != 0
**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior:

**Additional context**
Add any other context about the problem here.



Discussion:

Resolving patch:
diff --git a/src/so_vits_svc_fork/inference/infer_tool.py b/src/so_vits_svc_fork/inference/infer_tool.py
--- a/src/so_vits_svc_fork/inference/infer_tool.py
+++ b/src/so_vits_svc_fork/inference/infer_tool.py
@@ -189,6 +189,16 @@ def infer(
             else:
                 LOG.warning(f"Speaker {speaker} is not found. Use speaker 0 instead.")
                 speaker_id = 0
+        speaker_candidates = list(
+            filter(lambda x: x[1] == speaker_id, self.spk2id.__dict__.items())
+        )
+        if len(speaker_candidates) > 1:
+            raise ValueError(
+                f"Speaker_id {speaker_id} is not unique. Candidates: {speaker_candidates}"
+            )
+        elif len(speaker_candidates) == 0:
+            raise ValueError(f"Speaker_id {speaker_id} is not found.")
+        speaker = speaker_candidates[0][0]
         sid = torch.LongTensor([int(speaker_id)]).to(self.dev).unsqueeze(0)
 
         # get unit f0


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
svc pre-resample resamples to 22 kHz and then to 44 kHz
I have wav files in the dataset_raw in mono 44.1 kHz sample rate. When I run svc pre-resample, the files are saved in dataset folder and when I played them I noticed that they sound lower quality.
When I checked with a spectrogram, I noticed that the samples were half quality.
![image](https://user-images.githubusercontent.com/101394399/227764670-ca16c8d5-489f-49a9-b563-ff22fd356cbf.png)

Workaround: copy the wavs from dataset_raw to dataset folder.



Discussion:
This worst ever bug has made it necessary to retrain all my models......
> This worst ever bug has made it necessary to retrain all my models......

RIP. I always check all audio files with spectograms.
Also the Auto Play in svcg also plays at 22 kHz.


Resolving patch:
diff --git a/src/so_vits_svc_fork/gui.py b/src/so_vits_svc_fork/gui.py
--- a/src/so_vits_svc_fork/gui.py
+++ b/src/so_vits_svc_fork/gui.py
@@ -4,9 +4,9 @@
 from logging import getLogger
 from pathlib import Path
 
-import librosa
 import PySimpleGUI as sg
 import sounddevice as sd
+import soundfile as sf
 import torch
 from pebble import ProcessFuture, ProcessPool
 from tqdm.tk import tqdm_tk
@@ -24,7 +24,7 @@
 def play_audio(path: Path | str):
     if isinstance(path, Path):
         path = path.as_posix()
-    data, sr = librosa.load(path)
+    data, sr = sf.read(path)
     sd.play(data, sr)
 
 
diff --git a/src/so_vits_svc_fork/preprocess_resample.py b/src/so_vits_svc_fork/preprocess_resample.py
--- a/src/so_vits_svc_fork/preprocess_resample.py
+++ b/src/so_vits_svc_fork/preprocess_resample.py
@@ -9,6 +9,7 @@
 import librosa
 import numpy as np
 import soundfile
+import soundfile as sf
 from joblib import Parallel, delayed
 from tqdm_joblib import tqdm_joblib
 
@@ -58,7 +59,7 @@ def preprocess_one(input_path: Path, output_path: Path) -> None:
         """Preprocess one audio file."""
 
         try:
-            audio, sr = librosa.load(input_path)
+            audio, sr = sf.read(input_path)
 
         # Audioread is the last backend it will attempt, so this is the exception thrown on failure
         except audioread.exceptions.NoBackendError as e:
diff --git a/src/so_vits_svc_fork/preprocess_split.py b/src/so_vits_svc_fork/preprocess_split.py
--- a/src/so_vits_svc_fork/preprocess_split.py
+++ b/src/so_vits_svc_fork/preprocess_split.py
@@ -2,6 +2,7 @@
 from pathlib import Path
 
 import librosa
+import soundfile
 import soundfile as sf
 from joblib import Parallel, delayed
 from tqdm import tqdm
@@ -19,7 +20,7 @@ def _process_one(
     hop_seconds: float = 0.1,
 ):
     try:
-        audio, sr = librosa.load(input_path)
+        audio, sr = sf.read(input_path)
     except Exception as e:
         LOG.warning(f"Failed to read {input_path}: {e}")
         return


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
Illegal combination of I/O devices [PaErrorCode -9993]
**Describe the bug**
Whenever I try the realtime mode, I get this error: "Illegal combination of I/O devices [PaErrorCode -9993]"

**To Reproduce**
1. Press start voice changer button.
2. After a short time, that error appears.



Discussion:

Resolving patch:
diff --git a/src/so_vits_svc_fork/gui.py b/src/so_vits_svc_fork/gui.py
--- a/src/so_vits_svc_fork/gui.py
+++ b/src/so_vits_svc_fork/gui.py
@@ -460,7 +460,18 @@ def update_speaker() -> None:
             )
 
     def update_devices() -> None:
-        input_devices, output_devices, _, _ = get_devices()
+        (
+            input_devices,
+            output_devices,
+            input_device_indices,
+            output_device_indices,
+        ) = get_devices()
+        input_device_indices_reversed = {
+            v: k for k, v in enumerate(input_device_indices)
+        }
+        output_device_indices_reversed = {
+            v: k for k, v in enumerate(output_device_indices)
+        }
         window["input_device"].update(
             values=input_devices, value=values["input_device"]
         )
@@ -471,12 +482,12 @@ def update_devices() -> None:
         if values["input_device"] not in input_devices:
             window["input_device"].update(
                 values=input_devices,
-                set_to_index=0 if input_default is None else input_default - 1,
+                set_to_index=input_device_indices_reversed.get(input_default, 0),
             )
         if values["output_device"] not in output_devices:
             window["output_device"].update(
                 values=output_devices,
-                set_to_index=0 if output_default is None else output_default - 1,
+                set_to_index=output_device_indices_reversed.get(output_default, 0),
             )
 
     PRESET_KEYS = [


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
Learning rate (display) issue
**Describe the bug**
I have set a different learning rate (compared to the default 1e-4) as well as a different value of  lr_decay for my training in config.json.

However during training the lr displayed in Tensorboard shows a constant value of 1e-4 at any steps.

**To Reproduce**
Steps to reproduce the behavior:

Set a different  lr or lr_decay, observer the lr log in Tensorboard

**Additional context**
I wonder if this is a bug in display or the manually set lr and lr_decay is not used after lightning is implemented?



Discussion:

Resolving patch:
diff --git a/src/so_vits_svc_fork/train.py b/src/so_vits_svc_fork/train.py
--- a/src/so_vits_svc_fork/train.py
+++ b/src/so_vits_svc_fork/train.py
@@ -418,6 +418,11 @@ def training_step(self, batch: dict[str, torch.Tensor], batch_idx: int) -> None:
         optim_d.step()
         self.untoggle_optimizer(optim_d)
 
+        # end of epoch
+        if self.trainer.is_last_batch:
+            self.scheduler_g.step()
+            self.scheduler_d.step()
+
     def validation_step(self, batch, batch_idx):
         with torch.no_grad():
             self.net_g.eval()


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
Use RichProgressBar
**Is your feature request related to a problem? Please describe.**
We already include the `rich` package, so we can use it's progress bar as described here:

It'll look like this:
![image](https://user-images.githubusercontent.com/1345036/231591900-57088cdb-5b26-49d3-a876-dcf628b637b6.png)


**Describe the solution you'd like**
To implement the RichProgressBar

**Additional context**
All that's needed is to modify the trainer initialization as follow:
```python
    trainer = pl.Trainer(
        accelerator="auto",
        logger=TensorBoardLogger(model_path),
        # profiler="simple",
        val_check_interval=hparams.train.eval_interval,
        max_epochs=hparams.train.epochs,
        check_val_every_n_epoch=None,
        precision="16-mixed"
        if hparams.train.fp16_run
        # else "bf16-mixed"
        else "bf16-mixed"
        if hparams.train.get("bf16_run", False)
        else 32,
        callbacks=[pl.callbacks.RichProgressBar()] # <-- Add this here
    )
```

Since it's a one-line change I don't see a huge need to turn this into a full pull request. I hope that's okay 🙏 



Discussion:
I think it's fine. Please send a PR anyway.  (I would have to follow the same procedure if I were to do it)

Resolving patch:
diff --git a/src/so_vits_svc_fork/train.py b/src/so_vits_svc_fork/train.py
--- a/src/so_vits_svc_fork/train.py
+++ b/src/so_vits_svc_fork/train.py
@@ -82,6 +82,7 @@ def train(
         if hparams.train.get("bf16_run", False)
         else 32,
         strategy=strategy,
+        callbacks=[pl.callbacks.RichProgressBar()],
     )
     model = VitsLightning(reset_optimizer=reset_optimizer, **hparams)
     trainer.fit(model, datamodule=datamodule)


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
Use `version` parameter for TensorBoardLogger
**Is your feature request related to a problem? Please describe.**
Currently the TensorBoardLogger doesn't have a version parameter when initialized.
By default, it is `None`, and the documentation states:
> version ([Union](https://docs.python.org/3/library/typing.html#typing.Union)[[int](https://docs.python.org/3/library/functions.html#int), [str](https://docs.python.org/3/library/stdtypes.html#str), [None](https://docs.python.org/3/library/constants.html#None)]) – Experiment version. If version is not specified the logger inspects the save directory for existing versions, then automatically assigns the next available version. If it is a string then it is used as the run-specific subdirectory name, otherwise 'version_${version}' is used.

https://lightning.ai/docs/pytorch/stable/extensions/generated/lightning.pytorch.loggers.TensorBoardLogger.html

**Describe the solution you'd like**
An option in the model to define the experiment version so it will not start new ones like here:
![image](https://user-images.githubusercontent.com/1345036/231876558-bc2afa60-33a2-441e-8c6c-3e712415894c.png)
![image](https://user-images.githubusercontent.com/1345036/231877738-6c48e96b-5437-4f08-b775-4ec89009e00a.png)

It would instead use the already existing (or set) version and allow events to be contained within just that version.



Discussion:

Resolving patch:
diff --git a/src/so_vits_svc_fork/train.py b/src/so_vits_svc_fork/train.py
--- a/src/so_vits_svc_fork/train.py
+++ b/src/so_vits_svc_fork/train.py
@@ -75,7 +75,9 @@ def train(
     )
     LOG.info(f"Using strategy: {strategy}")
     trainer = pl.Trainer(
-        logger=TensorBoardLogger(model_path),
+        logger=TensorBoardLogger(
+            model_path, "lightning_logs", hparams.train.get("log_version", 0)
+        ),
         # profiler="simple",
         val_check_interval=hparams.train.eval_interval,
         max_epochs=hparams.train.epochs,


Test patch:
Repository: voicepaw/so-vits-svc-fork

Issue:
"TypedStorage is deprecated" while Training
**Describe the bug**
Spammy "TypedStorage is deprecated" warning on every epoch.

```
[23:52:12] WARNING  [23:52:12] C:\omited\venv\lib\site-packages\torch\_utils.py:776: UserWarning:        warnings.py:109
                    TypedStorage is deprecated. It will be removed in the future and UntypedStorage will
                    be the only storage class. This should only matter to you if you are using storages
                    directly.  To access UntypedStorage directly, use tensor.untyped_storage() instead
                    of tensor.storage()
                      return self.fget.__get__(instance, owner)()
```

**To Reproduce**
Simply train a voice.

**Additional context**
I updated to 3.6.1 today and start seeing the issue. Unfortunately I didn't know what was last good known version.

I'm training a voice using CREPE F0 predictor and using PyTorch 2.0.0 in Windows 11 if that matters.



Discussion:
From my understanding this is an issue with *some* library / package that this project is utilizing, as I can't find any usage of `tensor.storage()` or `TypedStorage` in general in the code

I don't know *which* package is using it and if it already has an updated version that uses `UntypedStorage` instead

This warning can be safely ignored for now as it shouldn't affect training 😁 (at least it doesn't for me) 
___
I noticed that it's spamming it for every DataLoader instance... if you want to disable that warning, change the following line in your venv:

Line 316 in `venv\lib\site-packages\torch\storage.py`
```py
    warnings.warn(message, UserWarning, stacklevel=stacklevel + 1)
```
to
```py
    # warnings.warn(message, UserWarning, stacklevel=stacklevel + 1)
```
___
It seems this was addressed in the development code for pytorch already here:
https://github.com/pytorch/pytorch/issues/97207
https://github.com/pytorch/pytorch/commit/fbc803df0c420db84429c51599f4fa4354b4493f

It hasn't been included in a new release, however, meaning we have to wait for 2.0.1.

The alternative would be to suppress the warning for the TypedStorage deprecation for the time being.

I'll quickly spin up a pull request for that 😄 

Resolving patch:
diff --git a/src/so_vits_svc_fork/logger.py b/src/so_vits_svc_fork/logger.py
--- a/src/so_vits_svc_fork/logger.py
+++ b/src/so_vits_svc_fork/logger.py
@@ -1,5 +1,6 @@
 import os
 import sys
+import warnings
 from logging import (
     DEBUG,
     INFO,
@@ -35,6 +36,9 @@ def init_logger() -> None:
     if IS_TEST:
         getLogger(package_name).setLevel(DEBUG)
     captureWarnings(True)
+    warnings.filterwarnings(
+        "ignore", category=UserWarning, message="TypedStorage is deprecated"
+    )
     LOGGER_INIT = True
 
 


Test patch: