fastai
      • 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
    • Invite by email
      Invitee

      This note has no invitees

    • 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
    • Note Insights New
    • Engagement control
    • Make a copy
    • 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 Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy 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
  • Invite by email
    Invitee

    This note has no invitees

  • 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    **---** type: article title: fastai - Architecture date: 2021-03-10T17:15:00+01:00 draft: false # set to false if your team gives consent to publish this post publicly **---** {{<image file="fastai_logo.png">}} Deep Learning libraries like PyTorch, Keras and Tensorflow help us in creating Deep Learning solutions. However, none of them cater to its users as **fastai**. fastai is made with **ease of use** in mind. This is achieved by incorporating parts of other libraries and then adding (abstraction) layers on top of that, such that the user can start quickly, without having to write elaborate code and familiarize itself with too many deep learning details. In this post we present an architectural overview, where we look at how stakeholders interact with the system at Architectural style. Afterwards we look at the environment of the system in the section Containers view. Next, we take a look at the structural components of the system its connections between these components in the Components view and Connectors view. Then the decomposition of the system of the found modules and its dependencies in the Development view. Moreover we look at the interactions of components at run time in run time view. Lastly we look at the trade-offs for chosen implementation and how the API design principles are applied. # Architectural style Fastai at its core tries to be user-friendly, where its user can pick and choose components and extend where necessary. Thus a three layered, modular architecture was chosen as is shown in the image `Systemcontext`. {{<image file="Systemcontext_simple.png" caption="Systemcontext">}} The **high-level AP**I is catered to beginners and professionals that want to apply and/or repurpose pre-defined deep learning architecture and models. This API level uses, where possible, default values, which allows the user not to worry about many implementation details. The **mid-level API** contains the core deep learning and data-processing methods and models for the five chosen applications. The main purpose of this level is to add abstractions for common low-level API use-cases. The **low-level API** is basically connecting together many data science and machine learning packages such as Numpy, Pandas, Spacy, Scikit, Scipy and Torch. This architecture allows a completely different level of use to different types of users. "A user can **create and train a state-of-the-art vision model** using transfer learning with four understandable lines of code."[^6]. Moreover, users can **quickly set up a baseline** or **extend the library** using their own custom implementation. # Container view The main execution environment is mixed as shown in the image `Container view`. All the code is written in Jupyter Notebooks and converted by **nbdev** (an open-source library made by fast.ai) into a Python package. When executing such a Notebook, the Python package is imported such that we can make use of the whole library. {{<image file="Systemcontext_detailed.png" caption="Container view">}} # Component view Fastai tries to apply industry standards and common best practices. Therefore individual components adhere to standards like naming conventions. Thus a user that comes from a different library will be able to quickly get used to the fastai library, furthermore huffman encoding principles are applied in order to keep short and recognizable variable names, such as lm for language model and tfm for transform [^2]. As mentioned in the previous section, fastai makes use of nbdev. **Nbdev is able to convert Jupyter notebooks into raw Python code, furthermore it is able to stitch multiple notebooks together thereby making a package of python files that can be deployed as a library**. Fastai is thus a composition of different Jupyter notebooks building upon each other, which allows for exploratory programming, while not loosing the benefits of the Python language. Exploratory programming is a programming style where a user can delve into the code just like a scientist's journal and observe all the experiments that a developer has tried [^1]. Every notebook contains rich documentation accompanied which simple tests and examples in order to illustrate how to use a each module of the library. {{<image file="Reimaged_fastai.png" caption="Component view">}} In every application dependencies between components can be found, we have depicted the most important ones in the image `Component view`. One of the more interesting dependencies is the dependency between the data component and all other model components such as vision, text and tabular. This dependency has an effect on ***how each models data is processed and is defined in the data component*** as such this components needs to have a well defined API such that it can be used by a variety of models. # Connectors view The library makes use of Python files, Jupyter notebooks and incorporates other material found online. In the image `Connectors view` we can observe the main types of connections used by this project. {{<image file="Connectors_view.png" caption="Connectors view">}} Firstly, we have the **Nbdev** connector, that converts the Jupyter notebooks to Python files with documentation. Next, as second connector, fastai makes use of readily available datasets and models, which are retrieved through **external file transfer**. Additionally, fastai **imports other packages** on which fastai depends on. This is the third connector. It works by making a local calls when the package is already locally installed. Otherwise, it is a remote file transfer call, whereby we make use of Pip. Local files, variables and environment variables can also be identified what the fourth type of connector helps with, namely **local file transfer**. Examples of environment variables are when the user has a NVidia GPU or AMD one, is on Windows or MacOS. This can make a difference and thus is reflected in the code. # Development view The modular construction of the application allows scalability and rapid prototyping for users and developers. However, it is not always easy to understand dependencies and how they relate to each other. {{<image file="fastai_main_structure_w_external.png" caption="Development view">}} In the image `Development view` the following structure is applied: - **Folders** are **external packages** which are imported - **light-blue color** it means the external package is a **math or machine learning package**, - **dark-blue** is a **utility package**, - **Oval shapes** indicate **internal packages**, **lighter color** means **lower API layer**. As mentioned in *Architectural style*, there are four layers, the darkest color layer are its use-cases, second-darkest is the layer that is required to be used, whereas the last two lightest color oval shapes are more optional. ## Runtime view In this section we will look at the library from a process point of view. We use the Philippe Kruchten's Process View perspective[^7]. This view looks at the dynamic aspects of the system. Thus we will show a runtime view, followed with a summary of the hardware interactions. {{<image file="runtime_diagram.png" caption="Runtime view">}} We provide an example runtime overview through showing the runtime schema of one of the example of the fastai library. In the image `Runtime view` we show the runtime diagram of the first example of the vision library[^3]. The diagram allows us to clearly see the interactions between the different components of the library, such as the data component and the model component. In the learner component the model is optimized according to the error criteria that the model was given by the user based on the specified data. In order to actually deploy a trained model, fastai supplies a native way to interact with the file system. Similarly to other artificial intelligence libraries fastai offers a simple way to create checkpoints from where the training process of a model can be restarted. This training can be done on both the GPU and the CPU, of which the GPU is the preferred manner as it allows for faster computations. # Key quality attribute trade-offs Flexibility and modularity are the key quality attributes of fastai. Since Python is a dynamically, strong typed language, the packages that it uses are also affected by these design decisions. As such PyTorch and other math related packages that are integrated by fastai are easily used to interact within the different layers of the architecture without the necessity of changing complex structures [^6]. This setup provides a simple composition of functions that allows the users to pick and choose different objects in any sequence to develop different sorts of complex models. But there is a trade-off, and in this case, the **simplicity** that fastai provides **can lead to a decreased performance** of the implemented machine learning model. This is because out of the box, best practices and abstractions have been incorporated. This means inherent design choices are abstracted away in the library. Beginners and even advanced users will have a difficult time uncovering all these default design choices that are implemented by the library. It would be helpful if this was (exhaustively) documented. However, this has been done insufficiently. So, using this library for the average use-case should most of the time lead to sufficient performance, however, specialized use-cases will have to consider if they want all these default choices and thus extend fastai or if they want to implement it without fastai. # API design principles As the authors mention, the design principles are accessibility and ease of use for high productivity, while also being "deeply hackable" and configurable [^6]. This goal inspired them to build the layered architecture mentioned above. Each of the implemented levels has different applications and varying levels of complexity to meet the needs of a variety of users (from beginner to advanced) this way they target the **approachability** of the API. When referring to the **flexibility** of the API, fastai tries to offer a friendly high level layer that works as an interface for different kind of users who may have similar needs when implementing the most popular machine learning models available but who also have different approaches on the subject. The **documentation** of the API, can be seen as a small flaw of the library, given that not everything is extensively documented as expected (like the design implementation choices). Nevertheless, they offer many tutorials and courses that aims to **help** new users to begin working with their library. But, as a results caters less to advanced users. [^1]: Nbdev: Use Jupyter Notebooks for Everything · Fast.Ai. https://www.fast.ai/2019/12/02/nbdev/. Accessed 10 Mar. 2021. [^2]: Fastai Abbreviation Guide | Fastai. https://docs.fast.ai/dev/abbr.html. Accessed 10 Mar. 2021. [^3]: ‘Fastai/Fastai’. GitHub, https://github.com/fastai/fastai. Accessed 10 Mar. 2021. [^6]: Howard, Jeremy & Sylvain Gugger. "fastai: A Layered API for Deep Learning". Information, vol. 11, no. 2, Feb. 2020, p. 108. arXiv.org, doi:10.3390/info11020108. [^7]: Kruchten, Philippe. "Architectural Blueprints–The 4+ 1 View Model of Software Architecture, Software, Vol. 12, Number 6." (1995). \end{markdown} \end{document}

    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