fit_to_data compiles about 26 XLA programs for every new window size

Aperta
#366 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
49/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

The issue points to fit_to_data, fit_flow, and the step calls in the training loop, but names no source file or test. Start by locating those entry points and tracing how changing window and batch shapes trigger compilation; use the supplied reproduction to measure compilations across window sizes. Done means reducing repeated XLA compilations while preserving the training behavior.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

normalizing-flows

fit_to_data, the flow's training loop, compiles about 26 XLA programs each time the adapter hands it a window of a new size. Window sizes change until the window reaches its maximum length. The shuffle, the train/validation split, the batching and count_fruitless run as eager JAX ops on arrays whose shapes change, and every batch is a separate jitted step call.

import logging

import jax
import numpy as np
from nutpie.transform_adapter import FisherLoss, fit_flow, make_transform_adapter

compiles = []


class CountCompiles(logging.Handler):
    def emit(self, record):
        if "Finished XLA compilation" in record.getMessage():
            compiles.append(record.getMessage())


jax.config.update("jax_log_compiles", True)
logging.getLogger("jax").addHandler(CountCompiles())
logging.getLogger("jax").setLevel(logging.WARNING)

rng = np.random.default_rng(0)
draws = rng.normal(size=(600, 20))
make_flow_fn = make_transform_adapter(num_layers=4).keywords["make_flow_fn"]
flow = make_flow_fn(0, draws, -draws, n_layers=4)

for n_draws in [137, 265, 393, 521, 600, 600]:  # the window sizes nutpie's adapter trains on
    before = len(compiles)
    fit_flow(jax.random.PRNGKey(0), flow, FisherLoss(), draws[:n_draws], -draws[:n_draws], np.zeros(n_draws),
             max_epochs=30, max_patience=30, batch_size=128, show_progress=False)
    print(f"n_draws={n_draws}: {len(compiles) - before} XLA compilations")
# n_draws=137: 47, 265: 26, 393: 27, 521: 26, 600: 26, 600: 2
Lingua principale
Python
Stelle
214
Fork
30
Merge medio
3h 50m
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pymc-devs/nutpie

Tutte le issue di pymc-devs/nutpie

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.