Skip to content

Instantly share code, notes, and snippets.

import json
from itertools import pairwise
def sentinel(iterable):
for x in iterable:
yield x
yield None
def write_json_streaming_style(generator, indent=4):
print("[")
# Wrapper class to re-define the loss function everywhen a model is
# re-generated for hyper-parameter search.
class CustomCrossEncoderTrainer(CrossEncoderTrainer):
def __init__(self, *, loss_init=None, **kwargs):
self.__loss_init = loss_init
super().__init__(**kwargs)
def call_model_init(self, trial=None):
model = super().call_model_init(trial=trial)
self.loss = self.__loss_init(model)

調査日時: 2025年7月26日

https://download.pytorch.org/whl/rocm6.3 からインストールした pytorch

Python 3.12.11 (main, Jun  4 2025, 08:56:18) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import torch
>>> torch.__version__
'2.7.1+rocm6.3'
@tsuchm
tsuchm / Dockerfile
Last active July 17, 2025 12:50
Convert a docker container image distributed at DockerHub for singularity without installing singularity (but requires Docker)
FROM amd64/debian:unstable
# disallow services to run for package installation
RUN echo "#!/bin/sh\nexit 101" > /usr/sbin/policy-rc.d && chmod +x /usr/sbin/policy-rc.d
# upgrade already-installed packages
RUN apt update && \
DEBIAN_FRONTEND=noninteractive apt -y dist-upgrade && \
DEBIAN_FRONTEND=noninteractive apt install -y singularity-container
@tsuchm
tsuchm / howto-build-shellinabox.md
Last active April 8, 2025 04:00
shellinabox-install-playbook.yml

Because shellinaboxd RPM package is removed from EPEL official repository, it is necessary to build it by ourselves. Follow the following steps.

  1. Download the source RPM package from: https://src.fedoraproject.org/rpms/shellinabox

  2. Install it on your home directory:

$ rpm -i shellinabox-2.20-26.fc43.src.rpm
;; PlemoJPフォント https://github.com/yuru7/PlemolJP の Light を標準フォントとして使う場合の設定
;;
;; ~/.Xresources には以下のように書く.
;; Emacs.Font: PlemolJP Console Light-18
;;
;; これで PlemolJP Console Light が全体に使われるようになる.
;; 個人的な好みとして,bold / bold-italic が少し太すぎたので,以下のように補充設定をして調節しておく.
(when (display-graphic-p)
(set-face-attribute 'bold nil :family "PlemolJP Console Medium" :weight 'normal)
(set-face-attribute 'bold-italic nil :family "PlemolJP Console Medium" :weight 'normal :slant 'italic))
# Python implementation of https://aclanthology.org/P01-1064.pdf
#
# How to use:
# from textseg import textseg
# segments = textseg(texts)
from math import log2
import unittest
@tsuchm
tsuchm / gnus-resume.el
Last active October 23, 2023 11:33
Ridiculous training gear for users to prevent too frequent activation of Gnus
(defun gnus-resume (&optional force)
"Resume the last Gnus session or start a Gnus session."
(interactive "P")
(when (or force
(memq major-mode '(gnus-group-mode gnus-summary-mode gnus-article-mode message-mode lsdb-mode))
(let* ((key (+ ?a (random 26)))
(inp (read-char (format "Really start or resume Gnus session? Type \"%s\": " (string key)))))
(or (char-equal key inp)
(progn
(message "No reading news is good news")
@tsuchm
tsuchm / my-make-frame-command.el
Last active May 10, 2023 05:55
Extension of make-frame-command to generate a frame on visible position
;; 2つ目のフレームを作成する時,1つ目のフレームと重なって表示されてしまうため,重ならないよう場所を指定する
(defun my-make-frame-command ()
"Make a new frame, on the same terminal as the selected frame.
If the terminal is a text-only terminal, this also selects the
new frame."
(interactive)
(if (display-graphic-p)
(let ((left (cdr (assq 'left (frame-parameters (selected-frame)))))
(width (+ (frame-pixel-width) (frame-scroll-bar-width))))
(make-frame (list
--- a/internal/pkg/util/fs/mount/mount.go
+++ b/internal/pkg/util/fs/mount/mount.go
@@ -585,7 +585,10 @@
if sizelimit == 0 {
return fmt.Errorf("invalid image size, zero length")
}
- options = fmt.Sprintf("loop,offset=%d,sizelimit=%d,errors=remount-ro", offset, sizelimit)
+ options = fmt.Sprintf("loop,offset=%d,sizelimit=%d", offset, sizelimit)
+ if fstype == "ext3" {
+ options += ",errors=remount-ro"