Spaces:
Running
on
Zero
Running
on
Zero
Joseph Pollack
commited on
decodes outputs using tokenizer
Browse files
app.py
CHANGED
|
@@ -113,16 +113,40 @@ class LOperatorDemo:
|
|
| 113 |
tokenize=True,
|
| 114 |
)
|
| 115 |
|
| 116 |
-
logger.info(f"Processor output
|
| 117 |
|
| 118 |
-
#
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
except Exception as e:
|
| 128 |
logger.error(f"Error generating action: {str(e)}")
|
|
|
|
| 113 |
tokenize=True,
|
| 114 |
)
|
| 115 |
|
| 116 |
+
logger.info(f"Processor output keys: {list(inputs.keys())}")
|
| 117 |
|
| 118 |
+
# Move inputs to device
|
| 119 |
+
for key, value in inputs.items():
|
| 120 |
+
if isinstance(value, torch.Tensor):
|
| 121 |
+
inputs[key] = value.to(self.model.device)
|
| 122 |
|
| 123 |
+
logger.info(f"Inputs shape: {inputs['input_ids'].shape}, device: {inputs['input_ids'].device}")
|
| 124 |
+
|
| 125 |
+
# Generate response
|
| 126 |
+
logger.info("Generating response...")
|
| 127 |
+
with torch.no_grad():
|
| 128 |
+
outputs = self.model.generate(
|
| 129 |
+
**inputs,
|
| 130 |
+
max_new_tokens=128,
|
| 131 |
+
do_sample=True,
|
| 132 |
+
temperature=0.7,
|
| 133 |
+
top_p=0.9,
|
| 134 |
+
pad_token_id=self.processor.tokenizer.eos_token_id
|
| 135 |
+
)
|
| 136 |
+
|
| 137 |
+
logger.info("Decoding response...")
|
| 138 |
+
# Decode the generated tokens
|
| 139 |
+
response = self.processor.tokenizer.decode(
|
| 140 |
+
outputs[0][inputs['input_ids'].shape[1]:],
|
| 141 |
+
skip_special_tokens=True
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
# Try to parse as JSON for better formatting
|
| 145 |
+
try:
|
| 146 |
+
parsed_response = json.loads(response)
|
| 147 |
+
return json.dumps(parsed_response, indent=2)
|
| 148 |
+
except:
|
| 149 |
+
return response
|
| 150 |
|
| 151 |
except Exception as e:
|
| 152 |
logger.error(f"Error generating action: {str(e)}")
|