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

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

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

Just links

From Pixels to Components: Eigenvector Masking for Visual Representation Learning https://arxiv.org/abs/2502.06314

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

Just links

Competitive Programming with Large Reasoning Models https://arxiv.org/abs/2502.06807

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

Just links

It's All in The [MASK]: Simple Instruction-Tuning Enables BERT-like Masked Language Models As Generative Classifiers https://arxiv.org/abs/2502.03793

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

Just links

MathArena: Evaluating LLMs on Uncontaminated Math Competitions https://matharena.ai/

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

Just links

Gold-medalist Performance in Solving Olympiad Geometry with AlphaGeometry2 https://arxiv.org/abs/2502.03544
via @seeallochnaya

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

Just links

Empowering deep neural quantum states through efficient optimization https://www.nature.com/articles/s41567-024-02566-1

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

Just links

Improving Vision-Language-Action Model with Online Reinforcement Learning https://arxiv.org/abs/2501.16664

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

Just links

Constraints on the location of the liquid–liquid critical point in water https://www.nature.com/articles/s41567-024-02761-0

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

Just links

LLMs can see and hear without any training https://arxiv.org/abs/2501.18096

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

Just links

ReferDINO: Referring Video Object Segmentation with Visual Grounding Foundations https://arxiv.org/abs/2501.14607

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

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

Gemstones: A Model Suite for Multi-Faceted Scaling Laws https://arxiv.org/abs/2502.06857

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

Just links

https://arxiv.org/abs/2502.07374

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

Just links

MATH-Perturb: Benchmarking LLMs' Math Reasoning Abilities against Hard Perturbations https://arxiv.org/abs/2502.06453

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

Just links

Chiral Instabilities in Driven-Dissipative Quantum Liquids https://arxiv.org/abs/2502.04443

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

Just links

Amortized Planning with Large-Scale Transformers: A Case Study on Chess https://openreview.net/forum?id=XlpipUGygX

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

Just links

Leveraging Online Olympiad-Level Math Problems for LLMS Training and Contamination-Resistant Evaluation https://livemathbench.github.io/

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

Just links

Mathematical Foundations of Quantum Mechanics: An Advanced Short Course https://arxiv.org/abs/1508.06951

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

Just links

Improving Transformer World Models for Data-Efficient RL https://arxiv.org/abs/2502.01591

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

Just links

Goedel-Prover A New Frontier in Automated Theorem Proving https://goedel-lm.github.io/

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

Just links

Physical Review Letters collection of the year 2024 https://promo.aps.org/PRL2024

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

Just links

Improving Your Model Ranking on Chatbot Arena by Vote Rigging https://arxiv.org/abs/2501.17858

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