Files
2nd/10_Wiki/Topic_Programming/AI_and_ML/Seed.md
T
Antigravity Agent 9148c358d0 docs(10_Wiki): 위키 전체 재구성 — Topic_* 폴더를 4개 카테고리로 통합 + 대규모 중복 제거
Topic_Agent/Topic_Blog/Topics/Topics_Biz/Topics_Meeting/Topics_Rag의 마크다운 지식 문서를
Topic_General/Topic_Programming/Topic_Graphic/Topic_Business 4개 카테고리로 재분류.

- 중복 제거: frontmatter의 status:duplicate/merged + duplicate_of/redirect_to 필드로
  자기 자신을 중복으로 선언한 리다이렉트 stub 1032개 제거, 완전 동일 내용 파일 472개 제거,
  동일 파일명·다른 내용 충돌 시 더 큰(완전한) 버전만 유지(162개 제거) — 총 1639개 중복 제거.
- 분류: 폴더 단위로 명확한 항목(AI_and_ML/Coding/Architecture 등 → Programming,
  Comfyui/Visual_Effects → Graphic, Topics_Biz/Topics_Meeting/사업 등 → Business,
  Poetic_Blog_Writing/창의성/Game_Design 등 → General)은 폴더 우선순위로,
  나머지 혼재 폴더(Topic_Agent/Topic_Blog/Topics 루트/Thinking & Reasoning/Other/UI_UX_Assets)는
  title/tags 키워드 스코어링으로 파일 단위 분류(불명확한 경우 General로 폴백).
  원본 폴더명은 "From_*" 서브폴더로 보존해 추적 가능성 유지.
- 최종 배치: Programming 2784 / General 1608 / Graphic 285 / Business 249 = 4926개 문서.
- 에이전트 운영 상태(.astra/.agent/.obsidian/sessions/memory/_company/docs/lessons/_shared/src)는
  지식 콘텐츠가 아니므로 재분류 대상에서 제외하고 원위치 유지.
- Topics/Topic_email(상위 보호 폴더 Topic_email과 파일명 100% 중복) 삭제 — 보호 폴더 자체는 미변경.
- 완전히 비게 된 Topic_Agent/Topic_Blog/Topics_Biz/Topics_Rag 폴더 제거.
2026-07-05 00:33:48 +09:00

6.9 KiB

id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
id title category status canonical_id aliases duplicate_of source_trust_level confidence_score verification_status tags raw_sources last_reinforced github_commit tech_stack
wiki-2026-0508-seed Seed 10_Wiki/Topics verified self
Random Seed
RNG Seed
Reproducibility Seed
none A 0.9 applied
reproducibility
random
ml-training
image-gen
determinism
2026-05-10 pending
language framework
Python PyTorch

Seed

매 한 줄

"매 seed 는 reproducibility 의 anchor — 매 same seed + same code + same hardware → same result". 매 origin 은 von Neumann 1949 mid-square method, 매 modern state 는 ML training (PyTorch, JAX), image gen (Stable Diffusion, FLUX 의 seed lock), 그리고 매 paper reproducibility 의 standard practice.

매 핵심

매 seed 가 영향 주는 곳

  • Data shuffling: DataLoader sampler order.
  • Weight init: Xavier/He 의 random.
  • Augmentation: random crop/flip/color.
  • Dropout / BatchNorm noise: training 시 stochastic.
  • Image gen: latent noise (z) sampling.
  • MC simulation: Monte Carlo sample order.

매 hardware non-determinism (매 seed 의 한계)

  • CUDA atomics: scatter_add 등 floating-point atomic 의 비결정적 order.
  • cuDNN heuristic: convolution 의 algo 선택.
  • TF32 / mixed precision: FP rounding 차이.
  • Multi-GPU all-reduce: NCCL ring order.
  • → 매 seed 만으로 부족, deterministic=True 필요.

매 응용

  1. ML training reproducibility (paper).
  2. Image gen 의 seed lock (consistent character, A/B test).
  3. Statistical simulation (bootstrap, MC).
  4. Bug reproduction (flake → 매 seed pin).

💻 패턴

매 PyTorch full reproducibility (2026)

import os, random
import numpy as np
import torch

def seed_everything(seed: int = 42):
    os.environ["PYTHONHASHSEED"] = str(seed)
    os.environ["CUBLAS_WORKSPACE_CONFIG"] = ":4096:8"  # 매 cublas 결정적
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed_all(seed)
    # 매 cuDNN 결정적 (매 속도 trade-off)
    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = False
    # 매 PyTorch 2.x deterministic algorithms
    torch.use_deterministic_algorithms(True, warn_only=True)

seed_everything(42)

매 DataLoader seed (매 worker 마다 다른 seed)

def worker_init_fn(worker_id):
    seed = torch.initial_seed() % 2**32
    np.random.seed(seed + worker_id)
    random.seed(seed + worker_id)

g = torch.Generator()
g.manual_seed(42)

loader = torch.utils.data.DataLoader(
    dataset,
    batch_size=32,
    shuffle=True,
    num_workers=4,
    worker_init_fn=worker_init_fn,
    generator=g,
)

매 Stable Diffusion / FLUX 의 seed lock

import torch
from diffusers import FluxPipeline

pipe = FluxPipeline.from_pretrained(
    "black-forest-labs/FLUX.1-dev", torch_dtype=torch.bfloat16
).to("cuda")

prompt = "A cyberpunk samurai at neon market, 4k photo"

# 매 same seed → same image (same hardware)
gen = torch.Generator(device="cuda").manual_seed(20260510)
img = pipe(prompt, generator=gen, num_inference_steps=28).images[0]
img.save("samurai_seed20260510.png")

# 매 seed sweep — 매 character consistency 찾기
for s in range(1000, 1010):
    g = torch.Generator(device="cuda").manual_seed(s)
    pipe(prompt, generator=g).images[0].save(f"sweep_{s}.png")

매 JAX (functional seed, 매 split)

import jax
import jax.numpy as jnp

key = jax.random.PRNGKey(42)
key, subkey1, subkey2 = jax.random.split(key, 3)

x = jax.random.normal(subkey1, (1000, 128))
y = jax.random.normal(subkey2, (1000,))

# 매 매 functional — 매 implicit global state X
# 매 same key chain → exact same numbers

매 numpy 의 새 generator API (post-1.17)

import numpy as np

# 매 legacy (매 global, 매 thread-unsafe)
np.random.seed(42); np.random.randn(3)  # 매 권장 X (in 2026)

# 매 modern: explicit Generator
rng = np.random.default_rng(seed=42)
rng.standard_normal(3)         # array([ 0.30471708, -1.03998411, ...])
rng.choice([1,2,3], size=10)

매 JS (web 의 seedable, Math.random 은 X)

// 매 seedrandom (매 V8 Math.random 은 seedable X)
import seedrandom from "seedrandom";

const rng = seedrandom("2026-05-10");
console.log(rng());        // 매 deterministic
console.log(rng.int32());  // 매 deterministic int

매 reproducibility checklist (매 paper / experiment)

# 매 매 run 시작 시 dump:
import torch, sys, json, hashlib

manifest = {
    "seed": 42,
    "python": sys.version,
    "torch": torch.__version__,
    "cuda": torch.version.cuda,
    "cudnn": torch.backends.cudnn.version(),
    "gpu": torch.cuda.get_device_name(0) if torch.cuda.is_available() else None,
    "code_sha": _git_sha(),
    "data_sha": hashlib.sha256(open("data.bin","rb").read()).hexdigest(),
    "hyperparams": {"lr": 3e-4, "batch": 64, "epochs": 30},
}
with open("run_manifest.json","w") as f:
    json.dump(manifest, f, indent=2)

매 multi-seed eval (매 paper 의 robust 결과)

results = []
for seed in [42, 123, 2024, 31337, 7]:
    seed_everything(seed)
    model = train()
    acc = evaluate(model)
    results.append(acc)

# 매 report mean ± std (NOT single-seed best)
print(f"Acc = {np.mean(results):.3f} ± {np.std(results):.3f} (n=5 seeds)")
# 매 매 single-seed claim 은 매 reviewer 가 reject.

매 결정 기준

상황 Approach
매 paper experiment seed_everything + multi-seed (≥3) + manifest dump
매 image gen consistency seed lock + sweep
매 prod ML training seed + log, 매 deterministic 의 perf cost 고려
매 hyperparam sweep seed pin per run, vary hyperparam
매 MC simulation seed log per run, 매 reproducible

기본값: seed_everything(42) + manifest JSON + 매 paper claim 매 multi-seed mean±std.

🔗 Graph

🤖 LLM 활용

언제: 매 LLM의 seed param (OpenAI 의 seed arg, Anthropic 의 temperature=0 근사) — 매 partial reproducibility. 매 prompt 의 deterministic eval. 언제 X: 매 LLM 은 매 fully reproducible X (provider routing, kernel non-determinism). 매 expectation 조정.

안티패턴

  • Single-seed paper: 매 매 result fragility. 매 N≥3 seed report.
  • Seed pin without manifest: 매 hardware/lib 변경 시 깨짐.
  • Forget DataLoader workers: 매 worker 의 random 따로 — 매 worker_init_fn 필요.
  • np.random.seed global: 매 thread-unsafe — 매 default_rng 사용.
  • Determinism off-by-default: 매 cuDNN benchmark=True 면 매 결과 다름.

🧪 검증 / 중복

  • Verified (PyTorch reproducibility docs 2026, JAX PRNG design notes, Pineau "ML Reproducibility Checklist" NeurIPS).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — PyTorch + JAX + FLUX seed + multi-seed eval