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 lines11121314151610 unmodified lines```bash# dependencypip install -r requirements.txt```### Usage10 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```### Usage
38 unmodified lines39404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293192 unmodified lines28628728828929029129220 unmodified lines31331431531631731831932032132232332432532614 unmodified lines34134234334434534634714 unmodified lines362363364365366367368212 unmodified lines5815825835845855865877 unmodified lines5955965975985996006013 unmodified lines60560660760860961061139 unmodified lines65165265365465565665765865966066166266366466566666734 unmodified lines70270370470570670770819 unmodified lines72872973073173273373459 unmodified lines79479579679779879980067 unmodified lines86886987087187287387413 unmodified lines88888989089189289389411 unmodified lines90690790890991091191220 unmodified lines9339349359369379389392 unmodified lines9429439449459469479482 unmodified lines95195295395495595695710 unmodified lines96896997097197297397413 unmodified lines9889899909919929939947 unmodified lines100210031004100510061007100838 unmodified linesreturn 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 forreduced 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 notexplicitly 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):@staticmethoddef forward(ctx, run_function, length, *args):ctx.run_function = run_functionctx.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@staticmethoddef 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_tensorsdel ctx.input_paramsdel output_tensorsreturn (None, None) + input_gradsdef timestep_embedding(timesteps, dim, max_period=10000, repeat_only=False):"""Create sinusoidal timestep embeddings.192 unmodified linescontext_dim,dropout=0.0,gated_ff=True,checkpoint=True,ip_dim=0,ip_weight=1,):20 unmodified linesself.norm1 = nn.LayerNorm(dim)self.norm2 = nn.LayerNorm(dim)self.norm3 = nn.LayerNorm(dim)self.checkpoint = checkpointdef 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) + xx = rearrange(x, "b (f l) c -> (b f) l c", f=num_frames).contiguous()14 unmodified linesdropout=0.0,ip_dim=0,ip_weight=1,use_checkpoint=True,):super().__init__()14 unmodified linesd_head,context_dim=context_dim[d],dropout=dropout,checkpoint=use_checkpoint,ip_dim=ip_dim,ip_weight=ip_weight,)212 unmodified linesconvolution instead of a smaller 1x1 convolution to change thechannels 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 linesuse_conv=False,use_scale_shift_norm=False,dims=2,use_checkpoint=False,up=False,down=False,):3 unmodified linesself.dropout = dropoutself.out_channels = out_channels or channelsself.use_conv = use_convself.use_checkpoint = use_checkpointself.use_scale_shift_norm = use_scale_shift_normself.in_layers = nn.Sequential(39 unmodified linesself.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 beclass-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 usea fixed channel width per attention head.19 unmodified linesconv_resample=True,dims=2,num_classes=None,use_checkpoint=False,num_heads=-1,num_head_channels=-1,num_heads_upsample=-1,59 unmodified linesself.channel_mult = channel_multself.conv_resample = conv_resampleself.num_classes = num_classesself.use_checkpoint = use_checkpointself.num_heads = num_headsself.num_head_channels = num_head_channelsself.num_heads_upsample = num_heads_upsample67 unmodified linesdropout,out_channels=mult * model_channels,dims=dims,use_checkpoint=use_checkpoint,use_scale_shift_norm=use_scale_shift_norm,)]13 unmodified linesdim_head,context_dim=context_dim,depth=transformer_depth,use_checkpoint=use_checkpoint,ip_dim=self.ip_dim,ip_weight=self.ip_weight,)11 unmodified linesdropout,out_channels=out_ch,dims=dims,use_checkpoint=use_checkpoint,use_scale_shift_norm=use_scale_shift_norm,down=True,)20 unmodified linestime_embed_dim,dropout,dims=dims,use_checkpoint=use_checkpoint,use_scale_shift_norm=use_scale_shift_norm,),SpatialTransformer3D(2 unmodified linesdim_head,context_dim=context_dim,depth=transformer_depth,use_checkpoint=use_checkpoint,ip_dim=self.ip_dim,ip_weight=self.ip_weight,),2 unmodified linestime_embed_dim,dropout,dims=dims,use_checkpoint=use_checkpoint,use_scale_shift_norm=use_scale_shift_norm,),)10 unmodified linesdropout,out_channels=model_channels * mult,dims=dims,use_checkpoint=use_checkpoint,use_scale_shift_norm=use_scale_shift_norm,)]13 unmodified linesdim_head,context_dim=context_dim,depth=transformer_depth,use_checkpoint=use_checkpoint,ip_dim=self.ip_dim,ip_weight=self.ip_weight,)7 unmodified linesdropout,out_channels=out_ch,dims=dims,use_checkpoint=use_checkpoint,use_scale_shift_norm=use_scale_shift_norm,up=True,)38 unmodified lines394041424344192 unmodified lines23723823924024124220 unmodified lines26326426526626726826927014 unmodified lines28528628728828929014 unmodified lines305306307308309310212 unmodified lines5235245255265275287 unmodified lines5365375385395405413 unmodified lines54554654754854955039 unmodified lines59059159259359459534 unmodified lines63063163263363463519 unmodified lines65565665765865966059 unmodified lines72072172272372472567 unmodified lines79379479579679779813 unmodified lines81281381481581681711 unmodified lines82983083183283383420 unmodified lines8558568578588598602 unmodified lines8638648658668678682 unmodified lines87187287387487587610 unmodified lines88788888989089189213 unmodified lines9069079089099109117 unmodified lines91992092192292392438 unmodified linesreturn torch.from_numpy(np.stack(cameras, axis=0)).float() # [num_frames, 16]def timestep_embedding(timesteps, dim, max_period=10000, repeat_only=False):"""Create sinusoidal timestep embeddings.192 unmodified linescontext_dim,dropout=0.0,gated_ff=True,ip_dim=0,ip_weight=1,):20 unmodified linesself.norm1 = nn.LayerNorm(dim)self.norm2 = nn.LayerNorm(dim)self.norm3 = nn.LayerNorm(dim)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) + xx = rearrange(x, "b (f l) c -> (b f) l c", f=num_frames).contiguous()14 unmodified linesdropout=0.0,ip_dim=0,ip_weight=1,):super().__init__()14 unmodified linesd_head,context_dim=context_dim[d],dropout=dropout,ip_dim=ip_dim,ip_weight=ip_weight,)212 unmodified linesconvolution instead of a smaller 1x1 convolution to change thechannels in the skip connection.:param dims: determines if the signal is 1D, 2D, or 3D.:param up: if True, use this block for upsampling.:param down: if True, use this block for downsampling."""7 unmodified linesuse_conv=False,use_scale_shift_norm=False,dims=2,up=False,down=False,):3 unmodified linesself.dropout = dropoutself.out_channels = out_channels or channelsself.use_conv = use_convself.use_scale_shift_norm = use_scale_shift_normself.in_layers = nn.Sequential(39 unmodified linesself.skip_connection = conv_nd(dims, channels, self.out_channels, 1)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 beclass-conditional with `num_classes` classes.:param num_heads: the number of attention heads in each attention layer.:param num_heads_channels: if specified, ignore num_heads and instead usea fixed channel width per attention head.19 unmodified linesconv_resample=True,dims=2,num_classes=None,num_heads=-1,num_head_channels=-1,num_heads_upsample=-1,59 unmodified linesself.channel_mult = channel_multself.conv_resample = conv_resampleself.num_classes = num_classesself.num_heads = num_headsself.num_head_channels = num_head_channelsself.num_heads_upsample = num_heads_upsample67 unmodified linesdropout,out_channels=mult * model_channels,dims=dims,use_scale_shift_norm=use_scale_shift_norm,)]13 unmodified linesdim_head,context_dim=context_dim,depth=transformer_depth,ip_dim=self.ip_dim,ip_weight=self.ip_weight,)11 unmodified linesdropout,out_channels=out_ch,dims=dims,use_scale_shift_norm=use_scale_shift_norm,down=True,)20 unmodified linestime_embed_dim,dropout,dims=dims,use_scale_shift_norm=use_scale_shift_norm,),SpatialTransformer3D(2 unmodified linesdim_head,context_dim=context_dim,depth=transformer_depth,ip_dim=self.ip_dim,ip_weight=self.ip_weight,),2 unmodified linestime_embed_dim,dropout,dims=dims,use_scale_shift_norm=use_scale_shift_norm,),)10 unmodified linesdropout,out_channels=model_channels * mult,dims=dims,use_scale_shift_norm=use_scale_shift_norm,)]13 unmodified linesdim_head,context_dim=context_dim,depth=transformer_depth,ip_dim=self.ip_dim,ip_weight=self.ip_weight,)7 unmodified linesdropout,out_channels=out_ch,dims=dims,use_scale_shift_norm=use_scale_shift_norm,up=True,)
README.md+4
mv_unet.py-84