Run this model with HF Jobs
Run SumantBobade/Image_To_3D_Generator on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/SumantBobade/Image_To_3D_Generator. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/SumantBobade/Image_To_3D_Generator on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use SumantBobade/Image_To_3D_Generator with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use SumantBobade/Image_To_3D_Generator with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("SumantBobade/Image_To_3D_Generator", 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
remove grad checkpointing
Browse filesFiles changed (2)
- README.md+4
- mv_unet.py-84
10 unmodified lines1112131415161718192010 unmodified lines```bash# dependencypip install -r requirements.txt
# xformers is required! please refer to https://github.com/facebookresearch/xformerspip install ninjapip install -v -U git+https://github.com/facebookresearch/xformers.git@main#egg=xformers```
### Usage38 unmodified lines39404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990424344192 unmodified lines23723823928924024124220 unmodified lines26326426531626626731932032132232326826927014 unmodified lines28528628734428828929014 unmodified lines305306307365308309310212 unmodified lines5235245255845265275287 unmodified lines5365375385985395405413 unmodified lines54554654760854854955039 unmodified lines59059159265465565665765865966066166266366459359459534 unmodified lines63063163270563363463519 unmodified lines65565665773165865966059 unmodified lines72072172279772372472567 unmodified lines79379479587179679779813 unmodified lines81281381489181581681711 unmodified lines82983083190983283383420 unmodified lines8558568579368588598602 unmodified lines8638648659458668678682 unmodified lines87187287395487487587610 unmodified lines88788888997189089189213 unmodified lines9069079089919099109117 unmodified lines919920921100592292392438 unmodified lines return torch.from_numpy(np.stack(cameras, axis=0)).float() # [num_frames, 16]
def checkpoint(func, inputs, params, flag): """ Evaluate a function without caching intermediate activations, allowing for reduced memory at the expense of extra compute in the backward pass. :param func: the function to evaluate. :param inputs: the argument sequence to pass to `func`. :param params: a sequence of parameters `func` depends on but does not explicitly take as arguments. :param flag: if False, disable gradient checkpointing. """ if flag: args = tuple(inputs) + tuple(params) return CheckpointFunction.apply(func, len(inputs), *args) else: return func(*inputs)
class CheckpointFunction(torch.autograd.Function): @staticmethod def forward(ctx, run_function, length, *args): ctx.run_function = run_function ctx.input_tensors = list(args[:length]) ctx.input_params = list(args[length:])
with torch.no_grad(): output_tensors = ctx.run_function(*ctx.input_tensors) return output_tensors
@staticmethod def backward(ctx, *output_grads): ctx.input_tensors = [x.detach().requires_grad_(True) for x in ctx.input_tensors] with torch.enable_grad(): # Fixes a bug where the first op in run_function modifies the # Tensor storage in place, which is not allowed for detach()'d # Tensors. shallow_copies = [x.view_as(x) for x in ctx.input_tensors] output_tensors = ctx.run_function(*shallow_copies) input_grads = torch.autograd.grad( output_tensors, ctx.input_tensors + ctx.input_params, output_grads, allow_unused=True, ) del ctx.input_tensors del ctx.input_params del output_tensors return (None, None) + input_grads
def timestep_embedding(timesteps, dim, max_period=10000, repeat_only=False): """ Create sinusoidal timestep embeddings.192 unmodified lines context_dim, dropout=0.0, gated_ff=True, checkpoint=True, ip_dim=0, ip_weight=1, ):20 unmodified lines self.norm1 = nn.LayerNorm(dim) self.norm2 = nn.LayerNorm(dim) self.norm3 = nn.LayerNorm(dim) self.checkpoint = checkpoint
def forward(self, x, context=None, num_frames=1): return checkpoint( self._forward, (x, context, num_frames), self.parameters(), self.checkpoint )
def _forward(self, x, context=None, num_frames=1): x = rearrange(x, "(b f) l c -> b (f l) c", f=num_frames).contiguous() x = self.attn1(self.norm1(x), context=None) + x x = rearrange(x, "b (f l) c -> (b f) l c", f=num_frames).contiguous()14 unmodified lines dropout=0.0, ip_dim=0, ip_weight=1, use_checkpoint=True, ): super().__init__()
14 unmodified lines d_head, context_dim=context_dim[d], dropout=dropout, checkpoint=use_checkpoint, ip_dim=ip_dim, ip_weight=ip_weight, )212 unmodified lines convolution instead of a smaller 1x1 convolution to change the channels in the skip connection. :param dims: determines if the signal is 1D, 2D, or 3D. :param use_checkpoint: if True, use gradient checkpointing on this module. :param up: if True, use this block for upsampling. :param down: if True, use this block for downsampling. """7 unmodified lines use_conv=False, use_scale_shift_norm=False, dims=2, use_checkpoint=False, up=False, down=False, ):3 unmodified lines self.dropout = dropout self.out_channels = out_channels or channels self.use_conv = use_conv self.use_checkpoint = use_checkpoint self.use_scale_shift_norm = use_scale_shift_norm
self.in_layers = nn.Sequential(39 unmodified lines self.skip_connection = conv_nd(dims, channels, self.out_channels, 1)
def forward(self, x, emb): """ Apply the block to a Tensor, conditioned on a timestep embedding. :param x: an [N x C x ...] Tensor of features. :param emb: an [N x emb_channels] Tensor of timestep embeddings. :return: an [N x C x ...] Tensor of outputs. """ return checkpoint( self._forward, (x, emb), self.parameters(), self.use_checkpoint )
def _forward(self, x, emb): if self.updown: in_rest, in_conv = self.in_layers[:-1], self.in_layers[-1] h = in_rest(x)34 unmodified lines :param dims: determines if the signal is 1D, 2D, or 3D. :param num_classes: if specified (as an int), then this model will be class-conditional with `num_classes` classes. :param use_checkpoint: use gradient checkpointing to reduce memory usage. :param num_heads: the number of attention heads in each attention layer. :param num_heads_channels: if specified, ignore num_heads and instead use a fixed channel width per attention head.19 unmodified lines conv_resample=True, dims=2, num_classes=None, use_checkpoint=False, num_heads=-1, num_head_channels=-1, num_heads_upsample=-1,59 unmodified lines self.channel_mult = channel_mult self.conv_resample = conv_resample self.num_classes = num_classes self.use_checkpoint = use_checkpoint self.num_heads = num_heads self.num_head_channels = num_head_channels self.num_heads_upsample = num_heads_upsample67 unmodified lines dropout, out_channels=mult * model_channels, dims=dims, use_checkpoint=use_checkpoint, use_scale_shift_norm=use_scale_shift_norm, ) ]13 unmodified lines dim_head, context_dim=context_dim, depth=transformer_depth, use_checkpoint=use_checkpoint, ip_dim=self.ip_dim, ip_weight=self.ip_weight, )11 unmodified lines dropout, out_channels=out_ch, dims=dims, use_checkpoint=use_checkpoint, use_scale_shift_norm=use_scale_shift_norm, down=True, )20 unmodified lines time_embed_dim, dropout, dims=dims, use_checkpoint=use_checkpoint, use_scale_shift_norm=use_scale_shift_norm, ), SpatialTransformer3D(2 unmodified lines dim_head, context_dim=context_dim, depth=transformer_depth, use_checkpoint=use_checkpoint, ip_dim=self.ip_dim, ip_weight=self.ip_weight, ), 2 unmodified lines time_embed_dim, dropout, dims=dims, use_checkpoint=use_checkpoint, use_scale_shift_norm=use_scale_shift_norm, ), )10 unmodified lines dropout, out_channels=model_channels * mult, dims=dims, use_checkpoint=use_checkpoint, use_scale_shift_norm=use_scale_shift_norm, ) ]13 unmodified lines dim_head, context_dim=context_dim, depth=transformer_depth, use_checkpoint=use_checkpoint, ip_dim=self.ip_dim, ip_weight=self.ip_weight, )7 unmodified lines dropout, out_channels=out_ch, dims=dims, use_checkpoint=use_checkpoint, use_scale_shift_norm=use_scale_shift_norm, up=True, )README.md+4
mv_unet.py-84