Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a search based document for DALL-E #109

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .fdignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
docs
.*
*/.*
*.ipynb
LICENSE
6 changes: 6 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
!.gitignore
!*
!*/*
cache_db.json
cache_tree.json
vector_cache
1 change: 1 addition & 0 deletions docs/cache_title.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"_default": {"1": {"path": "/README.md", "hash": "0c8cf0c67a41f4f8e7b16eacf23aa439", "title": "DALL-E's Discrete VAE PyTorch Package"}, "2": {"path": "/dall_e/__init__.py", "hash": "a2ad31846c456c5dd262ff3e610c7f51", "title": "DALL-E Model Loader"}, "3": {"path": "/dall_e/decoder.py", "hash": "167ae29ab96bf52a32f571768136de5d", "title": "DALL-E: Multigroup Convolutional Architecture"}, "4": {"path": "/dall_e/decoder.py:1-31", "hash": "d52e2cec072b3969e6e817669659da44", "title": "DecoderBlock: Neural Network Module for Convolutions and Identity Paths"}, "5": {"path": "/dall_e/decoder.py:32-54", "hash": "a3b5c6829b47300aa6f3624bd6eb809c", "title": "PyTorch Decoder Class: Forward Pass and Residual Paths"}, "6": {"path": "/dall_e/decoder.py:55-74", "hash": "6c24c98bf38b1371c2be2418bcffdd9c", "title": "DALL-E Neural Network Initialization"}, "7": {"path": "/dall_e/decoder.py:75-94", "hash": "1fbefc86698ab9fa845adfc466e70b1a", "title": "Encoder-Decoder Model in PyTorch"}, "8": {"path": "/dall_e/encoder.py", "hash": "6383eadd884947538edad2e37235b6e9", "title": "Dall-E Encoder Blocks and Neural Network Modules"}, "9": {"path": "/dall_e/encoder.py:1-31", "hash": "2fb8ace5910e0441c3bad2de24a6c2b7", "title": "EncoderBlock: Neural Network Encoder Module"}, "10": {"path": "/dall_e/encoder.py:32-56", "hash": "8841a8636148f5caf49e33de070385c8", "title": "Residual Convolutional Encoder Class"}, "11": {"path": "/dall_e/encoder.py:57-77", "hash": "1f78870eb5d37a07c99642df1f7b6e0a", "title": "Multi-Group Encoder Neural Network"}, "12": {"path": "/dall_e/encoder.py:77-93", "hash": "2f9d5fe05c8f88167b710c254b417574", "title": "Convolutional Neural Network Module"}, "13": {"path": "/dall_e/utils.py", "hash": "552e5e4523a9a66ef87593c354b6dd6b", "title": "Conv2d Class and Operations"}, "14": {"path": "/dall_e/utils.py:1-32", "hash": "9edfb4e0a1f4249a6b7a927dbfa229a6", "title": "Conv2D Layer Implementation"}, "15": {"path": "/dall_e/utils.py:33-59", "hash": "247e17199bc49bb2920c1c83bed30ca0", "title": "Convolution Utilities"}, "16": {"path": "/model_card.md", "hash": "39288813f85750d943afe91afe17537e", "title": "DVAE: Efficient but Fidelity Limited"}, "17": {"path": "/model_card.md:1-21", "hash": "30360226f34c4000ed480ee8a15aa968", "title": "Discrete VAE Model Card for DALL\u00b7E"}, "18": {"path": "/model_card.md:23-41", "hash": "72f3c5f49c0a78eb67d03c8bc49cd176", "title": "Unsuitable for High-Fidelity Image Compression"}, "19": {"path": "/notebooks/usage.py", "hash": "a32db587e530a6751718191a7f274a30", "title": "DALL-E Image Processing"}, "20": {"path": "/notebooks/usage.py:1-46", "hash": "3a117226a55d47b57fc635d41a59b0b1", "title": "Code for Image Processing and Downloads"}, "21": {"path": "/notebooks/usage.py:47-76", "hash": "f1662a832179b34fd852122af1bf2c19", "title": "Reconstruct DALL-E Images"}, "22": {"path": "/requirements.txt", "hash": "05a5350a9aee2a6a01bd692240cafbf2", "title": "Dependent Libraries for Codebase"}, "23": {"path": "/setup.py", "hash": "68de49c1050d99af666d83d3319c98e3", "title": "DALL-E: Discrete VAE PyTorch Package Setup"}}}
669 changes: 669 additions & 0 deletions docs/codeview.html

Large diffs are not rendered by default.

290 changes: 290 additions & 0 deletions docs/data/0.json

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions docs/data/titles/0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"/README.md": "DALL-E's Discrete VAE PyTorch Package",
"/dall_e/__init__.py": "DALL-E Model Loader",
"/dall_e/decoder.py": "DALL-E: Multigroup Convolutional Architecture",
"/dall_e/decoder.py:1-31": "DecoderBlock: Neural Network Module for Convolutions and Identity Paths",
"/dall_e/decoder.py:32-54": "PyTorch Decoder Class: Forward Pass and Residual Paths",
"/dall_e/decoder.py:55-74": "DALL-E Neural Network Initialization",
"/dall_e/decoder.py:75-94": "Encoder-Decoder Model in PyTorch",
"/dall_e/encoder.py": "Dall-E Encoder Blocks and Neural Network Modules",
"/dall_e/encoder.py:1-31": "EncoderBlock: Neural Network Encoder Module",
"/dall_e/encoder.py:32-56": "Residual Convolutional Encoder Class",
"/dall_e/encoder.py:57-77": "Multi-Group Encoder Neural Network",
"/dall_e/encoder.py:77-93": "Convolutional Neural Network Module",
"/dall_e/utils.py": "Conv2d Class and Operations",
"/dall_e/utils.py:1-32": "Conv2D Layer Implementation",
"/dall_e/utils.py:33-59": "Convolution Utilities",
"/model_card.md": "DVAE: Efficient but Fidelity Limited",
"/model_card.md:1-21": "Discrete VAE Model Card for DALL·E",
"/model_card.md:23-41": "Unsuitable for High-Fidelity Image Compression",
"/notebooks/usage.py": "DALL-E Image Processing",
"/notebooks/usage.py:1-46": "Code for Image Processing and Downloads",
"/notebooks/usage.py:47-76": "Reconstruct DALL-E Images",
"/requirements.txt": "Dependent Libraries for Codebase",
"/setup.py": "DALL-E: Discrete VAE PyTorch Package Setup"
}
25 changes: 25 additions & 0 deletions docs/doc/0c3fc06c-6184-4357-85d6-348275dd29c6.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"summary": "The code defines two classes, \"EncoderBlock\" and \"Encoder\", for neural network modules with 4 groups of 2 blocks each, using residual paths. It encodes input, performs max pooling, checks errors, and has various attributes for computation.",
"details": [
{
"comment": "This code defines a class named \"EncoderBlock\" which is a module for an encoder block in the neural network. It takes input parameters such as the number of input features (n_in), output features (n_out), and layers (n_layers). The module also has properties like device, requires_grad, and initializes instance variables n_hid, post_gain. It uses a partial function to make a convolution layer and creates an identity path and residual path for the encoder block.",
"location": "\"/media/root/Toshiba XG3/works/DALL-E/docs/src/dall_e/encoder.py\":0-30",
"content": "import attr\nimport numpy as np\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom collections import OrderedDict\nfrom functools import partial\nfrom dall_e.utils import Conv2d\[email protected](eq=False, repr=False)\nclass EncoderBlock(nn.Module):\n\tn_in: int = attr.ib(validator=lambda i, a, x: x >= 1)\n\tn_out: int = attr.ib(validator=lambda i, a, x: x >= 1 and x % 4 ==0)\n\tn_layers: int = attr.ib(validator=lambda i, a, x: x >= 1)\n\tdevice: torch.device = attr.ib(default=None)\n\trequires_grad: bool = attr.ib(default=False)\n\tdef __attrs_post_init__(self) -> None:\n\t\tsuper().__init__()\n\t\tself.n_hid = self.n_out // 4\n\t\tself.post_gain = 1 / (self.n_layers ** 2)\n\t\tmake_conv = partial(Conv2d, device=self.device, requires_grad=self.requires_grad)\n\t\tself.id_path = make_conv(self.n_in, self.n_out, 1) if self.n_in != self.n_out else nn.Identity()\n\t\tself.res_path = nn.Sequential(OrderedDict([\n\t\t\t\t('relu_1', nn.ReLU()),\n\t\t\t\t('conv_1', make_conv(self.n_in, self.n_hid, 3)),\n\t\t\t\t('relu_2', nn.ReLU()),"
},
{
"comment": "This code defines a class called \"Encoder\" which is a type of neural network module. It has 4 groups, each group containing 2 blocks of convolutional layers and activation functions. The input is passed through the identity path and the residual path, then their sum is returned as output. The Encoder class also has several attributes such as number of hidden units, number of block per group, input channels, vocabulary size, device to run on, requires gradient computation, and use mixed precision.",
"location": "\"/media/root/Toshiba XG3/works/DALL-E/docs/src/dall_e/encoder.py\":31-55",
"content": "\t\t\t\t('conv_2', make_conv(self.n_hid, self.n_hid, 3)),\n\t\t\t\t('relu_3', nn.ReLU()),\n\t\t\t\t('conv_3', make_conv(self.n_hid, self.n_hid, 3)),\n\t\t\t\t('relu_4', nn.ReLU()),\n\t\t\t\t('conv_4', make_conv(self.n_hid, self.n_out, 1)),]))\n\tdef forward(self, x: torch.Tensor) -> torch.Tensor:\n\t\treturn self.id_path(x) + self.post_gain * self.res_path(x)\[email protected](eq=False, repr=False)\nclass Encoder(nn.Module):\n\tgroup_count: int = 4\n\tn_hid: int = attr.ib(default=256, validator=lambda i, a, x: x >= 64)\n\tn_blk_per_group: int = attr.ib(default=2, validator=lambda i, a, x: x >= 1)\n\tinput_channels: int = attr.ib(default=3, validator=lambda i, a, x: x >= 1)\n\tvocab_size: int = attr.ib(default=8192, validator=lambda i, a, x: x >= 512)\n\tdevice: torch.device = attr.ib(default=torch.device('cpu'))\n\trequires_grad: bool = attr.ib(default=False)\n\tuse_mixed_precision: bool = attr.ib(default=True)\n\tdef __attrs_post_init__(self) -> None:\n\t\tsuper().__init__()\n\t\tblk_range = range(self.n_blk_per_group)"
},
{
"comment": "This code is creating a neural network encoder with multiple blocks. It consists of four groups, each with different number of layers and hidden size. Each group has a series of EncoderBlocks followed by a max pooling operation. The input channel size is defined based on the current block and group configuration.",
"location": "\"/media/root/Toshiba XG3/works/DALL-E/docs/src/dall_e/encoder.py\":56-76",
"content": "\t\tn_layers = self.group_count * self.n_blk_per_group\n\t\tmake_conv = partial(Conv2d, device=self.device, requires_grad=self.requires_grad)\n\t\tmake_blk = partial(EncoderBlock, n_layers=n_layers, device=self.device,\n\t\t\t\trequires_grad=self.requires_grad)\n\t\tself.blocks = nn.Sequential(OrderedDict([\n\t\t\t('input', make_conv(self.input_channels, 1 * self.n_hid, 7)),\n\t\t\t('group_1', nn.Sequential(OrderedDict([\n\t\t\t\t*[(f'block_{i + 1}', make_blk(1 * self.n_hid, 1 * self.n_hid)) for i in blk_range],\n\t\t\t\t('pool', nn.MaxPool2d(kernel_size=2)),\n\t\t\t]))),\n\t\t\t('group_2', nn.Sequential(OrderedDict([\n\t\t\t\t*[(f'block_{i + 1}', make_blk(1 * self.n_hid if i == 0 else 2 * self.n_hid, 2 * self.n_hid)) for i in blk_range],\n\t\t\t\t('pool', nn.MaxPool2d(kernel_size=2)),\n\t\t\t]))),\n\t\t\t('group_3', nn.Sequential(OrderedDict([\n\t\t\t\t*[(f'block_{i + 1}', make_blk(2 * self.n_hid if i == 0 else 4 * self.n_hid, 4 * self.n_hid)) for i in blk_range],\n\t\t\t\t('pool', nn.MaxPool2d(kernel_size=2)),\n\t\t\t]))),\n\t\t\t('group_4', nn.Sequential(OrderedDict([\n\t\t\t\t"
},
{
"comment": "The code defines a neural network module that takes an input tensor and passes it through multiple blocks of convolutional layers. The output is then processed by another set of convolutional layers before returning the final result. The function also includes error checks for the shape, number of channels, and data type of the input tensor to ensure proper functioning.",
"location": "\"/media/root/Toshiba XG3/works/DALL-E/docs/src/dall_e/encoder.py\":76-92",
"content": "*[(f'block_{i + 1}', make_blk(4 * self.n_hid if i == 0 else 8 * self.n_hid, 8 * self.n_hid)) for i in blk_range],\n\t\t\t]))),\n\t\t\t('output', nn.Sequential(OrderedDict([\n\t\t\t\t('relu', nn.ReLU()),\n\t\t\t\t('conv', make_conv(8 * self.n_hid, self.vocab_size, 1, use_float16=False)),\n\t\t\t]))),\n\t\t]))\n\tdef forward(self, x: torch.Tensor) -> torch.Tensor:\n\t\tif len(x.shape) != 4:\n\t\t\traise ValueError(f'input shape {x.shape} is not 4d')\n\t\tif x.shape[1] != self.input_channels:\n\t\t\traise ValueError(f'input has {x.shape[1]} channels but model built for {self.input_channels}')\n\t\tif x.dtype != torch.float32:\n\t\t\traise ValueError('input must have dtype torch.float32')\n\t\treturn self.blocks(x)"
}
]
}
10 changes: 10 additions & 0 deletions docs/doc/2702f9ef-853c-453e-a9d3-52a7f948e47d.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"summary": "Installed packages for codebase: Pillow, blobfile, mypy, numpy, pytest, requests, torch, torchvision.",
"details": [
{
"comment": "Installed packages for codebase: Pillow, blobfile, mypy, numpy, pytest, requests, torch, torchvision.",
"location": "\"/media/root/Toshiba XG3/works/DALL-E/docs/src/requirements.txt\":0-7",
"content": "Pillow\nblobfile\nmypy\nnumpy\npytest\nrequests\ntorch\ntorchvision"
}
]
}
10 changes: 10 additions & 0 deletions docs/doc/6a64bc63-97f1-469f-8134-72ca11c14704.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"summary": "This is the official PyTorch package for DALL-E's discrete VAE. Transformer for image generation from text not included. Install using pip install DALL-E.",
"details": [
{
"comment": "This is the official PyTorch package for DALL-E's discrete VAE. Transformer for image generation from text not included. Install using pip install DALL-E.",
"location": "\"/media/root/Toshiba XG3/works/DALL-E/docs/src/README.md\":0-10",
"content": "# Overview\n[[Blog]](https://openai.com/blog/dall-e/) [[Paper]](https://arxiv.org/abs/2102.12092) [[Model Card]](model_card.md) [[Usage]](notebooks/usage.ipynb)\nThis is the official PyTorch package for the discrete VAE used for DALL\u00b7E. The transformer used to generate the images from the text is not part of this code release.\n# Installation\nBefore running [the example notebook](notebooks/usage.ipynb), you will need to install the package using\n\tpip install DALL-E"
}
]
}
10 changes: 10 additions & 0 deletions docs/doc/6e2219bf-c085-433e-9e45-71ef30ea0a5a.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"summary": "The code imports necessary libraries, defines a function load_model that loads the DALL-E model from a given path, and handles loading the model from either URL or local file.",
"details": [
{
"comment": "The code imports necessary libraries, defines a function load_model that loads the DALL-E model from a given path, and handles loading the model from either URL or local file.",
"location": "\"/media/root/Toshiba XG3/works/DALL-E/docs/src/dall_e/__init__.py\":0-17",
"content": "import io, requests\nimport torch\nimport torch.nn as nn\nfrom dall_e.encoder import Encoder\nfrom dall_e.decoder import Decoder\nfrom dall_e.utils import map_pixels, unmap_pixels\ndef load_model(path: str, device: torch.device = None) -> nn.Module:\n if path.startswith('http://') or path.startswith('https://'):\n resp = requests.get(path)\n resp.raise_for_status()\n with io.BytesIO(resp.content) as buf:\n return torch.load(buf, map_location=device)\n else:\n with open(path, 'rb') as f:\n return torch.load(f, map_location=device)"
}
]
}
Loading