Spaces:
Sleeping
Sleeping
Upload folder using huggingface_hub
Browse filesFiles changed (2)
- inference.py+6-3
- tasks.py+9-1
307 unmodified lines308309310311312313314315316317318319320321322323324325326327307 unmodified linesstep_num += 1print(f"[STEP] {json.dumps({'task': task_name, 'step': step_num, 'action': action, 'reward': round(obs.get('reward') or 0.5, 4), 'cumulative_profit': round(obs.get('cumulative_profit', 0.0), 4), 'holding_cost': round(obs.get('holding_cost_this_step', 0.0), 4), 'placement_cost': obs.get('placement_cost_this_step', 0.0), 'restock_cost': round(obs.get('restock_cost_this_step', 0.0), 4), 'unjustified_penalty': round(obs.get('unjustified_discount_penalty', 0.0), 4)})}",flush=True,)if obs.get("done", False):breakcumulative = obs.get("cumulative_profit", 0.0)return cumulative, grade(task_name, cumulative)finally:score = grade(task_name, cumulative)print(f"[END] {json.dumps({'task': task_name, 'cumulative_profit': round(cumulative, 4), 'score': round(score, 4), 'profit_target': task.profit_target})}",flush=True,)if ws is not None:307 unmodified lines308309310311312313314315316317318319320321322323324325326327328329330307 unmodified linesstep_num += 1print(f"[STEP] {json.dumps({'task': task_name, 'step': step_num, 'action': action, 'reward': round(obs.get('reward') if obs.get('reward') is not None else 0.5, 4), 'cumulative_profit': round(float(obs.get('cumulative_profit') or 0.0), 4), 'holding_cost': round(float(obs.get('holding_cost_this_step') or 0.0), 4), 'placement_cost': float(obs.get('placement_cost_this_step') or 0.0), 'restock_cost': round(float(obs.get('restock_cost_this_step') or 0.0), 4), 'unjustified_penalty': round(float(obs.get('unjustified_discount_penalty') or 0.0), 4)})}",flush=True,)if obs.get("done", False):breakcumulative_raw = obs.get("cumulative_profit")cumulative = float(cumulative_raw) if cumulative_raw is not None else 0.0return cumulative, grade(task_name, cumulative)finally:score = grade(task_name, cumulative)# Extra safety: ensure score is strictly within (0, 1) exclusivescore = max(1e-9, min(1.0 - 1e-9, score))print(f"[END] {json.dumps({'task': task_name, 'cumulative_profit': round(cumulative, 4), 'score': round(score, 6), 'profit_target': task.profit_target})}",flush=True,)if ws is not None:
129 unmodified lines130131132133134135136137138139140129 unmodified linesReturns:Score strictly between 0.0 and 1.0 (exclusive)."""_EPS = 0.001config = TASKS.get(task_name)if config is None or config.profit_target <= 0:return 1.0 - _EPSreturn min(1.0 - _EPS, max(_EPS, cumulative_profit / config.profit_target))__all__ = ["TaskConfig", "TASKS", "grade"]129 unmodified lines130131132133134135136137138139140141142143144145146147148129 unmodified linesReturns:Score strictly between 0.0 and 1.0 (exclusive)."""import math_EPS = 0.001try:cp = float(cumulative_profit)if not math.isfinite(cp):cp = 0.0except (TypeError, ValueError):cp = 0.0config = TASKS.get(task_name)if config is None or config.profit_target <= 0:return 1.0 - _EPSreturn min(1.0 - _EPS, max(_EPS, cp / config.profit_target))__all__ = ["TaskConfig", "TASKS", "grade"]
inference.py+6-3
tasks.py+9-1