#๐Ÿ”’ Function exits silently; proceeding lines do not run; Debug/Try-Except Reveal nothing

65 messages ยท Page 1 of 1 (latest)

somber snow
#

https://pastebin.com/cNKDr1M4
This is a test script for a STT tool I'm making. The purpose of the tool is to identify a pokemon name from speech, and then display relevant information.
I'm currently working on the STT portion. I'm using the faster-whisper model, and fuzzymatching to identify the pokemon name from speech correctly.
The test script has a function, compare_transaction() which iterates over 251 pokemon name recordings, transcribes each one, and puts information about the transcription into a dictionary. compare_transaction() then returns the dictionary.

I call the compare_transaction() function on line 52. All the code from this function runs and the loop completes. In vscode debug, I can see the data variable is a dict and, before the function has fully exited, has all 251 pokemon names as keys. The following print statements, and json.dump do not run. The print statements are not shown in the terminal, and the json file is not written.
If I modify compare_transaction() to run a limited number of times, it will run the print/json statements successfully. I have not tested this exhaustively, so as to find the "edge" of where this will fail or succeed, and have only limited the loop to running 10 times to see if it would work.

I would really appreciate any help understanding why this apparently fails without any errors. I have posted this previously. I was recommended to use the debugger with breakpoints, but unfortunately this didn't reveal anything. I'm hoping for some additional insight.

jovial monolithBOT
#

@somber snow

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

somber snow
#

OS: Windows 10
IDE: VS Code
Python: 3.11.3
venv: Yes
pip freeze:

attrs==23.2.0
av==11.0.0
beautifulsoup4==4.12.3
cattrs==23.2.3        
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
colorama==0.4.6
coloredlogs==15.0.1
ctranslate2==4.0.0
enum34==1.1.10
faster-whisper==0.10.0
filelock==3.9.0
flatbuffers==23.5.26
fsspec==2024.2.0
fuzzywuzzy==0.18.0
halo==0.0.31
html5lib==1.1
huggingface-hub==0.20.3
humanfriendly==10.0
idna==3.6
Jinja2==3.1.2
Levenshtein==0.25.0
log-symbols==0.0.14
lxml==5.1.0
MarkupSafe==2.1.3
mpmath==1.3.0
natsort==8.4.0
networkx==3.2.1
numpy==1.26.4
onnxruntime==1.17.0
packaging==23.2
pandas==2.2.1
platformdirs==4.2.0
pokebase==1.4.1
protobuf==4.25.3
pvporcupine==1.9.5
PyAudio==0.2.14
pycparser==2.21
pyreadline3==3.4.1
python-dateutil==2.8.2
python-Levenshtein==0.25.0
pytz==2024.1
PyYAML==6.0.1
rapidfuzz==3.6.1
RealTimeSTT==0.1.9
requests==2.31.0
requests-cache==1.2.0
scipy==1.12.0
six==1.16.0
sounddevice==0.4.6
soundfile==0.12.1
soupsieve==2.5
spinners==0.0.24
sympy==1.12
termcolor==2.4.0
tokenizers==0.15.2
torch==2.1.2+cu118
torchaudio==2.1.2+cu118
tqdm==4.66.2
typing_extensions==4.8.0
tzdata==2024.1
url-normalize==1.4.3
urllib3==2.2.1
webencodings==0.5.1
webrtcvad==2.0.10
runic moat
#

Did you try putting print statements inside compare_transcription to see where it's having trouble?

#

That would be my next step.

somber snow
#

maybe it's just my vscode terminal settings though

runic moat
#

You said it will run a limited number of times so my suspicion is that something is growing asymptotically.

somber snow
#

It will run to completion and the debug variable inspector shows data and it appears normal

#

i can artificially stop it at 10 and it will run normally

#

that makes sense though. i think you're probably right

#

something i just noticed is that if i limit the loop by putting this at the bottom of the for loop, it will print 31 as the last statement

if i > 29:
  break
#

i would think 30 should be the last statement that gets printed from print(len(data)) in this case

#

also, the statements after the function call in main do not run even when the loop is limited to running 30 times

runic moat
#

Does the program just stop or does it hang?

somber snow
#

it brings me back to the terminal prompt without any intervention

#

so it appears to just stop

#
30
31

(venv) D:\Programming\Python\pokemon-helper\src>
runic moat
#

I'm not familiar with whisper_model - are you running the model locally?

somber snow
#

yes

runic moat
#

I'd look at memory usage if so

#

see if anything weird happens

somber snow
#

i get closer to the 8GB mark with the large model so i've been using medium for testing

#

i believe i had the same results with the tiny model but i will try again here

#

yeah same result

runic moat
#

Hmm. Sorry, wish I was more help.

somber snow
#

I really appreciate the brainstorm

runic moat
#

I suspect the data though.

#

I'm looking at the project on github right now.

#

It says the medium.en model performs better than medium - are you using English exclusively?

somber snow
#

im going to try breaking the transcription into its own function... i have a gut feeling that will help

somber snow
runic moat
#

how long are the audio files?

somber snow
#

3 seconds

runic moat
#

So that's probably not the issue. Is the GPU throttling?

#

maybe it's getting hot

somber snow
#

its at 58ยฐC

#

not sure what rate task man is reading the temp at but i havent seen it above 80 during my previous tests

runic moat
#

I'm not sure, I'd have to look at it more closely to see if I understand.

somber snow
#

I moved the below into a function

        segments, info = model.transcribe(recording_path, beam_size=5)
        original_transcribed = list(segments)[0].text.lower().rstrip('.')

->

def transcribe_recording(recording_path,model=WhisperModel("tiny", device="cuda", compute_type="float32")):
    segments, info = model.transcribe(recording_path, beam_size=5)
    original_transcribed = list(segments)[0].text.lower().rstrip('.')
    return original_transcribed, info

then called the function in the for loop

original_transcribed, info = transcribe_recording(recording_path)
runic moat
#

Yeah the only real difference is using the tiny model afaict

somber snow
#

i will run it with large, it will take like 10 mins

runic moat
#

That's really interesting that isolating that solves the issue.

somber snow
#

so, the rational i had was:
-segments is a generator
-it's being run in a for loop
-maybe thats bad?

#

brainlet brainlet degree of troubleshooting

runic moat
#

yeah if model.transcribe returns a generator that increases the complexity exponentially

#

I didn't know what it returned

#

glad you figured it out

somber snow
#

can you help me understand? i don't know if i can even praise myself by calling it an intuitive solution

#

my confusion is that it seems segments should be exhausted by calling list(segments)

#

i don't really understand what is increasing exponentially if the generator is exhausted, or why

runic moat
#

yes, it would basically instantiate every element of the generator in a list

#

Maybe there's some optimizations happening that I don't know about though.

somber snow
#

thanks for your help!

runic moat
#

you're welcome

#

not that I really helped :P

#

You can type !close on a blank line to close the thread.

somber snow
#

!close

jovial monolithBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.