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
fix mvdream
Browse filesFiles changed (6)
3 unmodified lines45673 unmodified lines*.pycweightssd-v2*3 unmodified lines456783 unmodified lines*.pycweightsmodelssd-v2*
3 unmodified lines4567893 unmodified lines### convert weights```bash# download original ckptwget https://huggingface.co/MVDream/MVDream/resolve/main/sd-v2.1-base-4view.ptwget https://raw.githubusercontent.com/bytedance/MVDream/main/mvdream/configs/sd-v2-base.yaml3 unmodified lines4567891011123 unmodified lines### convert weights```bash# dependencypip install -U omegaconf diffusers safetensors huggingface_hub transformers accelerate# download original ckptwget https://huggingface.co/MVDream/MVDream/resolve/main/sd-v2.1-base-4view.ptwget https://raw.githubusercontent.com/bytedance/MVDream/main/mvdream/configs/sd-v2-base.yaml
404 unmodified lines405406407408409410404 unmodified lines# )# print(f"Unet Config: {original_config.model.params.unet_config.params}")unet_config = create_unet_config(original_config)unet = MultiViewUNetModel(**unet_config)unet.register_to_config(**unet_config)# print(f"Unet State Dict: {unet.state_dict().keys()}")404 unmodified lines405406407408409410411412413414415416404 unmodified lines# )# print(f"Unet Config: {original_config.model.params.unet_config.params}")unet_config = create_unet_config(original_config)# remove unused configsdel unet_config['legacy']del unet_config['use_linear_in_transformer']del unet_config['use_spatial_transformer']unet = MultiViewUNetModel(**unet_config)unet.register_to_config(**unet_config)# print(f"Unet State Dict: {unet.state_dict().keys()}")
1234567 unmodified lines141516171819202122# obtained and modified from https://github.com/bytedance/MVDreamimport mathimport torchimport torch.nn as nnimport torch.nn.functional as F7 unmodified linestry:import xformers # type: ignoreimport xformers.ops # type: ignoreXFORMERS_IS_AVAILBLE = Trueexcept:XFORMERS_IS_AVAILBLE = False# CrossAttn precision handling1237 unmodified lines111213141516171819import torchimport torch.nn as nnimport torch.nn.functional as F7 unmodified linestry:import xformers # type: ignoreimport xformers.ops # type: ignoreXFORMERS_IS_AVAILBLE = Trueexcept:print(f'[WARN] xformers is unavailable!')XFORMERS_IS_AVAILBLE = False# CrossAttn precision handling
1234562 unmodified lines91011121314153 unmodified lines192021222324252627282930313233343536371 unmodified line3940414243444571 unmodified lines117118119120121122123165 unmodified lines28929029129229329488 unmodified lines38338438538638738838940 unmodified lines43043143243343443543643743843944044144221 unmodified lines46446546646746846947079 unmodified lines550551552553554555556# obtained and modified from https://github.com/bytedance/MVDreamimport mathimport torchimport torch.nn as nnimport torch.nn.functional as F2 unmodified linesfrom typing import Any, List, Optionalfrom torch import Tensorfrom abc import abstractmethodfrom .util import (checkpoint,conv_nd,3 unmodified lines)from .attention import SpatialTransformer, SpatialTransformer3Dclass TimestepBlock(nn.Module):"""Any module where forward() takes timestep embeddings as a second argument."""@abstractmethoddef forward(self, x, emb):"""Apply the module to `x` given `emb` timestep embeddings."""class TimestepEmbedSequential(nn.Sequential, TimestepBlock):"""A sequential module that passes timestep embeddings to the children thatsupport it as an extra input.1 unmodified linedef forward(self, x, emb, context=None, num_frames=1):for layer in self:if isinstance(layer, TimestepBlock):x = layer(x, emb)elif isinstance(layer, SpatialTransformer3D):x = layer(x, context, num_frames=num_frames)71 unmodified linesreturn self.op(x)class ResBlock(TimestepBlock):"""A residual block that can optionally change the number of channels.:param channels: the number of input channels.165 unmodified linesdisable_middle_self_attn=False,adm_in_channels=None,camera_dim=None,):super().__init__()assert context_dim is not None88 unmodified linesself.input_blocks = nn.ModuleList([TimestepEmbedSequential(conv_nd(dims, in_channels, model_channels, 3, padding=1))]40 unmodified linesuse_checkpoint=use_checkpoint,))self.input_blocks.append(TimestepEmbedSequential(*layers))self._feature_size += chinput_block_chans.append(ch)if level != len(channel_mult) - 1:out_ch = chself.input_blocks.append(TimestepEmbedSequential(ResBlock(ch,time_embed_dim,21 unmodified linesnum_heads = ch // num_head_channelsdim_head = num_head_channelsself.middle_block = TimestepEmbedSequential(ResBlock(ch,time_embed_dim,79 unmodified lineselse Upsample(ch, conv_resample, dims=dims, out_channels=out_ch))ds //= 2self.output_blocks.append(TimestepEmbedSequential(*layers))self._feature_size += chself.out = nn.Sequential(1232 unmodified lines678910113 unmodified lines15161718192021221 unmodified line2425262728293071 unmodified lines102103104105106107108165 unmodified lines27427527627727827928088 unmodified lines36937037137237337437540 unmodified lines41641741841942042142242342442542642742821 unmodified lines45045145245345445545679 unmodified lines536537538539540541542import torchimport torch.nn as nnimport torch.nn.functional as F2 unmodified linesfrom typing import Any, List, Optionalfrom torch import Tensorfrom .util import (checkpoint,conv_nd,3 unmodified lines)from .attention import SpatialTransformer, SpatialTransformer3Dclass CondSequential(nn.Sequential):"""A sequential module that passes timestep embeddings to the children thatsupport it as an extra input.1 unmodified linedef forward(self, x, emb, context=None, num_frames=1):for layer in self:if isinstance(layer, ResBlock):x = layer(x, emb)elif isinstance(layer, SpatialTransformer3D):x = layer(x, context, num_frames=num_frames)71 unmodified linesreturn self.op(x)class ResBlock(nn.Module):"""A residual block that can optionally change the number of channels.:param channels: the number of input channels.165 unmodified linesdisable_middle_self_attn=False,adm_in_channels=None,camera_dim=None,**kwargs,):super().__init__()assert context_dim is not None88 unmodified linesself.input_blocks = nn.ModuleList([CondSequential(conv_nd(dims, in_channels, model_channels, 3, padding=1))]40 unmodified linesuse_checkpoint=use_checkpoint,))self.input_blocks.append(CondSequential(*layers))self._feature_size += chinput_block_chans.append(ch)if level != len(channel_mult) - 1:out_ch = chself.input_blocks.append(CondSequential(ResBlock(ch,time_embed_dim,21 unmodified linesnum_heads = ch // num_head_channelsdim_head = num_head_channelsself.middle_block = CondSequential(ResBlock(ch,time_embed_dim,79 unmodified lineselse Upsample(ch, conv_resample, dims=dims, out_channels=out_ch))ds //= 2self.output_blocks.append(CondSequential(*layers))self._feature_size += chself.out = nn.Sequential(
123456789101112# adopted from# https://github.com/openai/improved-diffusion/blob/main/improved_diffusion/gaussian_diffusion.py# and# https://github.com/lucidrains/denoising-diffusion-pytorch/blob/7706bdfc6f527f58d33f84b7b522e61e6e3164b3/denoising_diffusion_pytorch/denoising_diffusion_pytorch.py# and# https://github.com/openai/guided-diffusion/blob/0ba878e517b276c45d1195eb29f6f5f72659a05b/guided_diffusion/nn.py## thanks!import mathimport torchimport torch.nn as nn123import mathimport torchimport torch.nn as nn
.gitignore+1
README.md+3
convert_mvdream_to_diffusers.py+6
mvdream/attention.py+1-4
mvdream/models.py+9-23
mvdream/util.py-9