Skip to content

Instantly share code, notes, and snippets.

View jfischoff's full-sized avatar
™️
Jonathaning

Jonathan Fischoff jfischoff

™️
Jonathaning
View GitHub Profile
@jfischoff
jfischoff / diff_loss.py
Created November 13, 2023 17:03
Random Start Frame Diff Loss
def frame_diff_with_anchor(video_tensor, anchor_frame_index):
"""
Compute the frame difference for a video tensor using an anchor frame.
video_tensor should have shape (batch_size, channels, frames, height, width)
anchor_frame_index is the index of the anchor frame around which diffs are computed
"""
# Ensure that the anchor frame is within the correct range
num_frames = video_tensor.shape[2]
if not (0 <= anchor_frame_index < num_frames):
raise ValueError("anchor_frame_index is out of range.")
@jfischoff
jfischoff / run.py
Created July 14, 2023 06:13
AnimateDiff simple runner
from pathlib import Path
from animatediff.pipelines.pipeline_animation import AnimationPipeline
import torch
from diffusers import AutoencoderKL, DDIMScheduler, EulerAncestralDiscreteScheduler
from tqdm.auto import tqdm
from transformers import CLIPTextModel, CLIPTokenizer
from animatediff.models.unet import UNet3DConditionModel
from diffusers.utils.import_utils import is_xformers_available
from safetensors import safe_open
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE OverloadedStrings #-}
postgres=# explain (analyze, buffers) UPDATE payloads
postgres-# SET state='dequeued'
postgres-# WHERE id in
postgres-# ( SELECT p1.id
postgres(# FROM payloads AS p1
postgres(# WHERE p1.state='enqueued'
postgres(# ORDER BY p1.modified_at ASC
postgres(# FOR UPDATE SKIP LOCKED
postgres(# LIMIT 1
postgres(# )
CREATE OR REPLACE FUNCTION enqueue(count int8, x anyarray) RETURNS void AS $$
DECLARE
startValue int8;
lastValue int8;
currentValue int8;
partition_name text;
doubleCount int8;
BEGIN
doubleCount := 2 * count;
SELECT nextval('modified_index') INTO currentValue ;
2019-12-29 21:13:35 GMT [42602]: LOG: duration: 2.476 ms plan:
Query Text: INSERT INTO users (email, password, name) VALUES ('example@example1.com', 'password', 'name1') RETURNING id
Insert on public.users (cost=0.00..0.02 rows=1 width=382) (actual time=2.471..2.472 rows=1 loops=1)
Output: id
Buffers: shared hit=9 read=11 dirtied=9
I/O Timings: read=1.879
-> Result (cost=0.00..0.02 rows=1 width=382) (actual time=1.100..1.100 rows=1 loops=1)
Output: nextval('users_id_seq'::regclass), clock_timestamp(), clock_timestamp(), 'example@example1.com'::character varying(140), '\x70617373776f7264'::bytea, 'name1'::text
Buffers: shared hit=9 read=4 dirtied=2
I/O Timings: read=1.028
aroundAll :: forall a. ((a -> IO ()) -> IO ()) -> SpecWith a -> Spec
aroundAll withFunc specWith = do
(var, stopper, asyncer) <- runIO $
(,,) <$> newEmptyMVar <*> newEmptyMVar <*> newIORef Nothing
let theStart :: IO a
theStart = do
thread <- async $ do
withFunc $ \x -> do
putMVar var x
-- I think this is a a monoid. Basically it is used to either mappend to a value or replace the value
data Lastoid a = Replace a | Mappend a | Nope
instance Semigroup a => Semigroup (Lastoid a) where
x <> y = case (x, y) of
(r@Replace {}, _ ) -> r
(Mappend a , Replace b) -> Replace $ a <> b
(Mappend a , Mappend b) -> Mappend $ a <> b
(Nope , x ) -> x
type WidgetFlow t m a = Workflow t (VtyWidget t m) a
testScreen
:: (Reflex t, Show a, Show b, Monad m)
=> a
-- ^ Input
-> (a -> VtyWidget t m (Event t b))
-- ^ Screen to test
-> (b -> WidgetFlow t m ())
-- ^ Next continuation
-- What I am struggling to do is sequence to looping things. First I have a loop where the output is feed into the
-- next step as input until it completes. Then the next loop starts.
-- I doubt this works ... I'm trying to test it now ... anyway I don't like it and feel like
-- there must be an easier way.
advance :: (Adjustable t m, MonadHold t m, Monad m, MonadFix m)
=> m (Event t (Maybe a))
-- ^ initial
-> (a -> m (Event t (Maybe a)))