mirror of
https://github.com/nerfstudio-project/nerfstudio.git
synced 2026-11-20 06:35:36 +08:00
torchtyping => jaxtyping (#1838)
* Run `ruff --fix` * Add jaxtyping migration script * Run migration scripts + ruff + black * Merge remote-tracking branch 'origin/main' into brent/jaxtyping * black * Fix lint * fix lint * Cleanup and more specific types * Fixed annotation errors * Fix more errors * Fix annotation * Delete _torchtyping_to_jaxtyping.py --------- Co-authored-by: Matt Tancik <mattt4001@gmail.com>
This commit is contained in:
1 parent
9b6290ea43
commit
6ba2a18b2b
65 files changed
+597
-531
No files matched your search
@@ -27,10 +27,10 @@ import numpy as np
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
import tyro
|
||||
from torch import nn
|
||||
from jaxtyping import Float
|
||||
from torch import Tensor, nn
|
||||
from torch.cuda.amp import custom_bwd, custom_fwd
|
||||
from torch.cuda.amp.grad_scaler import GradScaler
|
||||
from torchtyping import TensorType
|
||||
|
||||
from nerfstudio.utils.rich_utils import CONSOLE
|
||||
|
||||
@@ -148,7 +148,7 @@ class StableDiffusion(nn.Module):
|
||||
|
||||
def get_text_embeds(
|
||||
self, prompt: Union[str, List[str]], negative_prompt: Union[str, List[str]]
|
||||
) -> TensorType[2, "max_length", "embed_dim"]:
|
||||
) -> Float[Tensor, "2 max_length embed_dim"]:
|
||||
"""Get text embeddings for prompt and negative prompt
|
||||
Args:
|
||||
prompt: Prompt text
|
||||
@@ -184,8 +184,8 @@ class StableDiffusion(nn.Module):
|
||||
|
||||
def sds_loss(
|
||||
self,
|
||||
text_embeddings: TensorType["N", "max_length", "embed_dim"],
|
||||
image: TensorType["BS", 3, "H", "W"],
|
||||
text_embeddings: Float[Tensor, "N max_length embed_dim"],
|
||||
image: Float[Tensor, "BS 3 H W"],
|
||||
guidance_scale: float = 100.0,
|
||||
grad_scaler: Optional[GradScaler] = None,
|
||||
) -> torch.Tensor:
|
||||
@@ -229,13 +229,13 @@ class StableDiffusion(nn.Module):
|
||||
|
||||
def produce_latents(
|
||||
self,
|
||||
text_embeddings: TensorType["N", "max_length", "embed_dim"],
|
||||
text_embeddings: Float[Tensor, "N max_length embed_dim"],
|
||||
height: int = IMG_DIM,
|
||||
width: int = IMG_DIM,
|
||||
num_inference_steps: int = 50,
|
||||
guidance_scale: float = 7.5,
|
||||
latents: Optional[TensorType["BS", 4, "H", "W"]] = None,
|
||||
) -> TensorType["BS", 4, "H", "W"]:
|
||||
latents: Optional[Float[Tensor, "BS 4 H W"]] = None,
|
||||
) -> Float[Tensor, "BS 4 H W"]:
|
||||
"""Produce latents for a given text embedding
|
||||
Args:
|
||||
text_embeddings: Text embeddings
|
||||
@@ -275,7 +275,7 @@ class StableDiffusion(nn.Module):
|
||||
latents = self.scheduler.step(noise_pred, t, latents)["prev_sample"] # type: ignore
|
||||
return latents
|
||||
|
||||
def latents_to_img(self, latents: TensorType["BS", 4, "H", "W"]) -> TensorType["BS", 3, "H", "W"]:
|
||||
def latents_to_img(self, latents: Float[Tensor, "BS 4 H W"]) -> Float[Tensor, "BS 3 H W"]:
|
||||
"""Convert latents to images
|
||||
Args:
|
||||
latents: Latents to convert
|
||||
@@ -292,7 +292,7 @@ class StableDiffusion(nn.Module):
|
||||
|
||||
return imgs
|
||||
|
||||
def imgs_to_latent(self, imgs: TensorType["BS", 3, "H", "W"]) -> TensorType["BS", 4, "H", "W"]:
|
||||
def imgs_to_latent(self, imgs: Float[Tensor, "BS 3 H W"]) -> Float[Tensor, "BS 4 H W"]:
|
||||
"""Convert images to latents
|
||||
Args:
|
||||
imgs: Images to convert
|
||||
|
||||
Reference in new issue
Block a user