Skip to main content

miscellaneous python utilities

Project description

PyPI PyPI - Downloads docs

Checks Checks Coverage

GitHub commits GitHub commit activity GitHub closed pull requests code size, bytes

muutils, stylized as "$\mu$utils" or "μutils", is a collection of miscellaneous python utilities, meant to be small and with no dependencies outside of standard python.

installation

PyPi: muutils

pip install muutils

Note that for using mlutils, tensor_utils, nbutils.configure_notebook, or the array serialization features of json_serialize, you will need to install with optional array dependencies:

pip install muutils[array]

documentation

hosted html docs: https://miv.name/muutils

modules

statcounter

an extension of collections.Counter that provides "smart" computation of stats (mean, variance, median, other percentiles) from the counter object without using Counter.elements()

dictmagic

has utilities for working with dictionaries, like:

  • converting dotlist-dictionaries to nested dictionaries and back:
    >>> dotlist_to_nested_dict({'a.b.c': 1, 'a.b.d': 2, 'a.e': 3})
    {'a': {'b': {'c': 1, 'd': 2}, 'e': 3}}
    >>> nested_dict_to_dotlist({'a': {'b': {'c': 1, 'd': 2}, 'e': 3}})
    {'a.b.c': 1, 'a.b.d': 2, 'a.e': 3}
    
  • DefaulterDict which works like a defaultdict but can generate the default value based on the key
  • condense_tensor_dict takes a dict of dotlist-tensors and gives a more human-readable summary:
    >>> model = MyGPT()
    >>> print(condense_tensor_dict(model.named_parameters(), 'yaml'))
    
    embed:
        W_E: (50257, 768)
    pos_embed:
        W_pos: (1024, 768)
    blocks:
      '[0-11]':
        attn:
        	'[W_Q, W_K, W_V]': (12, 768, 64)
        W_O: (12, 64, 768)
        	'[b_Q, b_K, b_V]': (12, 64)
        b_O: (768,)
    <...>
    

kappa

Anonymous gettitem, so you can do things like

>>> k = Kappa(lambda x: x**2)
>>> k[2]
4

sysinfo

utility for getting a bunch of system information. useful for logging.

misc:

contains a few utilities: - stable_hash() uses hashlib.sha256 to compute a hash of an object that is stable across runs of python - list_join and list_split which behave like str.join and str.split but for lists - sanitize_fname and dict_to_filename for simplifying the creation of unique filename - shorten_numerical_to_str() and str_to_numeric turns numbers like 123456789 into "123M" and back - freeze, which prevents an object from being modified. Also see gelidum

nbutils

contains utilities for working with jupyter notebooks, such as:

  • quickly converting notebooks to python scripts (and running those scripts) for testing in CI
  • configuring notebooks, to make it easier to switch between figure output formats, locations, and more
  • shorthand for displaying mermaid diagrams and TeX

json_serialize

a tool for serializing and loading arbitrary python objects into json. plays nicely with ZANJ

[tensor_utils]

contains minor utilities for working with pytorch tensors and numpy arrays, mostly for making type conversions easier

group_equiv

groups elements from a sequence according to a given equivalence relation, without assuming that the equivalence relation obeys the transitive property

jsonlines

an extremely simple utility for reading/writing jsonl files

ZANJ

is a human-readable and simple format for ML models, datasets, and arbitrary objects. It's build around having a zip file with json and npy files, and has been spun off into its own project.

There are a couple work-in-progress utilities in _wip that aren't ready for anything, but nothing in this repo is suitable for production. Use at your own risk!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

muutils-0.6.15.tar.gz (2.0 MB view details)

Uploaded Source

Built Distribution

muutils-0.6.15-py3-none-any.whl (123.4 kB view details)

Uploaded Python 3

File details

Details for the file muutils-0.6.15.tar.gz.

File metadata

  • Download URL: muutils-0.6.15.tar.gz
  • Upload date:
  • Size: 2.0 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for muutils-0.6.15.tar.gz
Algorithm Hash digest
SHA256 fa3d08cd18471d6a1feec4ed7f6517a833cd70e6a2b046b0f5b62c8f7b811a19
MD5 489b09ac4105cb842f0c1cd0a7f3953a
BLAKE2b-256 4327e76e521df193d1a33a3ff0d1a7159eeac511f7d0268a4068edd7b92edd87

See more details on using hashes here.

File details

Details for the file muutils-0.6.15-py3-none-any.whl.

File metadata

  • Download URL: muutils-0.6.15-py3-none-any.whl
  • Upload date:
  • Size: 123.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for muutils-0.6.15-py3-none-any.whl
Algorithm Hash digest
SHA256 5a12944dd13009a2fa15fd8f8c0d4baf6996cb554e0ddc513f1ba5b05b513e90
MD5 c0fa3ed913bc22f351fb2e5c94c03045
BLAKE2b-256 695feb814fa61a81e8d6ddaa45d47dc98dea8f66f7cfff2f85865f42bbe6edd9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page