COSCUP
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invitee
    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Sharing URL Help
Menu
Options
Versions and GitHub Sync Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
Invitee
Publish Note

Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

Your note will be visible on your profile and discoverable by anyone.
Your note is now live.
This note is visible on your profile and discoverable online.
Everyone on the web can find and read all notes of this public team.
See published notes
Unpublish note
Please check the box to agree to the Community Guidelines.
View profile
Engagement control
Commenting
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
  • Everyone
Suggest edit
Permission
Disabled Forbidden Owners Signed-in users Everyone
Enable
Permission
  • Forbidden
  • Owners
  • Signed-in users
Emoji Reply
Enable
Import from Dropbox Google Drive Gist Clipboard
   owned this note    owned this note      
Published Linked with GitHub
Subscribed
  • Any changes
    Be notified of any changes
  • Mention me
    Be notified of mention me
  • Unsubscribe
Subscribe
在21世紀做自動微分?你需要Zygote.jl! - 鄭景文 === {%hackmd LcL4-VI0SGitSiINTuy4rA %} > 請從這裡開始 [slides/投影片](https://slides.com/peter-cheng/zygotejl#/) ## Automatic Differentiation (AD) 自動微分 ## How AD work - Wengert List (Tape / Graph) - Derivative Definition - Chain Rules Steps: 1. Get the Wengert List of the given expression 2. Transform each instruction in the Wengert List 3. Apply Chain rule ### Wengert List - A list of expression / instruction - Transform the expression with derivative definition - EX: $f(x) = 5\sin(\log(x))$ - Wengert List of $f$ - $y1 = \log (x)$ - $y2 = sin(y1)$ - $y3=5 \times y2$ - EX : $\frac{d}{dx}f(x)=\frac{5\cos(\log(x))}{x}$ ## Different types of AD - Foward mode - Reverse mode - Mix mode... ### Forward mode - dual number - 數學對應:類似複數,平方為 0 ```julia struct Dual{T<:Real} <: Real x::T ϵ::T ``` - chain rule multification start from the input $dy1/dx \times dy2/dy1$ - computational efficiency on multivariable differentiation with more output than input - 多 Output 時效率高 ### Reverse mode 現代深度學習較常見: back propogation做兩件事情 - reverse mode - 更新參數 從最接近輸出的地方開始 對於output跟變數數量差很多的,reverse mode會比較有效率。例如,通常back propogation只有一個output (loss function),但有很多變數(parameters) - Tracker - Record every operation on variables to Wengert List - Derive the Wengert List w.r.t. given variable - - Chain rule multiplication start from the output $dy/dy2 \times dy2/dy1$ - computational efficiency on mulivariable differentiation with more input than output - DL situation ## Where is the Wengert List in Forward mode? ### Wengert underneath Dual Number ```julia julia> @code_warntype f(3.) Body::Float64 1 ─ %1 = invoke Main.log(_2::Float64)::Float64 │ %2 = invoke Main.sin(%1::Float64)::Float64 │ %3 = (Base.mul_float)(5.0, %2)::Float64 └── return %3 julia> @code_warntype D(f, 3) Body::Float64 1 ─ %1 = (Base.sitofp)(Float64, x)::Float64 # sitofp : 型態轉換 │ %2 = invoke Base.Math.log(%1::Float64)::Float64 │ %3 = (Base.sitofp)(Float64, 1)::Float64 │ %4 = (Base.sitofp)(Float64, x)::Float64 │ %5 = (Base.div_float)(%3, %4)::Float64 │ %6 = invoke Main.sin(%2::Float64)::Float64 │ %7 = invoke Main.cos(%2::Float64)::Float64 │ %8 = (Base.mul_float)(%5, %7)::Float64 │ %9 = (Base.mul_float)(%6, 0.0)::Float64 │ %10 = (Base.mul_float)(5.0, %8)::Float64 │ %11 = (Base.add_float)(%9, %10)::Float64 └── return %11 ``` ## Why Julia - Fast - really good compiler design ## Zygote.jl - Source to source AD - support control flow, recursion, closures, structs, dictionaries, ... 安裝:`import Pkg ; Pkg.add("Zygote")` ## Source to Source AD 直接把某程式碼轉成另個程式碼 ## Differentiate SSA Form ### Julia Compile Process ![](http://blog.rogerluo.me/images/julia-compile-diagram.png) ## SSA From - Static Single Assignment Form - All the variable will only be assigned once - Most variable comes from function calls - All the control flows become branches https://arxiv.org/pdf/1810.07951.pdf ## Not just Unroll control flow ```julia function pow(x, n) r = 1 while n > 0 n -= 1 r *= x end return r end ``` ```julia function grad_pow(x, n) r = 1 Bs = Tuple{Int, Int}[] while n > 0 push!(Bs, (r, x)) r *= x n -= 1 end dx = 0 dr = 1 for i = length(Bs):-1:1 (r, x) = Bs[i] dx += dr*r dr = dr*x end return dx end ``` 減少呼叫次數 ## Zygote - Compile every Julia function into differentiable - Easy to add gradient hook - Differentiable Programming!! ## Differentiable Programming ![](https://fluxml.ai/assets/2019-03-05-dp-vs-rl/trebuchet-flow.png) ## Zygote + Pytorch ![](https://s3.amazonaws.com/media-p.slid.es/uploads/762879/images/6450610/2019-08-17_07-02-37_%E7%9A%84%E8%9E%A2%E5%B9%95%E6%93%B7%E5%9C%96.png) ## Zygote + XLA.jl XLA : Google TPU 格式 不須以 TensorFlow 改寫,即可在 Google TPU 上運作。 https://arxiv.org/pdf/1810.09868.pdf ###### tags: `COSCUP2019` `Julia language` `IB501`

Import from clipboard

Paste your markdown or webpage here...

Advanced permission required

Your current role can only read. Ask the system administrator to acquire write and comment permission.

This team is disabled

Sorry, this team is disabled. You can't edit this note.

This note is locked

Sorry, only owner can edit this note.

Reach the limit

Sorry, you've reached the max length this note can be.
Please reduce the content or divide it to more notes, thank you!

Import from Gist

Import from Snippet

or

Export to Snippet

Are you sure?

Do you really want to delete this note?
All users will lose their connection.

Create a note from template

Create a note from template

Oops...
This template has been removed or transferred.
Upgrade
All
  • All
  • Team
No template.

Create a template

Upgrade

Delete template

Do you really want to delete this template?
Turn this template into a regular note and keep its content, versions, and comments.

This page need refresh

You have an incompatible client version.
Refresh to update.
New version available!
See releases notes here
Refresh to enjoy new features.
Your user state has changed.
Refresh to load new user state.

Sign in

Forgot password

or

By clicking below, you agree to our terms of service.

Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
Wallet ( )
Connect another wallet

New to HackMD? Sign up

Help

  • English
  • 中文
  • Français
  • Deutsch
  • 日本語
  • Español
  • Català
  • Ελληνικά
  • Português
  • italiano
  • Türkçe
  • Русский
  • Nederlands
  • hrvatski jezik
  • język polski
  • Українська
  • हिन्दी
  • svenska
  • Esperanto
  • dansk

Documents

Help & Tutorial

How to use Book mode

Slide Example

API Docs

Edit in VSCode

Install browser extension

Contacts

Feedback

Discord

Send us email

Resources

Releases

Pricing

Blog

Policy

Terms

Privacy

Cheatsheet

Syntax Example Reference
# Header Header 基本排版
- Unordered List
  • Unordered List
1. Ordered List
  1. Ordered List
- [ ] Todo List
  • Todo List
> Blockquote
Blockquote
**Bold font** Bold font
*Italics font* Italics font
~~Strikethrough~~ Strikethrough
19^th^ 19th
H~2~O H2O
++Inserted text++ Inserted text
==Marked text== Marked text
[link text](https:// "title") Link
![image alt](https:// "title") Image
`Code` Code 在筆記中貼入程式碼
```javascript
var i = 0;
```
var i = 0;
:smile: :smile: Emoji list
{%youtube youtube_id %} Externals
$L^aT_eX$ LaTeX
:::info
This is a alert area.
:::

This is a alert area.

Versions and GitHub Sync
Get Full History Access

  • Edit version name
  • Delete

revision author avatar     named on  

More Less

Note content is identical to the latest version.
Compare
    Choose a version
    No search result
    Version not found
Sign in to link this note to GitHub
Learn more
This note is not linked with GitHub
 

Feedback

Submission failed, please try again

Thanks for your support.

On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

Please give us some advice and help us improve HackMD.

 

Thanks for your feedback

Remove version name

Do you want to remove this version name and description?

Transfer ownership

Transfer to
    Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

      Link with GitHub

      Please authorize HackMD on GitHub
      • Please sign in to GitHub and install the HackMD app on your GitHub repo.
      • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
      Learn more  Sign in to GitHub

      Push the note to GitHub Push to GitHub Pull a file from GitHub

        Authorize again
       

      Choose which file to push to

      Select repo
      Refresh Authorize more repos
      Select branch
      Select file
      Select branch
      Choose version(s) to push
      • Save a new version and push
      • Choose from existing versions
      Include title and tags
      Available push count

      Pull from GitHub

       
      File from GitHub
      File from HackMD

      GitHub Link Settings

      File linked

      Linked by
      File path
      Last synced branch
      Available push count

      Danger Zone

      Unlink
      You will no longer receive notification when GitHub file changes after unlink.

      Syncing

      Push failed

      Push successfully