Andrej Karpathy has put together a GPT-2 implementation in just 1,000 lines of code in a single file.
Saturday, March 9, 2024Andrej Karpathy has put together a GPT-2 implementation in just 1,000 lines of code in a single file.
Andrej Karpathy has put together a GPT-2 implementation in just 1,000 lines of code in a single file.
Andrej Karpathy has put together a GPT-2 implementation in just 1,000 lines of code in a single file.
Under the hood, async/await is built on promises, where the async function returns a promise that represents the eventual result. The event loop handles promise resolution by tracking promises and resuming suspended processes when promises are fulfilled. There’s a notion that async/await is inherently non-blocking, but that’s not true, as shown by a code example within this article.
Worker threads provide a way to create independent JavaScript execution threads that run in parallel. This post walks through an example of offloading CPU-intensive tasks to a worker thread in Node.js. Without offloading, tasks can block the event loop and prevent the server from processing other requests. The article shows an example of the server going from processing 7.3k requests to 0 tasks due to a CPU-intensive task.
Use of the “any” type is discouraged because it disables TypeScript's safety features, making code prone to errors and harder to maintain. However, there are some cases where using “any” is the right solution. It should be used in arguments when defining generic functions that should work with any function type. "any" can also be used with type assertions to work around TypeScript's limitations to accurately model functions that return different types based on input.
Golang comes with its own testing library, which is not common among popular programming languages. Unit tests in Go should be written to run in parallel by default so that concurrency issues are surfaced early on. The testing package has a comprehensive set of flags and can provide code coverage reports, race condition detection, static analysis, shuffled test execution, and more.
This article explains how to build a simplified version of React with 400 lines of code. The simplified React utilizes Fiber architecture and concurrency mode to avoid blocking the main thread during rendering. It is able to execute tasks during browser idle time. It uses a linked list structure to connect work units and triggers updates through a custom useState implementation.
This developer added a quicksort animation feature to a game to visually sort items while handling potential changes in the list being sorted. Instead of optimizing the quicksort algorithm to resume from its last state, the developer chose a simpler, inefficient solution (on purpose): the sorting illusion is created by repeatedly running the algorithm from the start until a change occurs.
importx is a unified tool for importing TypeScript modules at runtime. It makes it easy to switch between different loaders. The library aims to swallow the complexity of the underlying implementations so developers can focus on the feature sets they need.
This post discusses how to write a good commit message that focuses on information. It's important to consider the audience when writing a commit message, as many people might read them for lots of different reasons. The post covers what to include in a commit message and other places to post messages. It also covers typography, but attempts to keep the topic to a bare minimum.
Parsing JSON, despite its seemingly simple format, is actually quite challenging because there are so many specifications that can be interpreted in different ways. This has led to inconsistencies in how different JSON parsers handle edge cases, extreme values, and maliciously crafted payloads, resulting in potential bugs, crashes, and denial-of-service vulnerabilities. This article goes into detail about this issue with examples of different types of objects (arrays, objects, numbers, and strings) combined with different types of parsers (C Parsers, Regex, and more).
- A GitHub project offers an interactive spreadsheet-based nanoGPT pipeline to demystify GPT workings.
This project, a nanoGPT pipeline packed in a spreadsheet, was created to help further understanding of how GPT works. All of the mechanisms, calculations, and matrices included are fully interactive and configurable, designed to help readers visualize the entire structure and data flow. Resources for further learning are available.
- Async programming in Ruby on Rails can enhance app speed by parallelizing tasks but adds complexity.
Async programming can make Ruby on Rails apps faster by delaying non-essential tasks and parallelizing I/O-bound operations. This can be achieved using methods like `deliver_later` for emails, `load_async` for database queries, and `dependent: :destroy_async` for dependent associations. However, while async can speed up apps, it can also add complexity, so it's better to address basic performance issues first and use async judiciously.
Python Notebooks promote bad coding habits like neglecting testing and linting due to their ease of use and impermanence. They also worsen personal productivity by causing distractions and creating inconsistencies between the notebook environment and production. While they seem fast to iterate on, they slow down team collaboration by making it difficult to track changes, maintain awareness of ongoing work, and share useful code snippets.
JavaScript doesn't natively support canceling Promises. You can use `Promise.withResolvers()` to create cancelable tasks by manually resolving or rejecting Promises. Alternatively, `AbortController` can handle early rejection, which can be used for cancelable fetch requests and sequential request handling in React.
SCALE is a GPGPU programming toolkit that allows CUDA applications to be natively compiled for AMD GPUs. It does not require the CUDA program or its build system to be modified.
Python's datetime module can cause confusion when converting between timestamps and datetime objects due to timezone issues. The time.time() function returns a timestamp relative to epoch (UTC), while datetime.datetime.now() returns a timezone-naive object in the local timezone. This discrepancy can lead to incorrect results when converting timestamps back to datetime objects on systems with non-UTC timezones.
When data originates from outside your program, its type cannot be guaranteed, so assuming its type can lead to runtime errors. By assigning "unknown" to unverified data, you force yourself to explicitly validate its characteristics before using it, preventing potential errors and improving code safety. While "any" can be tempting to use, it disables type checking, which defeats the purpose of using a type system.
This article is a comprehensive guide on making C++ binaries highly debuggable, particularly for interactive debugging using tools like gdb. It focuses on configuring the C++ toolchain to produce binaries that are both efficient and easy to understand in the debugger. C++'s ahead-of-time compilation model requires a deliberate choice between debuggability and speed. The article presents various techniques, including enabling sanitizers, debug modes, and frame pointers to enhance the debugging experience.
- JavaScript's garbage collection can lead to memory leaks due to retained global variable references.
JavaScript garbage collection doesn't always release memory when a function is no longer callable, especially if the function's scope contains references to global variables, leading to memory leaks.
Functional programming languages should embrace mutation more effectively, as current approaches have significant drawbacks. This author critiques existing options, including allowing unrestricted mutation, limiting mutation to specific regions, and using linearity. A fundamentally new approach that addresses the shortcomings of current methods and integrates well with existing state management solutions is needed.
A from-scratch experimental ahead-of-time JS engine.
The C# language design team has proposed official type unions in a document detailing how they will be implemented and used.
Programmers should embrace a mindset of skepticism and constant verification, as trusting abstractions can lead to unexpected problems. Abstractions, while necessary for efficient thinking, are often leaky and can fail in unpredictable ways, so it's important to understand the underlying mechanisms. That's why "trust, but verify” is necessary when working on a project with a lot of abstractions.
Global Interpreter Lock (GIL) can be disabled in Python version 3.13. GIL is a mechanism used by the C Python interpreter to ensure that only one thread executes the Python bytecode at a time. Free-threaded mode, which disables GIL, is currently experimental. Disabling GIL makes a massive difference in the performance of multithreaded tasks.
Markus, a solo developer, uses a single programming language, Go, for all his projects. This allows him to move faster as he has the deepest understanding of the language, and so doesn't have to context switch across languages as much. Furthermore, as he develops, he continues to specialize in Go, which gives him more opportunities in the future.
This article explores how to implement Rust's Result and Option types in TypeScript to make error handling and null value management easier.
JavaScript's WeakMap should be made iterable, as the original motivation for its non-iterability is no longer valid and the current workaround using FinalizationRegistry is inefficient and non-standard.