Skip to content

Instantly share code, notes, and snippets.

View malcolmgreaves's full-sized avatar

Malcolm Greaves malcolmgreaves

View GitHub Profile
Hugging Face Optimized Inference License 1.0 (HFOILv1.0)
This License Agreement governs the use of the Software and its Modifications. It is a
binding agreement between the Licensor and You.
This License Agreement shall be referred to as Hugging Face Optimized Inference License
1.0 or HFOILv1.0. We may publish revised versions of this License Agreement from time to
time. Each version will be given a distinguished number.
@malcolmgreaves
malcolmgreaves / unix_program_shortcuts.md
Created July 27, 2023 17:34
Helpful unix shortcuts

Unix Program Shortcuts

Files

Need to transfer data locally or remote? Support efficient re-connect and dedupe? Want summary progress information?

rsync -a --info=progress2 --recursive [SOURCE] ... [DEST]
from dataclasses import dataclass
from typing import Collection, Dict, Iterator, Optional, Set
import torch
def torchscript(model: torch.nn.Module) -> torch.ScriptModule:
"""Runs TorchScript's scripting mode on the input model.
A torch scripted model is able to run in a Python-free execution environment,
ideal for production inference.
from concurrent.futures import ProcessPoolExecutor
from multiprocessing import BoundedSemaphore
from typing import Optional, Sequence
from concurrent_utils import BoundedPoolExecutor
__all__: Sequence[str] = ("BoundedProcessPoolExecutor",)
class BoundedProcessPoolExecutor(ProcessPoolExecutor, BoundedPoolExecutor):
from concurrent.futures import ThreadPoolExecutor
from threading import BoundedSemaphore, Lock
from typing import Optional, Sequence
from concurrent_utils import BoundedPoolExecutor
__all__: Sequence[str] = (
"BoundedThreadPoolExecutor",
"IsDone",
)
import threading
from abc import ABC
from concurrent.futures import Executor, Future
from multiprocessing import synchronize
from typing import Optional, Sequence, Union
__all__: Sequence[str] = ("BoundedPoolExecutor",)
class BoundedPoolExecutor(ABC, Executor):
@malcolmgreaves
malcolmgreaves / dataclass_destructing_syntax_support.py
Last active June 20, 2023 15:58
Adds syntactic support to destructing an @DataClass into field-values the same way a NamedTuple (or tuple) is.
from abc import ABC
from typing import Any, Iterable, Tuple
from dataclasses import dataclass
from functools import partial
@dataclass
class TupleDestructureSyntax(ABC):
"""Allows any @dataclass class to be decomposed into its fields & values as if it were a tuple.
@malcolmgreaves
malcolmgreaves / enum_parser.py
Last active May 3, 2023 22:40
Function to create a function that can parse `str -> Enum instance` and one from `Enum instance -> str`.
from enum import Enum
from typing import Callable, Optional, Type, TypeVar
class EnumStr(str, Enum):
pass
E = TypeVar('E', bound=EnumStr)
@malcolmgreaves
malcolmgreaves / git_branch_commits_in_ecr_repo.py
Created April 14, 2023 17:37
Get the image tags for an AWS ECR repo that exist within a branch. Prints them to STDOUT in descending order of pushed date.
"""
Use as:
REPO='ecr-repo-name' BRANCH='main' python git_branch_commits_in_ecr_repo.py
You can pipe this to `cut -f1 -s` to get the commits only. Or `-f2` to get the pushed by date only.
These values are separated by a tab (`"\t"`).
"""
import json
import os
@malcolmgreaves
malcolmgreaves / descent_torchscript_iterating.py
Last active February 21, 2023 21:01
descent_script: A function that recursively expands a model's children and TorchScripts everything, making it easy to identify which network parts are and are not TorchScript compatible.
import traceback
from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Iterator, Sequence, Union
import torch
from core_utils.common import type_name
__all__: Sequence[str] = (
"descent_script",