RFC: lingvo.jax exception flag mechanism
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 25/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
Start by reading lingvo/jax/train.py around train_and_evaluate_pmap and compare the proposed SafePmap flow with the model code described in the issue. The issue says the mechanism should live in layers and mentions pjit.pjit in trainer_lib.py as another path to investigate. Done means errors can be flagged during compiled computation and reported after the step, with the behavior integrated across the relevant training paths.
索引モデルが issue の本文から書いたものです。
説明
So, it's nice to be able to have runtime asserts, but we can't have them in a pure function.
In X86, when the processor encounters an error, it raises the floating point exception flag and goes on. You can check that flag at the end of the computation.
I prototyped a similar mechanism in my code. An error flag is raised during the computation. At the end of the computation, we check whether the error flag has been raised.
Unlike asserts, this method:
- Can be enabled in prod on the same graph. You could place the checks on a device of your choosing.
- Does not know which error came first. If there is a cascade of errors, you will not know. I don't think you can know unless you annotate the graph, or provide a jax op to timestamp the execution.
- Does not interrupt errors which cause infinite loops.
The second issue is the annoying one. My assumption is that you errors should generally happen in the order in which they are constructed.
I've implemented it in my model.py but it should go in layers.
model.py:
import traceback
def Check(ok_cond: JTensor, errflag: JTensor, errinfo: List[Any]) -> JTensor:
AssertShape(ok_cond, [])
errinfo.append(traceback.extract_stack())
err = jnp.logical_not(ok_cond)
return jnp.concatenate([errflag, err[jnp.newaxis]])
class Model(base_model.BaseModel):
def __init__(...):
self.errinfo = []
self.errflag = jnp.zeros(shape=[0], dtype=bool)
def compute_loss(...):
invariant = jnp.prod((z > 0).astype(int)) == 0
self.errflag = Check(invariant, self.errflag, self.errinfo)
Then, in lingvo/jax/train.py:
def SafePmap(errsrc, step, **pmap_kwargs):
# errsrc = jax_task.model which contains errflags and errinfo
import numpy as np
def StepWithErrflag(*args, **kwargs):
# The step will construct errflag and errinfo.
# This is pure and can be compiled.
ret = list(step(*args, **kwargs))
ret += [errsrc.errflag]
return ret
def RunCheckCompileStep(*arg, **kwargs):
ret = compiled_step(*arg, **kwargs)
# This runs in python land and we can access python objects.
errinfo = errsrc.errinfo
errflag = ret[-1][0]
if np.sum(errflag):
logging.info('==== ERRORS found: %s', np.sum(errflag))
for k, flag in enumerate(errflag):
if flag:
logging.info('== ERR[%d] at %s', k, '\n'.join(errinfo[k].format()))
raise ValueError('Exception flag raised')
return ret[:-1]
compiled_step = jax.pmap(StepWithErrflag, **pmap_kwargs)
return RunCheckCompileStep
...
def train_and_evaluate_pmap(...):
...
p_train_step = SafePmap(jax_task.model, train_step, donate_argnums=(0,), axis_name='batch')
There is the pjit.pjit in trainer_lib.py as well but it's not called in my path.
- 主要言語
- Python
- スター
- 2.9k
- フォーク
- 452
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
tensorflow/lingvo のほかの issue
-
About inverseAugオープン
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
tensorflow/lingvo#370 · コメント 1 件 ·
-
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
tensorflow/lingvo#359 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 15/100
tensorflow/lingvo#356 · リアクション 5 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
tensorflow/lingvo#332 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
tensorflow/lingvo#331 ·
tensorflow/lingvo の issue をすべて見る
似ている issue
-
enhancement good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
-
Community
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
kedro-org/kedro-plugins#1575 ·
メンテナーはふだん 1 日以内に返信
-
hive size:simple
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
Significant-Gravitas/AutoGPT#16733 ·
メンテナーはふだん 1 日以内に返信
-
changelog investigate
難易度 1/5 1時間未満 初心者へのやさしさ 74/100
ramnes/notion-sdk-py#444 ·