Peter Michael Gits Claude commited on
Commit
b8737d8
Β·
1 Parent(s): 1a1d398

Add comprehensive LMGen debugging and introspection

Browse files

v1.4.9 - Deep debug LMGen step() returning None:
- Added LMGen type and methods introspection
- Test step() with and without streaming context
- Log LMGen internal state and attributes
- Try different approaches to find working API pattern
- Will reveal why step() returns None and correct usage

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +30 -29
app.py CHANGED
@@ -21,7 +21,7 @@ from fastapi.responses import JSONResponse, HTMLResponse
21
  import uvicorn
22
 
23
  # Version tracking
24
- VERSION = "1.4.8"
25
  COMMIT_SHA = "TBD"
26
 
27
  # Configure logging
@@ -176,35 +176,36 @@ def transcribe_audio_moshi(audio_data: np.ndarray, sample_rate: int = 24000) ->
176
  try:
177
  # Use the actual language model for generation
178
  if lm_gen and lm_gen != "mock":
179
- # Use streaming LMGen step method for text generation
180
- with lm_gen.streaming(1):
181
- text_tokens = []
182
- for i in range(audio_tokens.shape[-1]):
183
- # Extract single timestep tokens
184
- code_step = audio_tokens[:, :, i:i+1] # [B, 8, 1]
185
- logger.info(f"πŸ” Step {i}: code_step shape: {code_step.shape}")
186
-
187
- # Generate tokens using step method
188
- tokens_out = lm_gen.step(code_step) # [B, 1 + 8, 1]
189
- logger.info(f"πŸ” Step {i}: tokens_out type: {type(tokens_out)}, value: {tokens_out}")
190
-
191
- if tokens_out is not None:
192
- logger.info(f"πŸ” Step {i}: tokens_out shape: {tokens_out.shape}")
193
- # Extract text token (index 1)
194
- text_token = tokens_out[:, 1:2, :] # [B, 1, 1]
195
- text_tokens.append(text_token)
196
- logger.info(f"βœ… Step {i}: Added text token shape: {text_token.shape}")
197
- else:
198
- logger.error(f"❌ Step {i}: lm_gen.step() returned None!")
199
- break
200
-
201
- # Concatenate all text tokens
202
- if text_tokens:
203
- all_text_tokens = torch.cat(text_tokens, dim=-1)
204
- text_output = f"Moshiko CPU transcription: Generated {all_text_tokens.shape} text tokens"
205
- logger.info(f"βœ… Generated transcription: {text_output}")
206
  else:
207
- text_output = "Moshiko: No text tokens generated"
 
 
 
 
 
208
  else:
209
  text_output = "Moshiko fallback: LM generator not available"
210
  logger.warning("⚠️ LM generator not available, using fallback")
 
21
  import uvicorn
22
 
23
  # Version tracking
24
+ VERSION = "1.4.9"
25
  COMMIT_SHA = "TBD"
26
 
27
  # Configure logging
 
176
  try:
177
  # Use the actual language model for generation
178
  if lm_gen and lm_gen != "mock":
179
+ logger.info(f"πŸ”§ LMGen type: {type(lm_gen)}")
180
+ logger.info(f"πŸ”§ LMGen methods: {[m for m in dir(lm_gen) if not m.startswith('_')]}")
181
+
182
+ # Try simpler approach - maybe streaming context is the issue
183
+ try:
184
+ # First try without streaming context
185
+ logger.info("πŸ§ͺ Trying step() without streaming context...")
186
+ code_step = audio_tokens[:, :, 0:1] # Just first timestep [B, 8, 1]
187
+ tokens_out = lm_gen.step(code_step)
188
+ logger.info(f"πŸ” Direct step result: {type(tokens_out)}, value: {tokens_out}")
189
+
190
+ if tokens_out is None:
191
+ # Try with streaming context
192
+ logger.info("πŸ§ͺ Trying with streaming context...")
193
+ with lm_gen.streaming(1):
194
+ tokens_out = lm_gen.step(code_step)
195
+ logger.info(f"πŸ” Streaming step result: {type(tokens_out)}, value: {tokens_out}")
196
+
197
+ if tokens_out is None:
198
+ # Maybe we need to call a different method or check state
199
+ logger.error("🚨 Both approaches returned None - checking LMGen state")
200
+ logger.info(f"πŸ”§ LMGen attributes: {vars(lm_gen) if hasattr(lm_gen, '__dict__') else 'No __dict__'}")
201
+ text_output = "Moshiko: LMGen step() returns None - API issue"
 
 
 
 
202
  else:
203
+ logger.info(f"βœ… Got tokens! Shape: {tokens_out.shape if hasattr(tokens_out, 'shape') else 'No shape'}")
204
+ text_output = f"Moshiko CPU: Successfully generated tokens with shape {tokens_out.shape if hasattr(tokens_out, 'shape') else 'unknown'}"
205
+
206
+ except Exception as step_error:
207
+ logger.error(f"🚨 LMGen step error: {step_error}")
208
+ text_output = f"Moshiko: LMGen step error: {str(step_error)}"
209
  else:
210
  text_output = "Moshiko fallback: LM generator not available"
211
  logger.warning("⚠️ LM generator not available, using fallback")