(评论)
(comments)

原始链接: https://news.ycombinator.com/item?id=43632373

Function (fxn.ai) 项目旨在弥合 Python 模型(例如 PyTorch 中的模型)及其部署之间的差距,提供类似 Rust 的性能,而无需开发者学习 Rust。它通过使用 Python 编译器将现有的 Python 代码编译成独立的原生二进制文件来实现这一点。 关键在于利用 PyTorch 的符号追踪,它记录函数操作的中间表示 (IR) 图。然后将此 IR 图降低到 C++(很快会是 Rust)代码,并由大型语言模型 (LLM) 协助编写和验证所需的操作。 要使用 Function,开发者可以使用 `@compile` 装饰器修饰函数,并使用 CLI 命令。虽然 Function 目前不支持所有 Python 功能(例如,类、lambda 表达式)或不是纯 Python 的外部库,但开发者计划使用大型语言模型 (LLM) 自动重新实现库功能。与 Mojo 不同,Function 不需要学习新的语言,并且可以从越来越多的用于生成生产代码的大型语言模型 (LLM) 中获益。该项目专注于编译特定函数,未来可能会扩展到完整的程序。

相关文章

原文
Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: Python at the Speed of Rust (fxn.ai)
31 points by olokobayusuf 2 hours ago | hide | past | favorite | 11 comments
I’m sure many of you are familiar, but there’s a treacherous gap between finding (or building) a model that works in PyTorch, and getting that deployed into your application, especially in consumer-facing applications.

I’ve been very interested in solving this problem with a great developer experience. Over time, I gradually realized that the highest-impact thing to have was a way to go from existing Python code to a self-contained native binary—in other words, a Python compiler.

I was already pretty familiar with a successful attempt: when Apple introduced armv8 on the iPhone 5s, they quickly mandated 64-bit support for all apps. Unity—where I had been programming since I was 11—kinda got f*cked because they used Mono to run developers’ C# code, and Mono didn’t support 64-bit ARM. Unity ended up building IL2CPP, which transpiles the C# intermediate language into C++, then cross-compiles it. Till date, this is perhaps the most amazing technical feat Unity has achieved imo.

I set out to build something similar, but this time starting from Python. It’s a pretty difficult problem, given the dynamic nature of the language. The key unlock was the PyTorch 2.0 release, where they pioneered the use of symbolic tracing to power `torch.compile`. In a nutshell, they register a callback with the Python interpreter (using CPython’s frame evaluation API), run a function with fake inputs, and record an IR graph of everything that happened in the function.

Once you have an IR graph, you can lower it to C++/Rust code, operation-by-operation, by propagating type information throughout the program (see the blog post for an example). And now is the perfect time to have this infrastructure, because LLMs can do all the hard work of writing and validating the required operations in native code.

Anyway, I wanted to share the proof-of-concept and gather feedback. Using Function is pretty simple, just decorate a module-level function with `@compile` then use the CLI to compile it: `fxn compile module.py` .

TL;DR: Get Rust performance without having to learn Rust ;)











I'm confused about the introduction mentioning API keys? The function is compiled on and/or uploaded to your servers?

The introduction could benefit from discussing a less toyish problem.



So will this only work with standard Python?

If I start pulling in Numpy, igraph, scikit, etc, will it still work?

The article mentions Numpy as a gang up when trying to use Python across multiple systems, but it doesn’t address whether Function deals with this.

Looks cool, regardless!



how come performance is worse than Rust? Isn’t this misleading


It's marginal. The difference exists because Function adds syntactic sugar to make the developer experience of calling the compiled functions easy and smooth. The Function call isn't a direct call; whereas the Rust one is.

It's possible to hack Function to perform a direct call and avoid (most of) the overhead, but in 99.99% of use cases this won't matter cos most processing time will be spent in the body of the function, not the scaffolding that Function uses.



Super cool! Have been a fan of this project for a while. I think this is super important for anyone who is trying to do ml inference on edge hardware, but also the browser too.


Thank you <3


How does this compare to a project like Mojo, which also seems to aim at filling that "treacherous gap" you note? They seem to believe that they can't just write a Python compiler, why are you more confident?


I think us and Modular have incredibly similar visions of the end state of the world. The main difference is that they require devs to learn a new programming language (Mojo), whereas Function is designed to meet devs exactly where they are--not an inch away.

More fundamental than that is that Mojo has somewhat of a built-in assumption (I'm a bit more skeptical) that they can outperform silicon OEMs like Nvidia using MLIR (Mojo is designed as a front-end to MLIR). We have a much more conservative view: we'll rely on silicon OEMs to give us libraries we can use to accelerate things like inference; and we'll provide devs the ability to inspect and modify the generated code (C++ atm, Rust soon).

TL;DR: Devs don't have to learn anything with Function. Devs have to learn Mojo and MLIR to use Modular's offerings properly.



Makes sense, that's definitely a downside with Mojo. But my understanding is they made this tradeoff because compiling the python code directly would not work out. So is this something that is for the function-level (hence the name) and you don't plan to do this for full programs?


Spot on! We're starting from specific functions for now, and will expand the scope if/when feasible. The challenges exist across two axes: language coverage and library coverage.

For language coverage, Function currently doesn't support classes (on the roadmap) or lambda expressions (much harder). But these are the main limitations.

For library coverage, this is where things get incredibly hairy. If a library isn't pure Python (i.e. most of the important libs), we can't compile them. We instead have to reimplement the library's functionality. For now, we plan on using LLMs to automate this as much as possible.



Also worth noting that we're better positioned for the coming wave of LLMs writing the vast majority of code in production. Function is designed specifically for LLMs to do the transpilation step (Function simply provides rails to stack these unitary operations into user-defined functions).

Mojo has a cold-start problem here, cos there isn't enough Mojo code in the wild for LLMs to be great at writing it in volume (compare this to C++ and Rust).







Join us for AI Startup School this June 16-17 in San Francisco!


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact



Search:
联系我们 contact @ memedata.com