[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
1a9598948b
commit
21b502a9a5
4 changed files with 20 additions and 11 deletions
|
|
@ -114,6 +114,7 @@ try:
|
|||
except Exception as e:
|
||||
print(f" ⚠️ Prometheus test skipped: {e}")
|
||||
import traceback
|
||||
|
||||
traceback.print_exc()
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
|
|
|
|||
|
|
@ -110,7 +110,7 @@ class InferenceStats:
|
|||
|
||||
def record_first_token(self, request_id: str, timestamp: Optional[float] = None):
|
||||
"""Record when the first token was generated.
|
||||
|
||||
|
||||
Args:
|
||||
request_id: Unique identifier for the request
|
||||
timestamp: Optional timestamp. If None, uses current time.
|
||||
|
|
@ -119,7 +119,9 @@ class InferenceStats:
|
|||
if request_id in self._active_requests:
|
||||
req = self._active_requests[request_id]
|
||||
if req.first_token_time is None:
|
||||
req.first_token_time = timestamp if timestamp is not None else time.time()
|
||||
req.first_token_time = (
|
||||
timestamp if timestamp is not None else time.time()
|
||||
)
|
||||
if req.scheduled_time is None:
|
||||
req.scheduled_time = req.first_token_time
|
||||
|
||||
|
|
|
|||
|
|
@ -1917,20 +1917,20 @@ def _patch_training_metrics(Trainer):
|
|||
if hasattr(tensor, "shape") and len(tensor.shape) > 0:
|
||||
batch_size = tensor.shape[0]
|
||||
break
|
||||
|
||||
|
||||
# Track step duration (includes both forward and backward passes)
|
||||
step_start = time.time()
|
||||
|
||||
|
||||
# Call original training_step
|
||||
try:
|
||||
result = original_training_step(self, model, inputs, *args, **kwargs)
|
||||
except Exception as e:
|
||||
# Re-raise exception but don't track metrics on error
|
||||
raise
|
||||
|
||||
|
||||
step_end = time.time()
|
||||
step_duration = step_end - step_start
|
||||
|
||||
|
||||
# Extract loss and other info from result
|
||||
loss_value = None
|
||||
if isinstance(result, (int, float)):
|
||||
|
|
|
|||
|
|
@ -365,22 +365,28 @@ def unsloth_base_fast_generate(
|
|||
else:
|
||||
total_tokens = sequences.shape[-1]
|
||||
num_generation_tokens = max(0, total_tokens - num_prompt_tokens)
|
||||
|
||||
|
||||
# Estimate timing (simplified)
|
||||
# Note: These are estimations. For more accurate metrics, consider hooking into
|
||||
# the generation process itself (e.g., via LogitsProcessor or StoppingCriteria)
|
||||
if num_generation_tokens > 0:
|
||||
# Estimate first token time
|
||||
estimated_first_token_time = start_time + (e2e_latency / (num_generation_tokens + 1))
|
||||
collector.inference_stats.record_first_token(request_id, timestamp=estimated_first_token_time)
|
||||
|
||||
estimated_first_token_time = start_time + (
|
||||
e2e_latency / (num_generation_tokens + 1)
|
||||
)
|
||||
collector.inference_stats.record_first_token(
|
||||
request_id, timestamp = estimated_first_token_time
|
||||
)
|
||||
|
||||
# Record tokens (simplified - records all at once after generation)
|
||||
for _ in range(num_generation_tokens):
|
||||
collector.inference_stats.record_token(request_id)
|
||||
|
||||
# Determine finish reason (simplified - could be improved)
|
||||
finish_reason = "stop" # Default
|
||||
if isinstance(output, (dict, type(output))) and hasattr(output, "finish_reason"):
|
||||
if isinstance(output, (dict, type(output))) and hasattr(
|
||||
output, "finish_reason"
|
||||
):
|
||||
finish_reason = output.finish_reason
|
||||
elif isinstance(output, dict) and "finish_reason" in output:
|
||||
finish_reason = output["finish_reason"]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue