Module stringclasses 3
values | Name stringlengths 3 15 | MLX Python stringlengths 1.77k 25.6k | MLX Swift stringlengths 3.79k 44k | Notes stringclasses 1
value | Transformers / Diffusers .py (TODO) float64 | Unnamed: 6 float64 | Unnamed: 7 float64 | Unnamed: 8 float64 | Unnamed: 9 float64 | Unnamed: 10 float64 | Unnamed: 11 float64 | Unnamed: 12 float64 | Unnamed: 13 float64 | Unnamed: 14 float64 | Unnamed: 15 float64 | Unnamed: 16 float64 | Unnamed: 17 float64 | Unnamed: 18 float64 | Unnamed: 19 float64 | Unnamed: 20 float64 | Unnamed: 21 float64 | Unnamed: 22 float64 | Unnamed: 23 float64 | Unnamed: 24 float64 | Unnamed: 25 float64 | Unnamed: 26 float64 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
StableDiffusion | StableDiffusion | # Copyright © 2023-2024 Apple Inc.
import time
from typing import Optional, Tuple
import mlx.core as mx
from .model_io import (
_DEFAULT_MODEL,
load_autoencoder,
load_diffusion_config,
load_text_encoder,
load_tokenizer,
load_unet,
)
from .sampler import SimpleEulerAncestralSampler, SimpleEule... | // Copyright © 2024 Apple Inc.
import Foundation
import Hub
import MLX
import MLXNN
// port of https://github.com/ml-explore/mlx-examples/blob/main/stable_diffusion/stable_diffusion/__init__.py
/// Iterator that produces latent images.
///
/// Created by:
///
/// - ``TextToImageGenerator/generateLatents(parameters:)... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
StableDiffusion | Tokenizer | # Copyright © 2023 Apple Inc.
import regex
class Tokenizer:
"""A simple port of CLIPTokenizer from https://github.com/huggingface/transformers/ ."""
def __init__(self, bpe_ranks, vocab):
self.bpe_ranks = bpe_ranks
self.vocab = vocab
self.pat = regex.compile(
r"""<\|starto... | // Copyright © 2024 Apple Inc.
import Foundation
struct Bigram: Hashable {
let a: String
let b: String
init(_ s: String) {
let pieces = s.split(separator: " ")
precondition(pieces.count == 2, "BPEPair expected two pieces for '\(s)'")
self.a = String(pieces[0])
self.b = Str... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
StableDiffusion | Unet | # Copyright © 2023 Apple Inc.
import math
from typing import Optional
import mlx.core as mx
import mlx.nn as nn
from .config import UNetConfig
def upsample_nearest(x, scale: int = 2):
B, H, W, C = x.shape
x = mx.broadcast_to(x[:, :, None, :, None, :], (B, H, scale, W, scale, C))
x = x.reshape(B, H * sc... | // Copyright © 2024 Apple Inc.
import Foundation
import MLX
import MLXNN
// port of https://github.com/ml-explore/mlx-examples/blob/main/stable_diffusion/stable_diffusion/unet.py
func upsampleNearest(_ x: MLXArray, scale: Int = 2) -> MLXArray {
precondition(x.ndim == 4)
let (B, H, W, C) = x.shape4
var x ... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
StableDiffusion | VAE | # Copyright © 2023 Apple Inc.
import math
from typing import List
import mlx.core as mx
import mlx.nn as nn
from .config import AutoencoderConfig
from .unet import ResnetBlock2D, upsample_nearest
class Attention(nn.Module):
"""A single head unmasked attention for use with the VAE."""
def __init__(self, di... | // Copyright © 2024 Apple Inc.
import Foundation
import MLX
import MLXNN
// port of https://github.com/ml-explore/mlx-examples/blob/main/stable_diffusion/stable_diffusion/vae.py
class Attention: Module, UnaryLayer {
@ModuleInfo(key: "group_norm") public var groupNorm: GroupNorm
@ModuleInfo(key: "query_proj... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
StableDiffusion | CLIP | # Copyright © 2023-2024 Apple Inc.
from dataclasses import dataclass
from typing import List, Optional
import mlx.core as mx
import mlx.nn as nn
from .config import CLIPTextModelConfig
_ACTIVATIONS = {"quick_gelu": nn.gelu_fast_approx, "gelu": nn.gelu}
@dataclass
class CLIPOutput:
# The last_hidden_state inde... | // Copyright © 2024 Apple Inc.
import Foundation
import MLX
import MLXNN
// port of https://github.com/ml-explore/mlx-examples/blob/main/stable_diffusion/stable_diffusion/clip.py
struct CLIPOutput {
/// The lastHiddenState indexed at the EOS token and possibly projected if
/// the model has a projection laye... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
StableDiffusion | Config | # Copyright © 2023-2024 Apple Inc.
from dataclasses import dataclass
from typing import Optional, Tuple
@dataclass
class AutoencoderConfig:
in_channels: int = 3
out_channels: int = 3
latent_channels_out: int = 8
latent_channels_in: int = 4
block_out_channels: Tuple[int] = (128, 256, 512, 512)
... | // Copyright © 2024 Apple Inc.
import Foundation
import MLX
import MLXNN
// port of https://github.com/ml-explore/mlx-examples/blob/main/stable_diffusion/stable_diffusion/config.py
/// Configuration for ``Autoencoder``
struct AutoencoderConfiguration: Codable {
public var inputChannels = 3
public var output... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
StableDiffusion | Load | # Copyright © 2023-2024 Apple Inc.
import json
from typing import Optional
import mlx.core as mx
from huggingface_hub import hf_hub_download
from mlx.utils import tree_unflatten
from .clip import CLIPTextModel
from .config import AutoencoderConfig, CLIPTextModelConfig, DiffusionConfig, UNetConfig
from .tokenizer imp... | // Copyright © 2024 Apple Inc.
import Foundation
import Hub
import MLX
import MLXNN
// port of https://github.com/ml-explore/mlx-examples/blob/main/stable_diffusion/stable_diffusion/model_io.py
/// Configuration for loading stable diffusion weights.
///
/// These options can be tuned to conserve memory.
public struc... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
StableDiffusion | Sampler | # Copyright © 2023 Apple Inc.
import mlx.core as mx
from .config import DiffusionConfig
def _linspace(a, b, num):
x = mx.arange(0, num) / (num - 1)
return (b - a) * x + a
def _interp(y, x_new):
"""Interpolate the function defined by (arange(0, len(y)), y) at positions x_new."""
x_low = x_new.astyp... | // Copyright © 2024 Apple Inc.
import Foundation
import MLX
// port of https://github.com/ml-explore/mlx-examples/blob/main/stable_diffusion/stable_diffusion/sampler.py
/// Interpolate the function defined by `(0 ..< y.count) y)` at positions `xNew`.
func interpolate(y: MLXArray, xNew: MLXArray) -> MLXArray {
le... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
LM | Bitnet | # Copyright © 2023-2024 Apple Inc.
from dataclasses import dataclass
from functools import partial
from typing import Any, Dict, Optional, Union
import mlx.core as mx
import mlx.nn as nn
from .base import BaseModelArgs, create_attention_mask, scaled_dot_product_attention
from .bitlinear_layers import BitLinear
from ... | //
// Bitnet.swift
// mlx-swift-examples
//
// Created by John Mai on 2025/6/12.
//
import Foundation
import MLX
import MLXFast
import MLXLMCommon
import MLXNN
import Tokenizers
// port of https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/bitnet.py
private func makeBitLinearKernel() -> MLXFast.MLXFastK... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
LM | Cohere | # Copyright © 2023-2024 Apple Inc.
from dataclasses import dataclass
from typing import Any, Optional
import mlx.core as mx
import mlx.nn as nn
from .base import BaseModelArgs, create_attention_mask, scaled_dot_product_attention
@dataclass
class ModelArgs(BaseModelArgs):
model_type: str
hidden_size: int = ... | import Foundation
import MLX
import MLXLMCommon
import MLXNN
// port of https://github.com/ml-explore/mlx-examples/blob/main/llms/mlx_lm/models/cohere.py
private class Attention: Module {
let args: CohereConfiguration
let scale: Float
@ModuleInfo(key: "q_proj") var wq: Linear
@ModuleInfo(key: "k_pro... | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null | null |
End of preview. Expand in Data Studio
README.md exists but content is empty.
- Downloads last month
- 18