j_links | Unsorted

Telegram-канал j_links - Just links

6269

That's just link aggregator of everything I consider interesting, especially DL and topological condensed matter physics. @EvgeniyZh

Subscribe to a channel

Just links

Warning Signs of a Possible Collapse of Contemporary Mathematics https://web.math.princeton.edu/~nelson/papers/warn.pdf

Читать полностью…

Just links

Proving Olympiad Inequalities by Synergizing LLMs and Symbolic Reasoning https://arxiv.org/abs/2502.13834

Читать полностью…

Just links

https://fixupx.com/deepseek_ai/status/1895279409185390655

Читать полностью…

Just links

Comment on "InAs-Al hybrid devices passing the topological gap protocol", Microsoft Quantum, Phys. Rev. B 107, 245423 (2023) https://arxiv.org/abs/2502.19560

Читать полностью…

Just links

Welcome to Ladybird, a truly independent web browser (🔥 Score: 150+ in 1 hour)

Link: https://readhacker.news/s/6pZHn
Comments: https://readhacker.news/c/6pZHn

Читать полностью…

Just links

Hardware-efficient quantum error correction via concatenated bosonic qubits https://www.nature.com/articles/s41586-025-08642-7

Читать полностью…

Just links

Universal Quantum Computation with the S3 Quantum Double: A Pedagogical Exposition https://arxiv.org/abs/2502.14974

Читать полностью…

Just links

Muon is Scalable for LLM Training https://github.com/MoonshotAI/Moonlight

Читать полностью…

Just links

BaxBench: Can LLMs Generate Secure and Correct Backends? https://baxbench.com/

Читать полностью…

Just links

mathconstruct: Challenging LLM Reasoning with Constructive Proofs https://arxiv.org/abs/2502.10197

Читать полностью…

Just links

Interferometric single-shot parity measurement in InAs–Al hybrid devices https://www.nature.com/articles/s41586-024-08445-2

Читать полностью…

Just links

Roadmap to fault tolerant quantum computation using topological qubit arrays https://arxiv.org/abs/2502.12252

Читать полностью…

Just links

Theory of correlated insulators and superconductor at ν = 1 in twisted WSe2 https://www.nature.com/articles/s41467-025-56816-8

Читать полностью…

Just links

Что такое GIL в Python?

Кажется, один из золотых вопросов для всех питонистов на собеседованиях.
Обычно, на встречный вопрос "а что конкретно в питоне является GIL?" не может ответить ни один спрашивающий.

Сегодня мы закроем данный пробел в знаниях питонистов.

Global Interpreter Lock не позволяет работать более чем одному треду работать с Python API за раз. Его можно отключить через --disable-gil в 3.13+, но сегодня мы про такое не будем.

Обратите внимание на ключевую фразу "c Python API". С системными треды могут и должны работать в режиме настоящей параллельности, без GIL. Что и позволяет получить ускорение при использовании threading, когда C код поддерживает такой способ.

Знакомьтесь – вот структура GIL _gil_runtime_state и поведение в ceval_gil.c.

Как можно отпустить GIL?

На уровне C есть макросы: Py_BEGIN_ALLOW_THREADS и Py_END_ALLOW_THREADS, которые отпускают GIL в нужных местах. Пример из модуля mmap:


Py_BEGIN_ALLOW_THREADS
m_obj->data = mmap(NULL, map_size, prot, flags, fd, offset);
Py_END_ALLOW_THREADS


Или time.sleep, который тоже дает работать другим тредам, пока ждет.

Что происходит, когда мы используем данный макрос? Они разворачиваются в:


{
PyThreadState *_save;
_save = PyEval_SaveThread();
// your code here
PyEval_RestoreThread(_save);
}


PyThreadState является текущим состоянием треда в CPython. Внутри хранится много контекста. Нас особо сильно интересует часть с полями про GIL:


struct PyThreadState {
struct {
unsigned int initialized:1;
/* Has been bound to an OS thread. */
unsigned int bound:1;
/* Has been unbound from its OS thread. */
unsigned int unbound:1;
/* Has been bound aa current for the GILState API. */
unsigned int bound_gilstate:1;
/* Currently in use (maybe holds the GIL). */
unsigned int active:1;
/* Currently holds the GIL. */
unsigned int holds_gil:1;
} _status;

// Thread state (_Py_THREAD_ATTACHED, _Py_THREAD_DETACHED, _Py_THREAD_SUSPENDED).
int state;

// ...
}


Когда вызывается PyEval_SaveThread и GIL отпускается, то на самом деле мы просто помечаем текущий PyThreadState как:


tstate->_status.active = 0;
tstate->_status.unbound = 1;
tstate->_status.holds_gil = 0;
tstate->state = detached_state;


И вызываем _PyEval_ReleaseLock, который уже правильно изменит _gil_runtime_state.
Как итог – текущий стейт теряет возможность вызывать какие-либо Python АПИ. Даже, например Py_DECREF, и в тредах есть свой refcount, который работает локально, чтобы можно было его вызывать без GIL.

Как треды берут GIL?

Смотрим на thread_run из _threadmodule.c.


_PyThreadState_Bind(tstate);
PyEval_AcquireThread(tstate);
_Py_atomic_add_ssize(&tstate->interp->threads.count, 1);


Там используется PyEval_AcquireThread, который берет GIL в конкретном треде для работы с Python API.
И дальше – отпускаем.

В следующих сериях поговорим про переключение тредов, ParkingLot API, Mutex'ы и прочее.
Обсуждение: сталкивались ли вы на собесах с вопросами про GIL? Стало ли теперь понятнее?

| Поддержать | sobolevn">YouTube | GitHub | Чат |

Читать полностью…

Just links

https://youtu.be/7gQ9DnSYsXg

Читать полностью…

Just links

Anomalies of Coset Non-Invertible Symmetries https://arxiv.org/abs/2503.00105

Читать полностью…

Just links

Zagier, D. (1990). How Often Should You Beat Your Kids? Mathematics Magazine63(2), 89–92. https://doi.org/10.1080/0025570X.1990.11977493

<...>
We, however, maintain that only the most degenerate parent would play against a two-year-old for money, and that our concern must therefore be, not by how much you can expect to win, but with what probability you will win at all. Our principal result is that this probability tends asymptotically to 85.4% (more precisely: to 1/2 + 1/sqrt(8)) as n tends to infinity. This shows with what unerring instinct Levasseur's mother selected the game — the high 85% loss rate will instill in the young progeny a due respect for the immense superiority of their parents, while the 15% win rate will maintain their interest and prevent them from succumbing to feelings of hopelessness and frustration.
<...>

Читать полностью…

Just links

't Hooft anomalies in metals https://arxiv.org/abs/2502.19471

Читать полностью…

Just links

The three-dimensional Kakeya conjecture, after Wang and Zahl
https://terrytao.wordpress.com/2025/02/25/the-three-dimensional-kakeya-conjecture-after-wang-and-zahl
via @cme_channel

Читать полностью…

Just links

LLM Processes: Numerical Predictive Distributions Conditioned on Natural Language https://arxiv.org/abs/2405.12856

Читать полностью…

Just links

Detecting emergent 1-form symmetries with quantum error correction https://arxiv.org/abs/2502.17572

Читать полностью…

Just links

LIMO: Less is More for Reasoning https://arxiv.org/abs/2502.03387

Читать полностью…

Just links

STP: Self-play LLM Theorem Provers with Iterative Conjecturing and Proving https://arxiv.org/abs/2502.00212

Читать полностью…

Just links

Topology from Nothing https://arxiv.org/abs/2502.12121

Читать полностью…

Just links

https://fixupx.com/IanCutress/status/1892246045385515266

Читать полностью…

Just links

Scaling Test-Time Compute Without Verification or RL is Suboptimal https://arxiv.org/abs/2502.12118

Читать полностью…

Just links

Extracting the topological spins from bulk multipartite entanglement https://arxiv.org/abs/2502.12259

Читать полностью…

Just links

Functional recovery of adult brain tissue arrested in time during cryopreservation by vitrification https://www.biorxiv.org/content/10.1101/2025.01.22.634384

Читать полностью…

Just links

Diverse Inference and Verification for Advanced Reasoning https://arxiv.org/abs/2502.09955

Читать полностью…

Just links

Training Language Models for Social Deduction with Multi-Agent Reinforcement Learning https://arxiv.org/abs/2502.06060

Читать полностью…
Subscribe to a channel