Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions sam3/model_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
from typing import Optional

import pkg_resources
from pathlib import Path as _Path
import torch
import torch.nn as nn
from huggingface_hub import hf_hub_download
Expand Down Expand Up @@ -596,9 +596,7 @@ def build_sam3_image_model(
A SAM3 image model
"""
if bpe_path is None:
bpe_path = pkg_resources.resource_filename(
"sam3", "assets/bpe_simple_vocab_16e6.txt.gz"
)
bpe_path = str(_Path(__file__).parent / "assets" / "bpe_simple_vocab_16e6.txt.gz")

# Create visual components
compile_mode = "default" if compile else None
Expand Down Expand Up @@ -695,9 +693,7 @@ def build_sam3_video_model(
Sam3VideoInferenceWithInstanceInteractivity: The instantiated dense tracking model
"""
if bpe_path is None:
bpe_path = pkg_resources.resource_filename(
"sam3", "assets/bpe_simple_vocab_16e6.txt.gz"
)
bpe_path = str(_Path(__file__).parent / "assets" / "bpe_simple_vocab_16e6.txt.gz")

# Build Tracker module
tracker = build_tracker(apply_temporal_disambiguation=apply_temporal_disambiguation)
Expand Down Expand Up @@ -1105,9 +1101,7 @@ def build_sam3_multiplex_video_predictor(
Sam3MultiplexVideoPredictor: The fully-initialized predictor
"""
if bpe_path is None:
bpe_path = pkg_resources.resource_filename(
"sam3", "assets/bpe_simple_vocab_16e6.txt.gz"
)
bpe_path = str(_Path(__file__).parent / "assets" / "bpe_simple_vocab_16e6.txt.gz")

from sam3.model.sam3_multiplex_base import Sam3MultiplexPredictorWrapper
from sam3.model.sam3_multiplex_detector import Sam3MultiplexDetector
Expand Down
5 changes: 3 additions & 2 deletions sam3/perflib/fused.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
def addmm_act(activation, linear, mat1):
if torch.is_grad_enabled():
raise ValueError("Expected grad to be disabled.")
orig_dtype = mat1.dtype
self = linear.bias.detach()
mat2 = linear.weight.detach()
self = self.to(torch.bfloat16)
Expand All @@ -18,8 +19,8 @@ def addmm_act(activation, linear, mat1):
mat1_flat = mat1.view(-1, mat1.shape[-1])
if activation in [torch.nn.functional.relu, torch.nn.ReLU]:
y = addmm_act_op(self, mat1_flat, mat2.t(), beta=1, alpha=1, use_gelu=False)
return y.view(mat1.shape[:-1] + (y.shape[-1],))
return y.view(mat1.shape[:-1] + (y.shape[-1],)).to(orig_dtype)
if activation in [torch.nn.functional.gelu, torch.nn.GELU]:
y = addmm_act_op(self, mat1_flat, mat2.t(), beta=1, alpha=1, use_gelu=True)
return y.view(mat1.shape[:-1] + (y.shape[-1],))
return y.view(mat1.shape[:-1] + (y.shape[-1],)).to(orig_dtype)
raise ValueError(f"Unexpected activation {activation}")