@@ -36,6 +36,18 @@ def _payload(request_id: str, code_len: int) -> StagePayload:
3636 )
3737
3838
39+ def _run_vocoder_request (scheduler , payload : StagePayload ) -> StagePayload :
40+ thread = threading .Thread (target = scheduler .start , daemon = True )
41+ thread .start ()
42+ try :
43+ scheduler .inbox .put (IncomingMessage (payload .request_id , "new_request" , payload ))
44+ output = scheduler .outbox .get (timeout = 2.0 )
45+ return output .data
46+ finally :
47+ scheduler .stop ()
48+ thread .join (timeout = 2.0 )
49+
50+
3951def test_fish_vocoder_uses_simple_scheduler_batch_path (monkeypatch ) -> None :
4052 codec = _FakeCodec ()
4153 monkeypatch .setattr (stages , "_resolve_checkpoint" , lambda model_path : model_path )
@@ -69,3 +81,31 @@ def test_fish_vocoder_uses_simple_scheduler_batch_path(monkeypatch) -> None:
6981 assert len (outputs ["req-long" ].data ["audio_data" ]) == 12
7082 assert outputs ["req-short" ].data ["audio_data" ] == [1.0 ] * 8
7183 assert outputs ["req-long" ].data ["audio_data" ] == [2.0 ] * 12
84+
85+
86+ def test_fish_vocoder_preserves_existing_usage (monkeypatch ) -> None :
87+ codec = _FakeCodec ()
88+ monkeypatch .setattr (stages , "_resolve_checkpoint" , lambda model_path : model_path )
89+ monkeypatch .setattr (stages , "_load_codec" , lambda checkpoint , device : codec )
90+
91+ payload = _payload ("req-usage" , 2 )
92+ usage = {
93+ "prompt_tokens" : 3 ,
94+ "completion_tokens" : 2 ,
95+ "total_tokens" : 5 ,
96+ "engine_time_s" : 0.25 ,
97+ }
98+ payload .data ["usage" ] = usage
99+ scheduler = stages .create_vocoder_executor (
100+ "unused" ,
101+ device = "cpu" ,
102+ max_batch_size = 1 ,
103+ max_batch_wait_ms = 1 ,
104+ )
105+
106+ output = _run_vocoder_request (scheduler , payload )
107+
108+ assert output .data ["usage" ] == usage
109+ assert output .data ["audio_data" ] == [1.0 ] * 8
110+ assert output .data ["sample_rate" ] == 44100
111+ assert output .data ["modality" ] == "audio"
0 commit comments