import urllib.parse
import sqlalchemy
password = ...
# escaping special characters such as @ signs
password = urllib.parse.quote_plus(password)
url = f'dialect+driver://username:{password}@host:port/database'
engine = sqlalchemy.create_engine(url) # Engine object
with engine.connect() as conn:
results = conn.execute('SELECT * FROM students')
for row in results:
print(row)
Python 并发简要
并发 (concurrency) 和并行 (parallelism) 是两个概念. 这两个术语的使用还有争议, 下面依照书上 (Fluent Python, 2nd Edition) 的说法, 并行是并发的子集.
A modern laptop with 4 CPU cores is routinely running more than 200 processes at any given time under normal, casual use. To execute 200 tasks in parallel, you’d need 200 cores. So, in practice, most computing is concurrent and not parallel.
深度学习性能瓶颈往往是内存带宽
首先是这篇文章
- Horace He. (2022). Making Deep Learning Go Brrrr From First Principles
内容不再赘述, 下面是纲要和一些对原文的注解. 虽然文章用 Torch 和 GPU 举例, 但基本原理依然普适.
注 (Show more »)
机器之心 编译 过这篇文章, 但有些错误. 比如只看第一段, 前几句话还行, 但光最后一句就有两个技术错误: (1) 把 in-place 说成内置; (2) 梯度设置为 None 说成 0. 关于第 2 点可以参考 torch 文档 Use parameter.grad = None instead of model.zero_grad() or optimizer.zero_grad().
简单介绍了模型耗时可以分为三部分
- Compute: Time spent on your GPU computing actual floating point operations (FLOPS)
- Bandwith: Time spent on moving the data from CPU to GPU, from one node to another, or even from CUDA global memory to CUDA shared memory
- Overhead: Everything else
Python 自动化杂录: Makefile 等
Makefile
直接看原文
- Aniket Bhattacharyea. (2021). Makefile Tutorials and Examples to Build From
- Aniket Bhattacharyea. (2021). Creating a Python Makefile
Python setuptools 简要
Java 初步: 简化版
主要参考 java4python “Learn Java: Programiz” app 上的小课. Just a quick review.
C++ 初步: 简化版
Shell 脚本简要
主要参考
- Shotts, W. (2019). The Linux command line
学习目标: 能写简单脚本, 能看懂长一些的脚本. Shell 脚本不是开发语言, 难以 debug, 不适合写太长.
If you are writing a script that is more than 100 lines long, or that uses non-straightforward control flow logic, you should rewrite it in a more structured language now. Bear in mind that scripts grow. Rewrite your script early to avoid a more time-consuming rewrite at a later date. (Google Shell Style Guide)
Python 装饰器杂录
装饰器基础, 以及常用装饰器略了, 比如 staticmethod
, classmethod
, property
, functools.lru_cache
.