Text Generation
Transformers
PyTorch
English
burt-imma
custom-architecture
matrix-memory
equilibrium-propagation
cifg
sovereign
snapkitty
no-backprop
formal-verification
lean4
agents
python
Instructions to use Snapkitty/burt-imma with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Snapkitty/burt-imma with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Snapkitty/burt-imma")# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Snapkitty/burt-imma", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Snapkitty/burt-imma with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Snapkitty/burt-imma" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Snapkitty/burt-imma", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Snapkitty/burt-imma
- SGLang
How to use Snapkitty/burt-imma with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Snapkitty/burt-imma" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Snapkitty/burt-imma", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Snapkitty/burt-imma" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Snapkitty/burt-imma", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Snapkitty/burt-imma with Docker Model Runner:
docker model run hf.co/Snapkitty/burt-imma
File size: 6,924 Bytes
b88c26d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | /-
SmoothLeakyActivation
Smooth leaky activation function with bounded gradient properties
-/
import Mathlib
import Mathlib.Analysis.SpecialFunctions.Log.Basic
import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basic
import Mathlib.Analysis.Calculus.Deriv.Basic
noncomputable section
open Real
-- ============================================================
-- Parameters
-- ============================================================
structure Params where
alpha : β
beta : β
h_alpha_pos : 0 < alpha
h_alpha_lt_one : alpha < 1
h_beta_pos : 0 < beta
-- ============================================================
-- Activation Function
-- Standard smooth leaky ReLU: f(x) = (1+Ξ±)/2 * x + (1-Ξ±)/2 * (1/Ξ²) * log(cosh(Ξ²x))
-- Derivative: f'(x) = (1+Ξ±)/2 + (1-Ξ±)/2 * tanh(Ξ²x) β (Ξ±, 1)
-- ============================================================
/-- The smooth leaky activation function -/
def f (p : Params) (x : β) : β :=
(1 + p.alpha) / 2 * x + (1 - p.alpha) / 2 * (1 / p.beta) * Real.log (Real.cosh (p.beta * x))
/-- The derivative of the smooth leaky activation -/
def f' (p : Params) (x : β) : β :=
(1 + p.alpha) / 2 + (1 - p.alpha) / 2 * Real.tanh (p.beta * x)
-- ============================================================
-- Properties
-- ============================================================
/-- The gradient is always strictly positive -/
theorem deriv_pos (p : Params) : β x : β, f' p x > 0 := by
intro x
have hβ : f' p x = (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * Real.tanh (p.beta * x) := rfl
rw [hβ]
have hβ : Real.tanh (p.beta * x) > -1 := Real.neg_one_lt_tanh (p.beta * x)
have hβ : 0 < p.alpha := p.h_alpha_pos
have hβ
: p.alpha < 1 := p.h_alpha_lt_one
have hβ : 0 < 1 - p.alpha := by linarith
have hβ : 0 < 1 + p.alpha := by linarith
have hββ : (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * Real.tanh (p.beta * x) β₯
(1 + p.alpha) / 2 + (1 - p.alpha) / 2 * (-1) := by
have hββ : Real.tanh (p.beta * x) β₯ -1 := by linarith
nlinarith
have hββ : (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * (-1 : β) = p.alpha := by ring
linarith [p.h_alpha_pos]
/-- The gradient is bounded below 1 -/
theorem deriv_bounded (p : Params) : β x : β, f' p x < 1 := by
intro x
have hβ : f' p x = (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * Real.tanh (p.beta * x) := rfl
rw [hβ]
have hβ : Real.tanh (p.beta * x) < 1 := Real.tanh_lt_one (p.beta * x)
have hβ
: p.alpha < 1 := p.h_alpha_lt_one
have hβ : 0 < 1 - p.alpha := by linarith
have hββ : (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * Real.tanh (p.beta * x) <
(1 + p.alpha) / 2 + (1 - p.alpha) / 2 * (1 : β) := by nlinarith
have hββ : (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * (1 : β) = 1 := by ring
linarith
/-- As x β +β, f'(x) β 1 -/
theorem deriv_limit_pos_inf (p : Params) :
Filter.Tendsto (f' p) Filter.atTop (nhds 1) := by
have htanh : Filter.Tendsto (fun x : β => Real.tanh (p.beta * x)) Filter.atTop (nhds 1) := by
have hbeta : Filter.Tendsto (fun x : β => p.beta * x) Filter.atTop Filter.atTop :=
Filter.Tendsto.atTop_mul_atTop (by linarith [p.h_beta_pos]) Filter.tendsto_id
exact Real.tendsto_tanh_atTop.comp hbeta
have : Filter.Tendsto (fun x : β => (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * Real.tanh (p.beta * x))
Filter.atTop (nhds ((1 + p.alpha) / 2 + (1 - p.alpha) / 2 * 1)) :=
Filter.Tendsto.const_add _ (Filter.Tendsto.const_mul _ htanh)
have heq : (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * 1 = 1 := by ring
simp only [f']
rwa [heq] at this
/-- As x β -β, f'(x) β alpha -/
theorem deriv_limit_neg_inf (p : Params) :
Filter.Tendsto (f' p) Filter.atBot (nhds p.alpha) := by
have htanh : Filter.Tendsto (fun x : β => Real.tanh (p.beta * x)) Filter.atBot (nhds (-1)) := by
have hbeta : Filter.Tendsto (fun x : β => p.beta * x) Filter.atBot Filter.atBot :=
Filter.Tendsto.atBot_mul_atBot (by linarith [p.h_beta_pos]) Filter.tendsto_id
exact Real.tendsto_tanh_atBot.comp hbeta
have : Filter.Tendsto (fun x : β => (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * Real.tanh (p.beta * x))
Filter.atBot (nhds ((1 + p.alpha) / 2 + (1 - p.alpha) / 2 * (-1))) :=
Filter.Tendsto.const_add _ (Filter.Tendsto.const_mul _ htanh)
have heq : (1 + p.alpha) / 2 + (1 - p.alpha) / 2 * (-1) = p.alpha := by ring
simp only [f']
rwa [heq] at this
/-- f is C^β (infinitely differentiable) -/
theorem smooth (p : Params) : ContDiff β β€ (f p) := by
have h_lin : ContDiff β β€ (fun x : β => (1 + p.alpha) / 2 * x) :=
(contDiff_const.mul contDiff_id)
have h_cosh : ContDiff β β€ (fun x : β => Real.cosh (p.beta * x)) :=
Real.contDiff_cosh.comp (contDiff_const.mul contDiff_id)
have h_pos : β x : β, Real.cosh (p.beta * x) > 0 := fun x => Real.cosh_pos _
have h_log : ContDiff β β€ (fun x : β => Real.log (Real.cosh (p.beta * x))) :=
h_cosh.log (fun x => ne_of_gt (h_pos x))
have h_scaled : ContDiff β β€ (fun x : β => (1 - p.alpha) / 2 * (1 / p.beta) * Real.log (Real.cosh (p.beta * x))) :=
contDiff_const.mul h_log
simp only [f]
exact h_lin.add h_scaled
/-- f(x) < 0 for all x < 0 -/
theorem neg_range (p : Params) : β x : β, x < 0 β f p x < 0 := by
intro x hx
simp only [f]
have hβ : 0 < p.beta := p.h_beta_pos
have hβ
: 0 < 1 + p.alpha := by linarith [p.h_alpha_pos]
have hβ : 0 < 1 - p.alpha := by linarith [p.h_alpha_lt_one]
have hβ : (0 : β) < 1 / p.beta := by positivity
have hβ : Real.log (Real.cosh (p.beta * x)) β₯ 0 :=
Real.log_nonneg (Real.one_le_cosh _)
have hβ : (1 + p.alpha) / 2 * x < 0 := by nlinarith
have hββ : Real.log (Real.cosh (p.beta * x)) β€ p.beta * |x| := by
have hle : Real.cosh (p.beta * x) β€ Real.exp (p.beta * |x|) := by
calc Real.cosh (p.beta * x)
β€ Real.cosh (|p.beta * x|) := Real.cosh_abs _ βΈ le_refl _
_ = Real.cosh (p.beta * |x|) := by
rw [abs_mul, abs_of_pos hβ]
_ β€ Real.exp (p.beta * |x|) := Real.cosh_le_exp _
linarith [Real.log_le_log (Real.cosh_pos _) hle,
Real.log_exp (p.beta * |x|)]
have hββ : |x| = -x := abs_of_neg hx
rw [hββ] at hββ
have hββ : (1 - p.alpha) / 2 * (1 / p.beta) * Real.log (Real.cosh (p.beta * x))
β€ (1 - p.alpha) / 2 * (-x) := by
have : (1 - p.alpha) / 2 * (1 / p.beta) * (p.beta * (-x)) = (1 - p.alpha) / 2 * (-x) := by
field_simp
nlinarith
have hββ
: (1 + p.alpha) / 2 * x + (1 - p.alpha) / 2 * (-x) = p.alpha * x := by ring
linarith [mul_neg_of_pos_of_neg p.h_alpha_pos hx]
/-- f(0) = 0 -/
theorem f_zero (p : Params) : f p 0 = 0 := by
simp [f, Real.cosh_zero, Real.log_one]
end
|