fxn 0.0.45__py3-none-any.whl → 0.0.46__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
fxn/__init__.py CHANGED
@@ -4,8 +4,8 @@
4
4
  #
5
5
 
6
6
  from .client import FunctionAPIError
7
- from .compile import compile, CompileTarget
7
+ from .compile import compile, CompileMetadata, CompileTarget
8
8
  from .function import Function
9
9
  from .sandbox import Sandbox
10
10
  from .types import *
11
- from .version import *
11
+ from .version import __version__
fxn/beta/__init__.py CHANGED
@@ -3,4 +3,8 @@
3
3
  # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
+ from .metadata import (
7
+ CoreMLInferenceMetadata, GGUFInferenceMetadata,
8
+ ONNXInferenceMetadata, ONNXRuntimeInferenceSessionMetadata
9
+ )
6
10
  from .remote import RemoteAcceleration
fxn/beta/metadata.py ADDED
@@ -0,0 +1,61 @@
1
+ #
2
+ # Function
3
+ # Copyright © 2025 NatML Inc. All Rights Reserved.
4
+ #
5
+
6
+ from pathlib import Path
7
+ from pydantic import BaseModel, BeforeValidator, ConfigDict, Field
8
+ from typing import Annotated, Literal
9
+
10
+ def _validate_torch_module (module: "torch.nn.Module") -> "torch.nn.Module": # type: ignore
11
+ try:
12
+ from torch.nn import Module # type: ignore
13
+ if not isinstance(module, Module):
14
+ raise ValueError(f"Expected torch.nn.Module, got {type(module)}")
15
+ return module
16
+ except ImportError:
17
+ raise ImportError("PyTorch is required to create this metadata but is not installed.")
18
+
19
+ def _validate_ort_inference_session (session: "onnxruntime.InferenceSession") -> "onnxruntime.InferenceSession": # type: ignore
20
+ try:
21
+ from onnxruntime import InferenceSession # type: ignore
22
+ if not isinstance(session, InferenceSession):
23
+ raise ValueError(f"Expected onnxruntime.InferenceSession, got {type(session)}")
24
+ return session
25
+ except ImportError:
26
+ raise ImportError("ONNXRuntime is required to create this metadata but is not installed.")
27
+
28
+ class CoreMLInferenceMetadata (BaseModel):
29
+ """
30
+ Metadata required to lower PyTorch models for inference on iOS, macOS, and visionOS with CoreML.
31
+ """
32
+ kind: Literal["meta.inference.coreml"] = "meta.inference.coreml"
33
+ model: Annotated[object, BeforeValidator(_validate_torch_module)] = Field(description="PyTorch module to apply metadata to.")
34
+ model_args: list[object] = Field(description="Positional inputs to the model.")
35
+ model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)
36
+
37
+ class ONNXInferenceMetadata (BaseModel):
38
+ """
39
+ Metadata required to lower PyTorch models for inference.
40
+ """
41
+ kind: Literal["meta.inference.onnx"] = "meta.inference.onnx"
42
+ model: Annotated[object, BeforeValidator(_validate_torch_module)] = Field(description="PyTorch module to apply metadata to.")
43
+ model_args: list[object] = Field(description="Positional inputs to the model.")
44
+ model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)
45
+
46
+ class ONNXRuntimeInferenceSessionMetadata (BaseModel):
47
+ """
48
+ Metadata required to lower ONNXRuntime inference sessions for inference.
49
+ """
50
+ kind: Literal["meta.inference.onnxruntime"] = "meta.inference.onnxruntime"
51
+ session: Annotated[object, BeforeValidator(_validate_ort_inference_session)] = Field(description="ONNXRuntime inference session to apply metadata to.")
52
+ model_path: Path = Field(description="ONNX model path. The model must exist at this path in the compiler sandbox.")
53
+ model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)
54
+
55
+ class GGUFInferenceMetadata (BaseModel): # INCOMPLETE
56
+ """
57
+ Metadata required to lower GGUF models for LLM inference.
58
+ """
59
+ kind: Literal["meta.inference.gguf"] = "meta.inference.gguf"
60
+ model_path: Path = Field(description="GGUF model path. The model must exist at this path in the compiler sandbox.")
61
+ model_config = ConfigDict(arbitrary_types_allowed=True, frozen=True)
fxn/compile.py CHANGED
@@ -11,11 +11,22 @@ from pydantic import BaseModel, ConfigDict, Field
11
11
  from types import ModuleType
12
12
  from typing import Literal
13
13
 
14
+ from .beta import (
15
+ CoreMLInferenceMetadata, GGUFInferenceMetadata,
16
+ ONNXInferenceMetadata, ONNXRuntimeInferenceSessionMetadata
17
+ )
14
18
  from .sandbox import Sandbox
15
19
  from .types import AccessMode
16
20
 
17
21
  CompileTarget = Literal["android", "ios", "linux", "macos", "visionos", "wasm", "windows"]
18
22
 
23
+ CompileMetadata = (
24
+ CoreMLInferenceMetadata |
25
+ GGUFInferenceMetadata |
26
+ ONNXInferenceMetadata |
27
+ ONNXRuntimeInferenceSessionMetadata
28
+ )
29
+
19
30
  class PredictorSpec (BaseModel):
20
31
  """
21
32
  Descriptor of a predictor to be compiled.
@@ -38,6 +49,7 @@ def compile (
38
49
  trace_modules: list[ModuleType]=[],
39
50
  targets: list[CompileTarget]=None,
40
51
  access: AccessMode=AccessMode.Private,
52
+ metadata: list[CompileMetadata]=[],
41
53
  card: str | Path=None,
42
54
  media: Path=None,
43
55
  license: str=None,
@@ -53,6 +65,7 @@ def compile (
53
65
  trace_modules (list): Modules to trace and compile.
54
66
  targets (list): Targets to compile this predictor for. Pass `None` to compile for our default targets.
55
67
  access (AccessMode): Predictor access.
68
+ metadata (list): Metadata to use while compiling the function.
56
69
  card (str | Path): Predictor card markdown string or path to card.
57
70
  media (Path): Predictor thumbnail image (jpeg or png) path.
58
71
  license (str): Predictor license URL. This is required for public predictors.
@@ -74,6 +87,7 @@ def compile (
74
87
  media=None, # INCOMPLETE
75
88
  license=license,
76
89
  trace_modules=trace_modules,
90
+ metadata=metadata,
77
91
  **kwargs
78
92
  )
79
93
  # Wrap
fxn/version.py CHANGED
@@ -3,4 +3,4 @@
3
3
  # Copyright © 2025 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
- __version__ = "0.0.45"
6
+ __version__ = "0.0.46"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: fxn
3
- Version: 0.0.45
3
+ Version: 0.0.46
4
4
  Summary: Run prediction functions locally in Python. Register at https://fxn.ai.
5
5
  Author-email: "NatML Inc." <hi@fxn.ai>
6
6
  License: Apache License
@@ -224,7 +224,7 @@ Requires-Dist: rich
224
224
  Requires-Dist: typer
225
225
  Dynamic: license-file
226
226
 
227
- # Function for Python and CLI
227
+ # Function for Python
228
228
 
229
229
  ![function logo](https://raw.githubusercontent.com/fxnai/.github/main/logo_wide.png)
230
230
 
@@ -1,12 +1,13 @@
1
- fxn/__init__.py,sha256=eOYYoHwwQWzYVnyBO1VtcWR0JnUm1GPl4kr8IzhnCqg,257
1
+ fxn/__init__.py,sha256=gnJK7iOmMVWFhluW9bOvTNxJbpT-GwzDJTMmjA_XxOE,284
2
2
  fxn/client.py,sha256=Deje8eiS1VOHX85tQnV34viv2CPVx2ljwHSbyVB5Z1o,3790
3
- fxn/compile.py,sha256=Z63DMk_pscerqf8uOgWYYEsEsJTDvfrfYBqKYk3PbKE,3426
3
+ fxn/compile.py,sha256=A9dxw6yv1eCd-zEYnqiyjDUZou8TkbEIA_yB9Tn4pXo,3894
4
4
  fxn/function.py,sha256=XeEuALkbVhkvwEBUfP0A2fu3tdimwHemoR17oomhzc8,1407
5
5
  fxn/logging.py,sha256=MsTSf0GZxrHNDwVAXDOh8_zRUg9hkeZ8DfhFUJs7D8A,7250
6
6
  fxn/sandbox.py,sha256=w2dnHMBaKOERxFMpeAP11X6_SPqcvnpd6SmX6b_FOYQ,7000
7
- fxn/version.py,sha256=59sX9tjcjcy9gw0lAlJ18hN47PCe6nQlyoQ8YVYW0hM,95
8
- fxn/beta/__init__.py,sha256=gKoDhuXtXCjdhUYUqmF0gDPMhJfg3UwFgbvMtRB5ipo,111
7
+ fxn/version.py,sha256=NugzjvuR0aE7hGoUmoQvcI8t1IrmT-Xm9J9SaWp3wVk,95
8
+ fxn/beta/__init__.py,sha256=aQAV-apg11Z7Pn86eIegJ2id7wkRUaYeEaeZthaCmYk,252
9
9
  fxn/beta/client.py,sha256=0lfwQPcB9ToIJC7AcCXO6DlJKkmId8EChhd9bk29GGE,2611
10
+ fxn/beta/metadata.py,sha256=7mnbIVoGQm6_5Qy-gSV6xpGuSP6LcnFjKbmSBNze34w,3067
10
11
  fxn/beta/prediction.py,sha256=9DTBahNF6m0TicLab2o9e8IKpiSV6K7cUSTYaFju0ZU,356
11
12
  fxn/beta/remote.py,sha256=HC8OIslZYyxw3XafVCCrP_wrPa00y5uekkKd_tkzyV0,7551
12
13
  fxn/c/__init__.py,sha256=NMIduqO_MYtI9jVCu6ZxvbBtYQXoQyNEWblNy3m2UPY,313
@@ -40,9 +41,9 @@ fxn/types/dtype.py,sha256=71Tuu4IydmELcBcSBbmWswhCE-7WqBSQ4VkETsFRzjA,617
40
41
  fxn/types/prediction.py,sha256=BdLTxnKiSFbz5warX8g_Z4DedNxXK3gaNjSKR2FP8tA,2051
41
42
  fxn/types/predictor.py,sha256=KRGZEuDt7WPMCyRcZvQq4y2FMocfVrLEUNJCJgfDY9Y,4000
42
43
  fxn/types/user.py,sha256=Z44TwEocyxSrfKyzcNfmAXUrpX_Ry8fJ7MffSxRn4oU,1071
43
- fxn-0.0.45.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
44
- fxn-0.0.45.dist-info/METADATA,sha256=5g5H7YpEWWAkji5HLSLajTb4npfo6igzAbNp6GQWjH4,16144
45
- fxn-0.0.45.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
46
- fxn-0.0.45.dist-info/entry_points.txt,sha256=O_AwD5dYaeB-YT1F9hPAPuDYCkw_W0tdNGYbc5RVR2k,45
47
- fxn-0.0.45.dist-info/top_level.txt,sha256=1ULIEGrnMlhId8nYAkjmRn9g3KEFuHKboq193SEKQkA,4
48
- fxn-0.0.45.dist-info/RECORD,,
44
+ fxn-0.0.46.dist-info/licenses/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
45
+ fxn-0.0.46.dist-info/METADATA,sha256=l-W_xp1vn_B4ORukQfRqqe_a2G1mN37IORvIfR-TjG8,16136
46
+ fxn-0.0.46.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
47
+ fxn-0.0.46.dist-info/entry_points.txt,sha256=O_AwD5dYaeB-YT1F9hPAPuDYCkw_W0tdNGYbc5RVR2k,45
48
+ fxn-0.0.46.dist-info/top_level.txt,sha256=1ULIEGrnMlhId8nYAkjmRn9g3KEFuHKboq193SEKQkA,4
49
+ fxn-0.0.46.dist-info/RECORD,,
File without changes