Instructions to use epfl-neuroai/NEvo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use epfl-neuroai/NEvo with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("epfl-neuroai/NEvo", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
Add MPS-compatible component dtypes
#1
by mzx - opened
stimulus_synthesis/generators/diffusers_i2v.py
CHANGED
|
@@ -14,6 +14,8 @@ class DiffusersImageToVideoAdapter(ImageToVideoGenerator):
|
|
| 14 |
dtype = torch_dtype
|
| 15 |
if dtype is None and str(device).startswith("cuda"):
|
| 16 |
dtype = torch.bfloat16
|
|
|
|
|
|
|
| 17 |
pipeline_cls = kwargs.pop("pipeline_cls", None) or _default_i2v_pipeline_cls(model_id)
|
| 18 |
pipeline = pipeline_cls.from_pretrained(model_id, torch_dtype=dtype, **kwargs)
|
| 19 |
self.pipe = pipeline
|
|
|
|
| 14 |
dtype = torch_dtype
|
| 15 |
if dtype is None and str(device).startswith("cuda"):
|
| 16 |
dtype = torch.bfloat16
|
| 17 |
+
if dtype is None and str(device).startswith("mps"):
|
| 18 |
+
dtype = torch.bfloat16
|
| 19 |
pipeline_cls = kwargs.pop("pipeline_cls", None) or _default_i2v_pipeline_cls(model_id)
|
| 20 |
pipeline = pipeline_cls.from_pretrained(model_id, torch_dtype=dtype, **kwargs)
|
| 21 |
self.pipe = pipeline
|
stimulus_synthesis/generators/diffusers_t2i.py
CHANGED
|
@@ -14,6 +14,8 @@ class DiffusersTextToImageAdapter(TextToImageGenerator):
|
|
| 14 |
dtype = torch_dtype
|
| 15 |
if dtype is None and str(device).startswith("cuda"):
|
| 16 |
dtype = torch.float16
|
|
|
|
|
|
|
| 17 |
pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype, **kwargs)
|
| 18 |
self.pipe = pipeline
|
| 19 |
self.device = device
|
|
|
|
| 14 |
dtype = torch_dtype
|
| 15 |
if dtype is None and str(device).startswith("cuda"):
|
| 16 |
dtype = torch.float16
|
| 17 |
+
if dtype is None and str(device).startswith("mps"):
|
| 18 |
+
dtype = torch.float32
|
| 19 |
pipeline = DiffusionPipeline.from_pretrained(model_id, torch_dtype=dtype, **kwargs)
|
| 20 |
self.pipe = pipeline
|
| 21 |
self.device = device
|
stimulus_synthesis/pipeline.py
CHANGED
|
@@ -93,6 +93,7 @@ class NevoPipeline(DiffusionPipeline):
|
|
| 93 |
encoder_call=cfg.encoder_call,
|
| 94 |
objective=cfg.default_objective,
|
| 95 |
device=device,
|
|
|
|
| 96 |
)
|
| 97 |
transform_spec = RobustTransformSpec.from_dict(dict(cfg.default_score_transform or {}))
|
| 98 |
scorer = RobustTransformScorer(base_scorer, transform_spec) if transform_spec is not None else base_scorer
|
|
|
|
| 93 |
encoder_call=cfg.encoder_call,
|
| 94 |
objective=cfg.default_objective,
|
| 95 |
device=device,
|
| 96 |
+
encoder_dtype=torch.float32 if str(device).startswith("mps") else None,
|
| 97 |
)
|
| 98 |
transform_spec = RobustTransformSpec.from_dict(dict(cfg.default_score_transform or {}))
|
| 99 |
scorer = RobustTransformScorer(base_scorer, transform_spec) if transform_spec is not None else base_scorer
|
stimulus_synthesis/scoring/encoder_scorer.py
CHANGED
|
@@ -18,6 +18,7 @@ class EncoderScorer(Scorer):
|
|
| 18 |
encoder_call: str = "predict_fmri",
|
| 19 |
objective: str | Any = "indices_mean",
|
| 20 |
device: str = "cuda",
|
|
|
|
| 21 |
trust_remote_code: bool = True,
|
| 22 |
**encoder_kwargs,
|
| 23 |
) -> None:
|
|
@@ -34,6 +35,8 @@ class EncoderScorer(Scorer):
|
|
| 34 |
self.objective = build_objective(objective)
|
| 35 |
self.device = device
|
| 36 |
if hasattr(self.encoder, "to"):
|
|
|
|
|
|
|
| 37 |
self.encoder.to(device)
|
| 38 |
if hasattr(self.encoder, "eval"):
|
| 39 |
self.encoder.eval()
|
|
|
|
| 18 |
encoder_call: str = "predict_fmri",
|
| 19 |
objective: str | Any = "indices_mean",
|
| 20 |
device: str = "cuda",
|
| 21 |
+
encoder_dtype: torch.dtype | None = None,
|
| 22 |
trust_remote_code: bool = True,
|
| 23 |
**encoder_kwargs,
|
| 24 |
) -> None:
|
|
|
|
| 35 |
self.objective = build_objective(objective)
|
| 36 |
self.device = device
|
| 37 |
if hasattr(self.encoder, "to"):
|
| 38 |
+
if encoder_dtype is not None:
|
| 39 |
+
self.encoder.to(dtype=encoder_dtype)
|
| 40 |
self.encoder.to(device)
|
| 41 |
if hasattr(self.encoder, "eval"):
|
| 42 |
self.encoder.eval()
|