C.W.K.
Stream
Lesson 06 of 08 · published

keras.ops — universal layer

~10 min · backend

Level 0Keras 도제
0 XP0/97 lessons0/20 achievements
0/120 XP to next level120 XP to go0% complete

namespace 하나, engine 전부

keras.ops 는 Keras 3 multi-backend 아키텍처의 뼈대 — 그리고 custom math 짤 때 실제로 만지는 부분이야. NumPy API 전체 에 NumPy 엔 없는 신경망 primitive (convolution·activation·crossentropy) 까지 구현하고, 매 호출을 로드된 backend 로 dispatch 해. NumPy 의 이름·시그니처를 일부러 그대로 베낀 게 핵심 설계라, NumPy 알면 이 surface 의 대부분을 이미 아는 셈.

자주 꺼낼 네 namespace

  • keras.ops (NumPy) — matmul·sum·mean·reshape·concatenate·einsum·arange·clip
  • keras.ops.nnsoftmax·sigmoid·relu·conv·depthwise_conv·binary_crossentropy
  • keras.ops.imageresize·crop_images·pad_images·rgb_to_grayscale
  • keras.randomnormal·uniform·dropout (SeedGenerator 와 함께)

지금 새겨둘 gotcha 하나: 난수는 keras.random 에 살고 backend 의 global RNG 가 아니라 SeedGenerator 로 굴리게 돼 있어. 그게 세 engine 전부에서 결과 재현성을 지키고 *동시에* JAX-pure 를 유지하는 비결이야.

TF 코드 op 단위로 포팅

기존 TensorFlow custom layer 옮길 땐 대부분 거의 기계적 rename — 같은 연산, NumPy 식 이름: tf.reduce_sumkeras.ops.sum, tf.concatkeras.ops.concatenate, tf.rangekeras.ops.arange, tf.reduce_meankeras.ops.mean, tf.gatherkeras.ops.take, tf.clip_by_valuekeras.ops.clip.

이 rename 한 번이면 layer 가 TF 전용을 벗어나 PyTorch·JAX 에서도 수정 없이 돌아 — 다음 lesson 이 기대는 원리야.

External links

Exercise

call() 이 keras.ops.softmax + keras.ops.matmul 만 쓰는 custom Layer subclass 짜. 세 backend 다 코드 변경 없이 돌리고, 출력이 numerical tolerance 안에서 일치하는지 확인.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.