OpenHTR commited on
Commit
2dad85b
·
verified ·
1 Parent(s): bde2db3

Update engine.py

Browse files
Files changed (1) hide show
  1. engine.py +7 -3
engine.py CHANGED
@@ -29,7 +29,7 @@ from diffusers import FluxFillPipeline, FluxTransformer2DModel
29
  HERE = os.path.dirname(os.path.abspath(__file__))
30
 
31
  DEFAULT_BASE_MODEL = os.environ.get("BASE_MODEL", "black-forest-labs/FLUX.1-Fill-dev")
32
- DEFAULT_FONT_PATH = os.path.join(HERE, "Arial-Unicode-Regular.ttf")
33
  LORA_FILENAME = os.environ.get("LORA_FILENAME", "pytorch_lora_weights.safetensors")
34
  # Fallback host for the style adapter when no local copy is shipped with the Space.
35
  DEFAULT_LORA_REPO = os.environ.get("DEFAULT_LORA_REPO", "OpenHTR/OpenHTR-Gen-LoRA")
@@ -456,8 +456,12 @@ def load_pipeline(base_model=DEFAULT_BASE_MODEL, lora_path=None,
456
  transformer_kwargs["quantization_config"] = DiffusersBnbConfig(load_in_8bit=True)
457
  elif os.environ.get("HW_DEVICE_MAP", "1") != "0":
458
  # Stream the 12B transformer straight to the GPU instead of materialising
459
- # ~24GB in CPU RAM first. Set HW_DEVICE_MAP=0 to use the plain path.
460
- transformer_kwargs["device_map"] = device
 
 
 
 
461
 
462
  print(f"[load] base={base_model} dtype={compute_dtype} 8bit={quantize_8bit}")
463
  with _tolerate_redundant_to_on_quantized_models():
 
29
  HERE = os.path.dirname(os.path.abspath(__file__))
30
 
31
  DEFAULT_BASE_MODEL = os.environ.get("BASE_MODEL", "black-forest-labs/FLUX.1-Fill-dev")
32
+ DEFAULT_FONT_PATH = os.path.join(HERE, "font", "Arial-Unicode-Regular.ttf")
33
  LORA_FILENAME = os.environ.get("LORA_FILENAME", "pytorch_lora_weights.safetensors")
34
  # Fallback host for the style adapter when no local copy is shipped with the Space.
35
  DEFAULT_LORA_REPO = os.environ.get("DEFAULT_LORA_REPO", "OpenHTR/OpenHTR-Gen-LoRA")
 
456
  transformer_kwargs["quantization_config"] = DiffusersBnbConfig(load_in_8bit=True)
457
  elif os.environ.get("HW_DEVICE_MAP", "1") != "0":
458
  # Stream the 12B transformer straight to the GPU instead of materialising
459
+ # ~24GB in CPU RAM first. The map value must carry a device index ("cuda:0"):
460
+ # a bare "cuda" becomes device(type='cuda'), which safetensors rejects.
461
+ dev = torch.device(device)
462
+ if dev.type == "cuda" and dev.index is None:
463
+ dev = torch.device("cuda", torch.cuda.current_device())
464
+ transformer_kwargs["device_map"] = {"": str(dev)}
465
 
466
  print(f"[load] base={base_model} dtype={compute_dtype} 8bit={quantize_8bit}")
467
  with _tolerate_redundant_to_on_quantized_models():