CodeSoft commited on
Commit
c9ee5f8
·
1 Parent(s): d32d17a
Files changed (2) hide show
  1. app.py +9 -9
  2. requirements.txt +3 -3
app.py CHANGED
@@ -1,3 +1,5 @@
 
 
1
  import os
2
  import json
3
  import random
@@ -97,7 +99,9 @@ MODEL_CONTEXT: Dict[str, int] = {
97
  "CodeSoft/MetaDiffusion-150M-ChatBase": 5120,
98
  }
99
 
100
- DEVICE = "cpu"
 
 
101
 
102
  @dataclass
103
  class MetaDiffusionConfig:
@@ -551,12 +555,7 @@ def load_diffusion_manual():
551
  cfg = MetaDiffusionConfig(**valid)
552
  cfg.tie_word_embeddings = False
553
  mdl = MetaDiffusionLM(cfg).to(DEVICE)
554
- try:
555
- from safetensors.torch import load_file
556
- except ImportError:
557
- import subprocess, sys
558
- subprocess.check_call([sys.executable, "-m", "pip", "install", "safetensors", "--quiet", "--break-system-packages"])
559
- from safetensors.torch import load_file # type: ignore
560
  state = load_file(str(model_path), device="cpu")
561
  state = {k[len("model."):] if k.startswith("model.") else k: v for k, v in state.items()}
562
  missing, unexpected = mdl.load_state_dict(state, strict=False)
@@ -688,6 +687,7 @@ def build_inputs(tokenizer, model_id: str, prompt: str):
688
  def is_diffusion_model(model_id: str) -> bool:
689
  return "metadiffusion" in model_id.lower()
690
 
 
691
  def generate_for_model(model_id: str, prompt: str) -> str:
692
  ensure_models_loaded()
693
  if model_id not in models or model_id not in tokenizers:
@@ -1093,7 +1093,7 @@ def create_demo() -> gr.Blocks:
1093
  # ---------------------------------------------------------------------------
1094
  if __name__ == "__main__":
1095
  print("=" * 60)
1096
- print("SLM Arena starting, attempting to load 4 models on CPU...")
1097
  print(f"Models: {MODEL_IDS}")
1098
  print(f"Data dir: {get_data_dir().resolve()} (bucket /data if mounted)")
1099
  print("=" * 60)
@@ -1113,4 +1113,4 @@ if __name__ == "__main__":
1113
  logger.warning(f"Leaderboard preview failed: {e}")
1114
  demo = create_demo()
1115
  demo.queue(max_size=20)
1116
- demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True, theme=gr.themes.Base(), css=CSS)
 
1
+ import spaces
2
+
3
  import os
4
  import json
5
  import random
 
99
  "CodeSoft/MetaDiffusion-150M-ChatBase": 5120,
100
  }
101
 
102
+ # ZeroGPU: CUDA is emulated at startup so models load onto cuda at module level;
103
+ # real GPU is only mounted inside @spaces.GPU-decorated calls.
104
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
105
 
106
  @dataclass
107
  class MetaDiffusionConfig:
 
555
  cfg = MetaDiffusionConfig(**valid)
556
  cfg.tie_word_embeddings = False
557
  mdl = MetaDiffusionLM(cfg).to(DEVICE)
558
+ from safetensors.torch import load_file
 
 
 
 
 
559
  state = load_file(str(model_path), device="cpu")
560
  state = {k[len("model."):] if k.startswith("model.") else k: v for k, v in state.items()}
561
  missing, unexpected = mdl.load_state_dict(state, strict=False)
 
687
  def is_diffusion_model(model_id: str) -> bool:
688
  return "metadiffusion" in model_id.lower()
689
 
690
+ @spaces.GPU(duration=120)
691
  def generate_for_model(model_id: str, prompt: str) -> str:
692
  ensure_models_loaded()
693
  if model_id not in models or model_id not in tokenizers:
 
1093
  # ---------------------------------------------------------------------------
1094
  if __name__ == "__main__":
1095
  print("=" * 60)
1096
+ print("SLM Arena starting, attempting to load 4 models...")
1097
  print(f"Models: {MODEL_IDS}")
1098
  print(f"Data dir: {get_data_dir().resolve()} (bucket /data if mounted)")
1099
  print("=" * 60)
 
1113
  logger.warning(f"Leaderboard preview failed: {e}")
1114
  demo = create_demo()
1115
  demo.queue(max_size=20)
1116
+ demo.launch(server_name="0.0.0.0", server_port=7860, show_error=True, theme=gr.themes.Base(), css=CSS)
requirements.txt CHANGED
@@ -1,8 +1,8 @@
1
- torch==2.13.0
2
  transformers==5.14.1
3
  gradio==6.5.1
4
- pandas==3.0.3
5
  safetensors==0.8.0
6
  huggingface_hub==1.22.0
7
  accelerate==1.14.0
8
- numpy==2.5.2
 
1
+ torch==2.11.0
2
  transformers==5.14.1
3
  gradio==6.5.1
4
+ pandas==2.3.3
5
  safetensors==0.8.0
6
  huggingface_hub==1.22.0
7
  accelerate==1.14.0
8
+ numpy==2.2.6