functools.partial

functools.partial

Speed up costly LLM API calls with a tiny in‑memory cache using Python’s functools.lru_cache. Learn how a simple decorator can slash latency, reduce token costs, and keep your workflow pure Python—no extra services needed. Code snippets, performance graphs, and tips for swapping in diskcache when memory runs low. #Python #LLM #functools #LRUCache
🔗 https://aidailypost.com/news/python-functools-inmemory-caching-speeds-expensive-llm-api-calls
Mia Bajić: The Standard Library Tour @ PyCon Ireland 2023
The Standard Library Tour is designed to provide attendees with an understanding of Python's standard library less known features. Have you ever found yourself writing complex code only to discover that Python has tools available within its library that could have made your job easier? Then this talk is for you!
@driscollis yet another thing in the #python standard library I've never seen or used. I wonder when one would use the functools.singledispatch over a set of if isinstance(..) elif isinstance(..)? The singledispatch feels like a bit of magic since going to the definition of the function does not show what it does and one has to go to Ctrl-F for all the @func.register's to find the implementation 🤔
#Python’s #functools Module: Caching, Dispatching, and Other Higher-Order Operations. Explaining Python’s functools module, including caching, comparison utilities, function dispatching, and more.
Today I learnt about @cached_property in python
As a classically trained physicist, my natural style of programming is functional.
But in production-level code, we usually want a mix of classes and functions.
However, this can get awkward.
THE CHICKEN AND EGG ATTRIBUTE DILEMMA
Oftentimes, we'll calculate some properties for a class and set them as attributes. Maybe it's the mean and standard deviation for our data class in machine learning, for example.
But that'd mean we have to initialise our class, load the data at initialisation and calculate those statistics.
That can be a bit silly in many cases.
Especially when we're building a larger class with some extra utility, this can quickly devolve into creating a monster at __init__.
Read more… [https://dramsch.net/today-i-learned/data-structures-and-algorithms/today-i-learnt-about-cached_property-in-python/] (2 min remaining to read)
#Functools #Python #TodayILearned #MachineLearning
Find more here: https://dramsch.net/today-i-learned/data-structures-and-algorithms/today-i-learnt-about-cached_property-in-python/
📣 New article on my website live!
Today I learnt about @cached_property in python
Check it out here:
https://dramsch.net/today-i-learned/data-structures-and-algorithms/today-i-learnt-about-cached_property-in-python/