binhqd commited on
Commit
f672f51
·
1 Parent(s): c5017ba

Add custom inference handler for Maya1 TTS

Browse files
Files changed (1) hide show
  1. handler.py +33 -4
handler.py CHANGED
@@ -49,10 +49,39 @@ class EndpointHandler:
49
  if device_override == "cpu":
50
  device_map_arg = "cpu"
51
 
52
- self.model = AutoModelForCausalLM.from_pretrained(
53
- path, torch_dtype=torch_dtype, device_map=device_map_arg
54
- )
55
- self.tokenizer = AutoTokenizer.from_pretrained(path)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
  # determine device from model parameters (safer than using `model.device`)
58
  try:
 
49
  if device_override == "cpu":
50
  device_map_arg = "cpu"
51
 
52
+ # Check if model path has a valid config before attempting to load
53
+ model_path = path if path else "/repository"
54
+
55
+ # Check if this is a valid model directory
56
+ config_path = os.path.join(model_path, "config.json")
57
+ if not os.path.exists(config_path):
58
+ raise RuntimeError(
59
+ f"❌ Model configuration not found at: {config_path}\n\n"
60
+ f"The repository appears to be missing model weights and configuration.\n\n"
61
+ f"To fix this:\n"
62
+ f"1. For TESTING: Set environment variable MAYA_USE_FAKE=1 to use fake mode\n"
63
+ f"2. For PRODUCTION: Upload Maya1 model weights to your repository:\n"
64
+ f" - config.json\n"
65
+ f" - model.safetensors (or pytorch_model.bin)\n"
66
+ f" - tokenizer.json\n"
67
+ f" - tokenizer_config.json\n"
68
+ f" - generation_config.json (optional)\n\n"
69
+ f"Current path: {model_path}\n"
70
+ f"Files found: {os.listdir(model_path) if os.path.exists(model_path) else 'path does not exist'}\n"
71
+ )
72
+
73
+ try:
74
+ self.model = AutoModelForCausalLM.from_pretrained(
75
+ path, torch_dtype=torch_dtype, device_map=device_map_arg
76
+ )
77
+ self.tokenizer = AutoTokenizer.from_pretrained(path)
78
+ except Exception as e:
79
+ raise RuntimeError(
80
+ f"Failed to load Maya1 model from {path}.\n"
81
+ f"Error: {e}\n\n"
82
+ f"Please ensure the repository contains valid Maya1 model files.\n"
83
+ f"For testing without model weights, set MAYA_USE_FAKE=1"
84
+ )
85
 
86
  # determine device from model parameters (safer than using `model.device`)
87
  try: